- 
                Notifications
    
You must be signed in to change notification settings  - Fork 99
 
Create an Appium UI Test Automation Project
        HydraXMan edited this page Dec 26, 2022 
        ·
        1 revision
      
    - implementation 'com.microsoft.hydralab:appium-sdk:1.0.0' link
 - implementation 'io.appium:java-client:8.0.0'
 
PS. The parameters in SDK are ThreadLocal, you need get them in main Thread.
- Methods of test cases should be annotated with @Test.
 - Add a method annotated with @Before.
- Get DeviceId from SDK method ThreadParam.getDeviceId()
 - Init Appium Service and Android driver
 
 
  @Before
  public void beforeTest() {
      DesiredCapabilities capabilities = new DesiredCapabilities();
      // Init and start AppiumService
      service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingPort(4723).withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/").withArgument(GeneralServerFlag.RELAXED_SECURITY).withArgument(GeneralServerFlag.LOG_LEVEL, "error").withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell"));
      service.start();
      // Get DeviceID and config from ThreadParam
      AppiumParam ap = ThreadParam.getAppiumParam();
      String deviceID = ap.getDeviceId();
      String configValue = ThreadParam.getConfigString("configKey");
      //Set the target device of AndroidDriver
      if (deviceID != null) {
          capabilities.setCapability("udid", deviceID);
      }`
      capabilities.setCapability("newCommandTimeout", 4000);
      capabilities.setCapability("clearDeviceLogonStart", true);
      // Init AndroidDriver
      androidDriver = new AndroidDriver(service.getUrl(), capabilities);
  }
- Add a method annotated with @After.
- Destroy Appium Service and Android driver
 
 
    @After
    public void afterTest() {
        if (androidDriver != null) {
            androidDriver.quit();
        }
        if (service != null) {
            service.stop();
        }
    }
- Methods of test cases should be annotated with @Test.
 - Add a method annotated with @Before.
 
    @Before
    public void beforeTest() {
        service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingPort(4723).withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/").withArgument(GeneralServerFlag.RELAXED_SECURITY).withArgument(GeneralServerFlag.LOG_LEVEL, "error").withArgument(GeneralServerFlag.ALLOW_INSECURE, "adb_shell"));
        service.start();
        AppiumParam ap = ThreadParam.getAppiumParam();
        String udid = ap.getDeviceId();
        String deviceName = ap.getDeviceName();
        String osVersion = ap.getDeviceOsVersion();
        int wdaPort = ap.getWdaPort();
        // These capabilities are important to the iOS Test
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 4000);
        caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
        caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
        caps.setCapability(IOSMobileCapabilityType.XCODE_SIGNING_ID, "iPhone Developer");
        caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, osVersion);
        caps.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
        caps.setCapability(MobileCapabilityType.UDID, udid);
        caps.setCapability(IOSMobileCapabilityType.WEB_DRIVER_AGENT_URL, "http://127.0.0.1:" + wdaPort);
        caps.setCapability(IOSMobileCapabilityType.USE_PREBUILT_WDA, false);
        caps.setCapability("useXctestrunFile", false);
        caps.setCapability("skipLogCapture", true);
        try {
            iosDriver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
- Add a method annotated with @After.
 
    @After
    public void afterTest() {
        if (iosDriver != null) {
            iosDriver.quit();
        }
        if (service != null) {
            service.stop();
        }
    }
- The class should be annotated with @@RunWith(Suite.class) and @Suite.SuiteClasses({}).
 - Put the test case classes into SuiteClasses.
 
   @RunWith(Suite.class)
   @Suite.SuiteClasses({
        BaseTest1.class,
        BaseTest2.class,
   })
   public class AppiumTestSuite {
   }
- This class is used to debug when developing test case.
 - Invoke test suite by JuitCore.
 - Init ThreadParam brfore starting test.
 
    public class AppiumTestEntry {
        public static void main(String[] args) {
            Map<String,String> configMap= new HashMap<>();
            configMap.put("dbUrl",".....");
            configMap.put("dbPwd",".....");
            AppiumParam ap = new AppiumParam(<deviceId>, <deviceName>, <osVersion>, <wdaPort>, <apkPath>, <outputDir>);
            ThreadParam.init(ap, configMap);
            JUnitCore junit = new JUnitCore();
            junit.run(AppiumTestSuite.class);
        }
    }
- Use shadow to generate Jar
 
plugins {
    id 'java'
    id 'com.kncept.junit.reporter' version '2.1.0'
    id 'com.github.johnrengelman.shadow' version '6.1.0'
}
shadowJar {
    classifier = 'test'
    version = null
    zip64 true
    manifest {
        attributes 'Main-Class': 'com.appium.demo.AppiumTestEntry'
    }
}
- Test Jar in local PC
 
java -cp path_to_jar com.appium.demo.AppiumTestEntry
Introduction:
User manual:
- Deploy Center Docker Container
 - Deploy Agent Docker Container
 - Test agent setup
 - One-Line-Installer Agent Setup
 - [DEPRECATED]Deploy a test agent service
 - Trigger a test task run in the Hydra Lab test service
 - Create an Appium UI Test Automation Project
 - Create test build and run XCTest
 - Test Task Customization
 - FAQ
 
Developer guideline:
- Start Services with Default Configuration
 - Dev Environment Setup
 - Technical Design
 - Integrate Hydra Lab test center with Microsoft AAD authentication service
 - Upgrade the test agent service from center service
 
News: