我如何使用TestNG框架工作在XML文件中执行多个类的脚本



我已经自动化了一个Android应用程序,并在三个不同的类中编写了测试脚本。日复一日,当我面临问题时,我需要更多的课程来编写测试脚本。在类中执行测试脚本时,它工作正常。当我想在XML文件中执行这些测试脚本时,只执行3个测试用例。

我已经实现了一个配置类,我可以在其中启动我的应用程序,并且该类在其他类中进行了扩展。

package com.macrosoft.CherryPick;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class Configuration {
public AndroidDriver driver;
@BeforeSuite
public void CherryPikLaunch() throws MalformedURLException, InterruptedException {
// Create object of DesiredCapabilities class and specify android platform
// Create object of DesiredCapabilities class
// File classpathRoot = new File(System.getProperty("user.dir"));
// File appDir = new File(classpathRoot, "/Apps/Amazon/");
// File app = new File(appDir, "selendroid-test-app-0.17.0.apk");
// DesiredCapabilities capabilities = new DesiredCapabilities();
DesiredCapabilities capabilities = new DesiredCapabilities().android();
// capabilities.setCapability("no",true);
// capabilities.setCapability("newCommandTimeout", 100000);
// capabilities.setCapability("noReset", true);
// Optional
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
// Specify the device name (any name)
capabilities.setCapability("deviceName", "Galaxy S4");
// Platform version
capabilities.setCapability("platformVersion", "5.1.0");
// platform name
capabilities.setCapability("platformName", "Android");
// specify the application package that we copied from appium
// capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.fittingnzidd.cherripik.development");
// specify the application activity that we copied from appium
capabilities.setCapability("appActivity", "com.fittingnzidd.cherripik.activity.SplashActivity");
// capabilities.setCapability("appActivity",".DispatchActivity");
// appWaitActivity = .DispatchActivity;
// Start android driver I used 4727 port by default it will be 4723
// driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
// capabilities);
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
// Specify the implicit wait of 5 second
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Thread.sleep(10000);
// close the application
// driver.quit();
try {
Thread.sleep(5000);
System.out.print("Successfully launched the Applicationn");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.print("Exception is displayed" + e);
e.printStackTrace();
}
}
@AfterSuite
public void close_browser() {
driver.quit();
}
}

Toolsrefferalcode 类单独工作正常,但不在 xml 文件中执行

package com.macrosoft.CherryPick;
import static org.junit.Assert.assertNotEquals;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import java.awt.Dimension;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Driver;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.Assert;
public class ToolsReferralCode extends Configuration {
public String BrandNameOnBrandDetailScreen;
// public AndroidDriver driver;
public ToolsReferralCode() {
}
// public AndroidDriver driver;
/*
* ToolsReferralCode() { }
*/
/*******************************
* Your Referral code Scripts
************************************/
@Test(priority = 1) // verify that Tools screen Opens successfully
public void OpenToolsScreen() {
WebElement ToolsButtonElement = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/footer_nav_settings_btn"));// Find Tools
                                      // Button ID
ToolsButtonElement.click();// click on tools button
WebElement ScreenTitleFindElement = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/tv_screen_title"));// Find the Id of
                              // Screen tile
String ScreentitleActualText = ScreenTitleFindElement.getText();// Get the Text of Title
Assert.assertEquals("Tools & Settings", ScreentitleActualText);// compare Actual Result with Expected Result
try {
Thread.sleep(5000);
// System.out.print("Successfully Opened the Tools Screenn");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.print("Exception is displayed" + e);
e.printStackTrace();
}
}
@Test(priority = 2) // Verify that on tools screen title is exist or not
public void OnToolsScreenTitlePresist() {
WebElement ScreenTitleFindElement = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/tv_screen_title"));// Find the Id of
                              // Screen tile
String ScreentitleActualText = ScreenTitleFindElement.getText();// Get the Text of Title
Assert.assertEquals("Tools & Settings", ScreentitleActualText);// compare Actual Result with Expected Result
}
@Test(priority = 3) // Verify that on Tools screen Your refferal code button is displayed & enabled
public void VerifyThatYourRefferalButtonIsAvailableOnToolsScreen() {
WebElement YourRefferalButtonGetElementById = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/imageView"));
boolean YourRefferalButtonisDisplayed = YourRefferalButtonGetElementById.isDisplayed();
boolean YourRefferalButtonisEnabled = YourRefferalButtonGetElementById.isEnabled();
if (YourRefferalButtonisDisplayed == true && YourRefferalButtonisEnabled) {
WebElement YourRefferalCodeTextId = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/tv_rate_this_location_text"));
String YourRefferalCodeGetText = YourRefferalButtonGetElementById.getText();
// System.out.print("Button Text" +YourRefferalCodeGetText );
Assert.assertEquals("Your Referral Code", YourRefferalCodeGetText);// compare Actual Result with Expected
          // Result
}
}
@Test(priority = 4)
public void OpenYourReferralScreen() {
WebElement YourRefferalButtonGetElementById = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/imageView"));
boolean YourRefferalButtonisDisplayed = YourRefferalButtonGetElementById.isDisplayed();
boolean YourRefferalButtonisEnabled = YourRefferalButtonGetElementById.isEnabled();
if (YourRefferalButtonisDisplayed == true && YourRefferalButtonisEnabled) {
YourRefferalButtonGetElementById.click();
WebElement ReferralScreenTitleId = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/tv_screen_title"));
String ReferralScreenTitleGetText = ReferralScreenTitleId.getText();
Assert.assertEquals("Referral Code", ReferralScreenTitleGetText);// compare Actual Result with Expected
          // Result
} else {
System.out.print("Test Case Failed:'Your Referral Code' Button is not Found on the Tool screen");
}
}
@Test(priority = 5) // verify that on referral screen Referral code is exist
public void verifyThatRefferalCodeExistOnRefferalScreen() {
WebElement YourReferralCodeId = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/tv_referral_code_text"));
if (YourReferralCodeId != null) {
System.out.print("Test Case Passed :" + YourReferralCodeId.getText());
Assert.assertNotNull(YourReferralCodeId);
} else {
System.out.print("Test Case Failed :your referral Code Not Found On Referral Screen");
Assert.assertNotNull(YourReferralCodeId);
}
}
}

Chrripik类单独工作正常,但不在XML文件中执行

package com.macrosoft.CherryPick;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import java.util.List;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
import org.hamcrest.core.IsEqual;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeTest;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
public class CherryPik extends Configuration {
public static String ActualResultSearch;
public static String ActualResultRecentLocation;
public static String ActualResultRecentLocationForHomeSelection;
public String ActualLocationSendKey = "test";
String GetTextSaveMyLocation;
public CherryPik() {
}
// verify that when user clicks on location button then system shows recent
// Location ByDefault
@Test(priority = 1)
public void RecentLocation() throws InterruptedException {
WebElement FindLocationElementByID = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/footer_nav_locations_btn"));
FindLocationElementByID.click();
Thread.sleep(5000);
// verify that Recent Button is Displayed
boolean RecentButtonPresence = driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/recent_loc"))
.isDisplayed();
// verify that Recent button is enabled
boolean RecentButtonEnabled = driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/recent_loc"))
.isEnabled();
if (RecentButtonPresence == true && RecentButtonEnabled == true) {
System.out
.print("Test Casepass:Recent Location is showing by default when user clicks on Location buttonn");
} else {
System.out.print("Test Case Failed:Recent Location Screen Not Found");
}
Thread.sleep(5000);
// driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/search_locations")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.print("Exception is displayed" + e);
e.printStackTrace();
}
}
private void If(boolean b) {
// TODO Auto-generated method stub
}
// verify that user can select the Location and Brands Name are displayed on the
// Map
@Test(priority = 2)
public void SearchLocation() throws InterruptedException {
// AndroidElement FindElementLocationButton= (AndroidElement)
// driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/footer_nav_locations_btn"));
driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/search_locations")).click();
// verify if the “ Search” Field is displayed and enabled
Thread.sleep(10000);
// verify that search field is displayed
boolean SearchFieldIsDisplayed = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/save_curr_to_my_loc_parent"))
.isDisplayed();
// verify that search field is enabled
boolean SearchFieldIsEnabled = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/save_curr_to_my_loc_parent")).isEnabled();
boolean OkButtonPresenece = driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/btn_here_now"))
.isDisplayed();
boolean OkButtonVisible = driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/btn_here_now"))
.isEnabled();
if (SearchFieldIsDisplayed == true && SearchFieldIsEnabled == true && OkButtonPresenece == true
&& OkButtonVisible == true) {
// verify that User can select the the location from the drop down
WebElement LocationSearchFieldElement = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/save_curr_to_my_loc_parent"));
LocationSearchFieldElement.sendKeys("Tes");
Thread.sleep(1500);
WebElement autoComplete = driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/list_view"));
try {
(new WebDriverWait(driver, 5/* sec */)).until(ExpectedConditions
.presenceOfElementLocated((By.id("com.fittingnzidd.cherripik.development:id/list_view"))));
} catch (org.openqa.selenium.TimeoutException e) {
// System.out.println(e.getMessage());
}
List<WebElement> autoCompleteList = driver
.findElements(By.id("com.fittingnzidd.cherripik.development:id/tv_item_name"));
Thread.sleep(1500);
// autoCompleteList.get(0).click();
if (autoCompleteList.size() == 0) {
System.out.println("AutoSearch list NOT foundn");
} else {
System.out.println("autoSearch list Found with elements:" + autoCompleteList.size());
// System.out.println("autoSearch list Found with elements:
// "+autoCompleteList.));
}
for (WebElement ac : autoCompleteList) {
if (ac.getText().contains("Tesla WV") || ac.getText().contains("Home")) {
ActualResultSearch = ac.getText();
ac.click();
break;
}
}
Thread.sleep(500);
boolean AfterSelectionofLocationMapIsdisplayed = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/footer_nav_map_btn")).isDisplayed();
if (AfterSelectionofLocationMapIsdisplayed == true) {
System.out.println("Test Case pass:Brands are successfully displayed on the map n");
} else {
System.out.println("Test Case Failed:Brands are not displayed on the map n");
}
// LocationSearchFieldElement.sendKeys("t");
Thread.sleep(5000);
// SelectElement selector = new SelectElement();
// selector.SelectByIndex(2);
} else {
System.out.println("Search Field Not Found On 'Search All Screen'n");
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.print("Exception is displayed" + e);
e.printStackTrace();
}
}
@Test(priority = 3) // verify that search Location is Exist in the Recent Location
// List
public void SearchLocationIsExistInTheRecentLocationList() throws InterruptedException {
// String ExpectedResult="Tesla WV";
// String ActualResultRecentLocation;
Thread.sleep(100);
RecentLocation();
Thread.sleep(1000);
WebElement autoComplete = driver.findElement(By.id("com.fittingnzidd.cherripik.development:id/main_content"));
try {
(new WebDriverWait(driver, 5/* sec */)).until(ExpectedConditions
.presenceOfElementLocated((By.id("com.fittingnzidd.cherripik.development:id/main_content"))));
} catch (org.openqa.selenium.TimeoutException e) {
// System.out.println(e.getMessage());
}
List<WebElement> autoCompleteList = autoComplete
.findElements(By.id("com.fittingnzidd.cherripik.development:id/tv_item_name"));
Thread.sleep(1500);
// autoCompleteList.get(0).click();
if (autoCompleteList.size() == 0) {
System.out.println("Search list NOT foundn");
} else {
System.out.println("Search list Found with elements:" + autoCompleteList.size());
// System.out.println("autoSearch list Found with elements:
// "+autoCompleteList.));
}
for (WebElement ac : autoCompleteList) {
// System.out.println("List Element Text:+"+ac.getText());
if (ac.getText().contains(ActualResultSearch)) {
// System.out.println("List Element Text:+"+ac.getText());
ActualResultRecentLocation = ac.getText();
System.out.println("List Element Text:+" + ActualResultSearch);
// System.out.println("data in acutual search :"+ActualResultSearch);
ac.click();
// Thread.sleep(1000);
break;
}
}
Assert.assertEquals(ActualResultRecentLocation, ActualResultSearch);
boolean AfterSelectionofLocationMapIsdisplayed = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/footer_nav_map_btn")).isDisplayed();
if (AfterSelectionofLocationMapIsdisplayed == true) {
System.out.println("Test Case pass:Brands are successfully displayed on the map n");
} else {
System.out.println("Test Case Failed:Brands are not displayed on the map n");
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.print("Exception is displayed" + e);
e.printStackTrace();
}
}
}

这是我的xml文件,当我运行它时,它只执行3个测试用例

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="10" name="CherriPik" group-by-instances="true">
<classes>
<class name="com.macrosoft.CherryPick.CherryPik"></class>
<class name="com.macrosoft.CherryPick.ToolsReferralCode"> </class>
</classes>
</test> <!-- Regression -->
</suite> <!-- Suite -->

您的设置有几个问题。

这可以通过以下 xml 配置修复

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="5">
<test name="ToolsReferralCode">
<classes>
<class name="pack.thisone.ToolsReferralCode" />
</classes>
</test>
<test name="CherriPik">
<classes>
<class name="pack.thisone.CherryPik" />
</classes>
</test> <!-- Regression -->
</suite>

请注意,每个测试类都是不同<Test>标记的一部分。suite name="Suite" parallel="tests" thread-count="5将确保测试将并行运行。

配置 testng.xml 文件时,代码中还有另一个关键问题。这就是您定义Config类的方式。Config类包含驱动程序,并在@BeforeSuite方法中初始化。然后,所有测试用例都会继承Config类。将测试用例添加到套件下的 xml 文件时,仅调用一次@BeforeSuite方法。因此,您的第一个测试将初始化驱动程序对象,而第二个测试将在尝试调用drivernull。因此,将@BeforeSuite和@AfterSuite替换为@BeforeTest和@AfterTest

public class Configuration {
public String driver;
@BeforeTest
public void cherryPikLaunch() {
System.out.println("Thread" + Thread.currentThread().getId() + " - cherryPikLaunch");
driver = "driver";
}
@AfterTest
public void close_browser() {
System.out.println("Thread" + Thread.currentThread().getId() + " - close_browser");
}
}
public class CherryPik extends Configuration {
@Test(priority = 1)
public void RecentLocation() throws InterruptedException {
System.out.println("Thread" + Thread.currentThread().getId() + " - RecentLocation - " + driver);
}
@Test(priority = 2)
public void SearchLocation() throws InterruptedException {
System.out.println("Thread" + Thread.currentThread().getId() +" - SearchLocation - " + driver);
}
@Test(priority = 3)
public void SearchLocationIsExistInTheRecentLocationList() throws InterruptedException {
System.out.println("Thread" + Thread.currentThread().getId() + " - SearchLocationIsExistInTheRecentLocationList - " + driver);
}
}
public class ToolsReferralCode extends Configuration {
@Test(priority = 1)
public void OpenToolsScreen() {
System.out.println("Thread" + Thread.currentThread().getId() + " - OpenToolsScreen - " + driver);
}
@Test(priority = 2)
public void OnToolsScreenTitlePresist() {
System.out.println("Thread" + Thread.currentThread().getId() + " - OnToolsScreenTitlePresist - " + driver);
}
@Test(priority = 3)
public void VerifyThatYourRefferalButtonIsAvailableOnToolsScreen() {
System.out.println("Thread" + Thread.currentThread().getId()
+ " - VerifyThatYourRefferalButtonIsAvailableOnToolsScreen - " + driver);
}
@Test(priority = 4)
public void OpenYourReferralScreen() {
System.out.println("Thread" + Thread.currentThread().getId() + " - OpenYourReferralScreen - " + driver);
}
@Test(priority = 5)
public void verifyThatRefferalCodeExistOnRefferalScreen() {
System.out.println(
"Thread" + Thread.currentThread().getId() + " - verifyThatRefferalCodeExistOnRefferalScreen - " + driver);
}
}

上面的代码结构将产生以下输出

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Thread12 - cherryPikLaunch
Thread13 - cherryPikLaunch
Thread12 - OpenToolsScreen - driver
Thread13 - RecentLocation - driver
Thread13 - SearchLocation - driver
Thread12 - OnToolsScreenTitlePresist - driver
Thread12 - VerifyThatYourRefferalButtonIsAvailableOnToolsScreen - driver
Thread13 - SearchLocationIsExistInTheRecentLocationList - driver
Thread12 - OpenYourReferralScreen - driver
Thread13 - close_browser
Thread12 - verifyThatRefferalCodeExistOnRefferalScreen - driver
Thread12 - close_browser
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.716 sec - in TestSuite

我在System.out.println中添加了 Thread 编号,以表明两个测试在 2 个线程中并行运行并了解执行顺序。

此外,我还打印了驱动程序的值,以显示驱动程序已在@BeforeTest类中初始化。看看当您将@BeforeTest更改为@BeforeSuite时会发生什么(提示:您将看到空)。

在同一驱动程序实例中运行所有测试的解决方案

要通过只打开一次浏览器来运行所有测试用例,请执行以下操作。

  1. 驱动程序更改为静态,将@BeforeTest和@AfterTest更改为@BeforeSuite和@AfterSuite

    public class Configuration {
    public static String driver;
    @BeforeSuite
    public void cherryPikLaunch() {
    System.out.println("Thread" + Thread.currentThread().getId() + " - cherryPikLaunch");
    driver = "driver";
    }
    @AfterSuite
    public void close_browser() {
    System.out.println("Thread" + Thread.currentThread().getId() + " - close_browser");
    driver = null;
    }
    }
    
  2. 作为静态成员访问测试类中的驱动程序对象Configuration.driver

    public class ToolsReferralCode {
    @Test(priority = 1)
    public void OpenToolsScreen() {
    System.out.println("Thread" + Thread.currentThread().getId() + " - OpenToolsScreen - " + Configuration.driver);
    }
    @Test(priority = 2)
    public void OnToolsScreenTitlePresist() {
    System.out.println("Thread" + Thread.currentThread().getId() + " - OnToolsScreenTitlePresist - " + Configuration.driver);
    }
    @Test(priority = 3)
    public void VerifyThatYourRefferalButtonIsAvailableOnToolsScreen() {
    System.out.println("Thread" + Thread.currentThread().getId()
    + " - VerifyThatYourRefferalButtonIsAvailableOnToolsScreen - " + Configuration.driver);
    }
    @Test(priority = 4)
    public void OpenYourReferralScreen() {
    System.out.println("Thread" + Thread.currentThread().getId() + " - OpenYourReferralScreen - " + Configuration.driver);
    }
    @Test(priority = 5)
    public void verifyThatRefferalCodeExistOnRefferalScreen() {
    System.out.println("Thread" + Thread.currentThread().getId()
    + " - verifyThatRefferalCodeExistOnRefferalScreen - " + Configuration.driver);
    }
    }
    public class CherryPik {
    @Test(priority = 1)
    public void RecentLocation() throws InterruptedException {
    System.out.println("Thread" + Thread.currentThread().getId() + " - RecentLocation - " + Configuration.driver);
    }
    @Test(priority = 2)
    public void SearchLocation() throws InterruptedException {
    System.out.println("Thread" + Thread.currentThread().getId() + " - SearchLocation - " + Configuration.driver);
    }
    @Test(priority = 3)
    public void SearchLocationIsExistInTheRecentLocationList() throws InterruptedException {
    System.out.println("Thread" + Thread.currentThread().getId()
    + " - SearchLocationIsExistInTheRecentLocationList - " + Configuration.driver);
    }
    }
    
  3. 在测试中包含Configuration类,如下所示

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Suite" parallel="none" thread-count="5">
    <test name="ToolsReferralCode">
    <classes>
    <class name="pack.thisone.Configuration"/>
    <class name="pack.thisone.ToolsReferralCode" />
    </classes>
    </test>
    <test name="CherriPik">
    <classes>
    <class name="pack.thisone.CherryPik" />
    </classes>
    </test> <!-- Regression -->
    </suite>
    
  4. suite tag中设置parallel="none"

输出将如下所示

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Thread1 - cherryPikLaunch
Thread1 - OpenToolsScreen - driver
Thread1 - OnToolsScreenTitlePresist - driver
Thread1 - VerifyThatYourRefferalButtonIsAvailableOnToolsScreen - driver
Thread1 - OpenYourReferralScreen - driver
Thread1 - verifyThatRefferalCodeExistOnRefferalScreen - driver
Thread1 - RecentLocation - driver
Thread1 - SearchLocation - driver
Thread1 - SearchLocationIsExistInTheRecentLocationList - driver
Thread1 - close_browser
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.201 sec - in TestSuite

最新更新