如何在testng中一个接一个地运行类

时间:2019-07-16 06:23:15

标签: testng-eclipse

我有2个Java类,需要使用testng xml一个接一个地运行。 但是当我运行xml时,这两个类正在并行执行。

我尝试设置parallel = false,但是它仍然可以并行执行

下面是我的课程:

第1类:

package pulse.roster;

import static org.testng.Assert.assertTrue;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class RosterClockinFilter {

    public WebDriver driver;
    public Actions actions;

    @BeforeSuite
    public void launchApplication() {

        System.setProperty("webdriver.chrome.driver",
                "C:\\MyChromeDriver\\chromedriver_win32\\chromedriver.exe");

        driver = new ChromeDriver();
        driver.get("mysite");
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        actions = new Actions(driver);

    }

    public void closeApplication() {
        driver.close();
    }

    @Test(priority = 0)
    public void adminLogin() {

        try {
            actions.moveToElement(driver.findElement(By.name("userId")));
            actions.click();
            actions.sendKeys("admin");
            actions.build().perform();

            actions.pause(java.time.Duration.ofSeconds(1));

            actions.moveToElement(driver.findElement(By.name("password")));
            actions.click();
            actions.sendKeys("abc@123");
            actions.build().perform();

            actions.pause(java.time.Duration.ofSeconds(1));

            actions.moveToElement(driver.findElement(By.name("dcNumber")));
            actions.click();
            actions.sendKeys("7036");
            actions.build().perform();

            actions.moveToElement(driver.findElement(By
                    .cssSelector("body > ion-app > ng-component > ion-nav > page-login > ion-content > div.scroll-content > ion-card > ion-grid > form > ion-list > div.login-button > button > span")));
            actions.click();
            actions.build().perform();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Test(priority = 1)
    public void rosterPage() {
        actions.moveToElement(driver.findElement(By
                .xpath("//*[@id='tab-t0-1']")));
        actions.click();
        actions.build().perform();
    }

    @Test(priority=2)

    public void filterButton(){
        WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By
                .xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/ion-toolbar/div[2]/ion-grid/ion-row/ion-col[2]/button")));
        actions.moveToElement(driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/ion-toolbar/div[2]/ion-grid/ion-row/ion-col[2]/button")));
        actions.click();
        actions.build().perform();

    }

    @Test(priority=3)
    public void selectClockin(){
        actions.moveToElement(driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/div/div/ion-row[3]/ion-col[1]/ion-row/ion-item[1]/div[1]/ion-radio")));
        actions.click();
        actions.build().perform();

    }

    @Test(priority=4)
    public void selectApply(){
        actions.moveToElement(driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/div/div/div/ion-row")));
        actions.click();
        actions.build().perform();

    }

    @Test(priority=5)
    public void checkFilter(){
        String element=driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/ion-content/div[2]/div[2]/ion-row/ion-col/div[2]/user-attendance-card/ion-list/div/ion-item[1]/div[1]/div/ion-label/ion-grid[2]/ion-row/ion-col[4]")).getText();
        assertTrue(element.contains("-"));

    }
}

第2类:

package pulse.roster;

import static org.testng.Assert.assertFalse;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class RosterClockoutFilter {



    public WebDriver driver;
    public Actions actions;

    @BeforeSuite
    public void launchApplication() {

        System.setProperty("webdriver.chrome.driver",
                "C:\\MyChromeDriver\\chromedriver_win32\\chromedriver.exe");

        driver = new ChromeDriver();
        driver.get("mysite");
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        actions = new Actions(driver);

    }

    public void closeApplication() {
        driver.close();
    }

    @Test(priority = 0)
    public void adminLogin() {

        try {
            actions.moveToElement(driver.findElement(By.name("userId")));
            actions.click();
            actions.sendKeys("admin");
            actions.build().perform();

            actions.pause(java.time.Duration.ofSeconds(1));

            actions.moveToElement(driver.findElement(By.name("password")));
            actions.click();
            actions.sendKeys("abc@123");
            actions.build().perform();

            actions.pause(java.time.Duration.ofSeconds(1));

            actions.moveToElement(driver.findElement(By.name("dcNumber")));
            actions.click();
            actions.sendKeys("7036");
            actions.build().perform();

            actions.moveToElement(driver.findElement(By
                    .cssSelector("body > ion-app > ng-component > ion-nav > page-login > ion-content > div.scroll-content > ion-card > ion-grid > form > ion-list > div.login-button > button > span")));
            actions.click();
            actions.build().perform();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Test(priority = 1)
    public void rosterPage() {
        actions.moveToElement(driver.findElement(By
                .xpath("//*[@id='tab-t0-1']")));
        actions.click();
        actions.build().perform();
    }

    @Test(priority=2)

    public void filterButton(){
        WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By
                .xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/ion-toolbar/div[2]/ion-grid/ion-row/ion-col[2]/button")));
        actions.moveToElement(driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/ion-toolbar/div[2]/ion-grid/ion-row/ion-col[2]/button")));
        actions.click();
        actions.build().perform();

    }

    @Test(priority=3)
    public void selectClockout(){
        actions.moveToElement(driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/div/div/ion-row[3]/ion-col[2]/ion-row/ion-item[1]/div[1]/ion-radio")));
        actions.click();
        actions.build().perform();

    }

    @Test(priority=4)
    public void selectApply(){
        actions.moveToElement(driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/div/div/div/ion-row")));
        actions.click();
        actions.build().perform();

    }

    @Test(priority=5)
    public void checkFilter(){
        String element=driver.findElement(By.xpath("//*[@id='tabpanel-t0-1']/whos-here-page/div/clocked-card/ion-content/div[2]/div[2]/ion-row/ion-col/div[2]/user-attendance-card/ion-list/div/ion-item[6]/div[1]/div/ion-label/ion-grid[2]/ion-row/ion-col[4]")).getText();
        assertFalse(element.isEmpty());

    }

}

我的testng xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Roster Suite" parallel="false" preserve-order="true" verbose="2">
<test name="Regression suite 1">
    <classes>
    <class name="pulse.roster.RosterClockinFilter"></class>
    </classes>
    </test>
    <test name="Regression suite 2">
    <classes>
    <class name="pulse.roster.RosterClockoutFilter"></class>
    </classes>
    </test>
</suite>

如果有人可以指导我如何以串行方式而不是并行方式运行我的课程,将会很有帮助。

0 个答案:

没有答案