繁体   English   中英

Appium / selenium:testNG并行执行不起作用

[英]Appium / selenium: testNG parallel execution not working

我正在使用 appium 和硒。 我正在尝试并行朗姆酒(一个案例又一个案例)我的第一个案例(忘记密码正在正常运行),然后执行就停止了。

谁能帮我这个?

我附上了 testng.xml 和 testbase 文件。 还登录并忘记密码脚本。

  • 我想注释存在一些问题。
  • 我试过很少,但现在工作了。

谁能帮我这个?

谢谢!!!

我的代码如下所示:

1.testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
    <test thread-count="5" name="Test" parallel="classes">
        <classes>
            <class name="com.live.testcase.TC0001ForgotPassword" />
            <class name="com.live.testcase.TC0002Login" />
            <class name="com.live.testcase.TC0003Dashboard" />
            <class name="com.live.testcase.TC0004Activity" />
            <class name="com.live.testcase.TC0005MoveMoney" />
            <class name="com.live.testcase.TC0006InternationalTransfer" />
            <class name="com.live.testcase.TC0007Integration" />
            <class name="com.live.testcase.TC0008Account" />
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

2.testbase.java

public class testBase {

    private String reportDirectory = "reports";
    private String reportFormat = "xml";
    private String testName = "Untitled";
    protected IOSDriver<IOSElement> driver = null;

    @BeforeSuite
    public void setup() throws MalformedURLException {

        DesiredCapabilities dc = new DesiredCapabilities();
        dc.setCapability("reportDirectory", reportDirectory);
        dc.setCapability("reportFormat", reportFormat);
        dc.setCapability("testName", testName);
        dc.setCapability(MobileCapabilityType.UDID, "afb65172e9b47b01482d912dede58515819748a3");
        dc.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.novo.ios.dev");
        driver = new IOSDriver<IOSElement>(new URL("http://localhost:4723/wd/hub"), dc);
        driver.setLogLevel(Level.INFO);

    }

    @AfterSuite
    public void teardown() {

    }

}

3.忘记密码

public class TC0001ForgotPassword extends testBase {

    @Test
    public void ForgotPassword() throws InterruptedException {

        // Test case for blank email address.

        driver.findElement(By.xpath("//*[@text='Forgot Password?']")).click();
        driver.findElement(By.xpath("//*[@placeholder='Email']")).sendKeys("Automationtesting@banknovo.com");
        driver.findElement(By.xpath("//*[@text='Done']")).click();

        Thread.sleep(1000);
        driver.findElement(By.xpath("//*[@text='CONFIRM']")).click();

        Thread.sleep(5000);
        driver.findElement(By.xpath("//*[@text='(MM/DD/YYYY)']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='Done']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='CONFIRM']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='1']")).click();
        driver.findElement(By.xpath("//*[@text='2']")).click();
        driver.findElement(By.xpath("//*[@text='3']")).click();
        driver.findElement(By.xpath("//*[@text='4']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='CONFIRM']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='CONFIRM']")).sendKeys("111111");

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='CONFIRM']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@placeholder='Password']")).sendKeys("Novo@2019");
        driver.findElement(By.xpath("//*[@placeholder='Confirm Password']")).sendKeys("Novo@2019");

        Thread.sleep(2000);
        driver.findElement(
                By.xpath("(//*[@class='UIAView' and ./parent::*[@class='UIAScrollView']]/*[@text='icEyeOpen'])[1]"))
                .click();
        driver.findElement(By.xpath("//*[@text='icEyeOpen']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='RESET PASSWORD']")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='DONE']")).click();

    }

4. 登录

package com.live.testcase;

import org.testng.annotations.Test;
import org.openqa.selenium.By;
import com.live.common.testBase;

public class TC0002Login extends testBase {

    @Test
    public void TC000001_Blank_Email_Password() {

        // Test case for blank email address.
        driver.findElement(By.xpath("//*[@text='LOG IN']")).click();
        driver.findElement(By.xpath("//*[@text='OK']")).click();
    }

    @Test
    public void TC000002_Invailid_Email() throws Exception {

        // Test case for invalid email addresses
        driver.findElement(By.xpath("//*[@placeholder='Email']")).sendKeys("automationtesting");
        driver.findElement(By.xpath("//*[@placeholder='Password']")).sendKeys("Novo");
        driver.findElement(By.xpath("//*[@text='LOG IN']")).click();
        driver.findElement(By.xpath("//*[@text='OK']")).click();

    }

    @Test
    public void TC000003_Invailid_Password() throws Exception {

        // Test case for invalid email addresses
        driver.findElement(By.xpath("//*[@placeholder='Email']")).clear();
        driver.findElement(By.xpath("//*[@placeholder='Password']")).clear();
        driver.findElement(By.xpath("//*[@placeholder='Password']")).sendKeys("Novo@2019");
        driver.findElement(By.xpath("//*[@text='LOG IN']")).click();
        driver.findElement(By.xpath("//*[@text='OK']")).click();

    }

    @Test
    public void TC000004_Valid_Email_Password() throws Exception {
        // Test case for Valid email addresses & password
        driver.findElement(By.xpath("//*[@placeholder='Email']")).sendKeys("automationtesting@banknovo.com");
        driver.findElement(By.xpath("//*[@placeholder='Password']")).sendKeys("Novo@2019");
        driver.findElement(By.xpath("//*[@text='LOG IN']")).click();
    }
}

5. pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.novo.app</groupId>
    <artifactId>com.novo.app</artifactId>
    <version>0.0.1-SNAPSHOT</version>


    <dependencies>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
        </dependency>

    </dependencies>


</project>

我认为这可能是问题所在:您指示testng在套件标签而非测试标签处并行运行。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" thread-count="5" parallel="classes">
    <test  name="Test">
        <classes>
            <class name="com.live.testcase.TC0001ForgotPassword" />
            <class name="com.live.testcase.TC0002Login" />
            <class name="com.live.testcase.TC0003Dashboard" />
            <class name="com.live.testcase.TC0004Activity" />
            <class name="com.live.testcase.TC0005MoveMoney" />
            <class name="com.live.testcase.TC0006InternationalTransfer" />
            <class name="com.live.testcase.TC0007Integration" />
            <class name="com.live.testcase.TC0008Account" />
        </classes>
</test> <!-- Test -->

根据“ 并行性和超时”一章:

<suite>标记上的parallel属性可以采用以下值之一:

<suite name="My suite" parallel="methods" thread-count="5">

<suite name="My suite" parallel="tests" thread-count="5">

<suite name="My suite" parallel="classes" thread-count="5">

<suite name="My suite" parallel="instances" thread-count="5">

所以我的期望是您需要修改testng.xml使其看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" configfailurepolicy="continue" verbose="2">
    <test name="TC0001ForgotPassword">
        <classes>
            <class name="com.live.testcase.TC0001ForgotPassword"/>
        </classes>
    </test>
    <test name="TC0002Login">
        <classes>
            <class name="com.live.testcase.TC0002Login"/>
        </classes>
    </test>
    <test name="TC0003Dashboard">
        <classes>
            <class name="com.live.testcase.TC0003Dashboard"/>
        </classes>
    </test>
    <test name="TC0004Activity">
        <classes>
            <class name="com.live.testcase.TC0004Activity"/>
        </classes>
    </test>
    <test name="TC0005MoveMoney">
        <classes>
            <class name="com.live.testcase.TC0005MoveMoney"/>
        </classes>
    </test>
    <test name="TC0006InternationalTransfer">
        <classes>
            <class name="com.live.testcase.TC0006InternationalTransfer"/>
        </classes>
    </test>
    <test name="TC0007Integration">
        <classes>
            <class name="com.live.testcase.TC0007Integration"/>
        </classes>
    </test>
    <test name="TC0008Account">
        <classes>
            <class name="com.live.testcase.TC0008Account"/>
        </classes>
    </test>
</suite>

更多信息,包括示例项目: 并行测试执行

我猜这个问题是你在 Desired Capabilities 中指定了 UDID。 因此,您的测试试图在同一设备上并行运行,这似乎是不可能的)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM