【问题标题】:How execute appium tests parallel on different devices using appium grid如何使用 appium 网格在不同设备上并行执行 appium 测试
【发布时间】:2021-10-18 15:21:39
【问题描述】:

目标:因为我是 Appium 的新手。我正在尝试在 Ubuntu 上使用 Appium 网格在多个 android 设备上并行自动化 Appium 测试。
我已经成功启动了一个网格中心服务器和 2 个具有不同端口的节点。
问题:无法同时在两个设备上运行测试用例(我确定问题在于如何我正在设计我的框架)。我不知道如何传递两个设备的功能并同时启动设备(主要问题)。我是否必须为此使用多线程,如果是,那么如何?
实际:当我在同一台设备上运行多个测试类时,它可以工作,但因为我只有一个实例我的 BaseTest 类中的 Android 驱动程序,我无法并行运行。
我尝试了什么:我在 google 上浏览了这么多线程,但找不到确切的解决方案。
这是我的 testng.xml 代码

<suite name="Functional" parallel="tests" thread-count="2">
<test verbose="2" name="Pixel 4a">
    <classes>
        <class name="tests.PersonalRegistrationTests" />
        <class name="tests.LoginTests"></class>
    </classes>
</test> <!-- Test -->
<test verbose="2" name="Galaxy A20s">
    <classes>
        <class name="tests.PersonalRegistrationTests" />
        <class name="tests.LoginTests"></class>
    </classes>
</test> <!-- Test -->

这是我的 TestBase.java 代码

public class TestBase {

static AppiumDriver androidDriver;

@BeforeSuite
public void setup() {
    try {
        androidDriver = DeviceUtility.getAndroidDriver();
    } catch (Exception exp) {
        System.out.println("Message is : " + exp.getMessage());
        androidDriver.quit();
    }
}

这是我的 DeviceUtility.java 代码

public static AppiumDriver getAndroidDriver() throws Exception {
    
    DesiredCapabilities capability = new DesiredCapabilities();
    AppiumDriver androidDriver;
    
    try {
        capability.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        capability.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.0");
        capability.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel 4a");
        capability.setCapability(MobileCapabilityType.UDID, "09091JEC214196");
        capability.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir") + getApkRelativePATH());
        
        androidDriver = new AndroidDriver<MobileElement>(new URL("http://192.168.88.60:4444/wd/hub"), capability);
        androidDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        return androidDriver;
    
    } catch (Exception ex) {
        throw new Exception("Error : " + ex.getMessage());
    }
}

这是一个测试样本。

public class PersonalRegistrationTests extends TestBase{

@Test(priority = 1)
public void verifyRegistrationWithSupportedCountry() throws Exception { 
    
    RegistrationScreens registrationScreens = new RegistrationScreens(androidDriver);
    
    try {
        registrationScreens.allowLocationPermission();
        registrationScreens.allowContactsPermission();
        registrationScreens.visitOnboardingScreens();
        registrationScreens.selectCountry("United States");
        registrationScreens.enterPhoneNumber("5678911111");
        registrationScreens.sendCode();
        
        Assert.assertTrue(registrationScreens.checkOTPScreenVisibility());
        
    }catch(Exception ex){
        throw new SkipException(ex.getMessage());
    }
    
}

我的框架哪里做错了?在此先感谢:)

【问题讨论】:

    标签: java selenium automation appium selenium-grid


    【解决方案1】:
    1. 对于设置函数而不是@BeforeSuite 使用@BeforeTest,这将确保函数在每次测试之前执行

    2. 在“getAndroidDriver”功能中,您只设置了一台移动设备的功能。相反,您可以通过以下方式构建解决方案:

      一个。在 testng xml 文件的测试标签下使用“参数”标签 湾。在参数中设置功能值,例如设置设备名称 C。在 Galaxy A20s 的其他测试标签下执行此操作

    3. 使用 @Parameters 注解设置函数来接收传递的值,例如@Parameters({"udid", "deviceName"})

    4. 更改设置函数定义以接受参数值,例如设置(字符串 udid,字符串设备名称)

    5. 将 setup 函数中接收到的参数值发送到 getAndroidDriver 函数。

    6. 完成上述操作后,您的设置和 getAndroidDriver 函数将使用两组不同的参数值并行执行

    确保您还通过参数标签传递了appium端口号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-15
      • 2019-01-13
      • 2016-09-25
      • 2019-08-13
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多