我设法与不同的浏览器并行运行我的测试,现在它看起来很好 我在@BeforeTest部分创建我的驱动程序并在@AfterTest中杀死它,线程很好(每个浏览器一个),启动并停止正常 我在不同的类中有很多使用我的驱动程序的函数,所以我想知道是否有某种方法来分享"它到整个项目 我知道我可以将驱动程序作为参数传递给其他类,但在其他方面会更容易:-)
有什么建议吗?
Public class Test1 {
protected static WebDriver driver;
@BeforeTest
@Parameters({ "browser", "HUBip" })
public void launchBrowser(@Optional("FF") String browser, @Optional("localhost") String HUBip) throws MalformedURLException {
try {
if (browser.equalsIgnoreCase("Chrome")) {
DesiredCapabilities caps=DesiredCapabilities.chrome();
driver=new ScreenShotRemoteWebDriver(url, caps);
} else if (browser.equalsIgnoreCase("FF")) {
DesiredCapabilities caps=DesiredCapabilities.firefox();
driver=new ScreenShotRemoteWebDriver(url, caps);
} else {
DesiredCapabilities caps=DesiredCapabilities.internetExplorer();
driver=new ScreenShotRemoteWebDriver(url, caps);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Parameters("browser")
@Test(testName="Quick SMS SmokeTest",description="Smoke test 'Quick SMS'section", groups="SmokeTest")
public void quickSMS_SmokeTest(@Optional("IE") String browser) throws Exception {
try {
LogIn(driver,ObjectsPaths.ADMIN_USER,ObjectsPaths.ADMIN_PASSWORD);
} catch (Exception e) {
Reporter.log("from exception" + e.toString());
}
}
@AfterTest
public void closeBrowser() throws Exception {
driver.quit();
}
<suite name="Automated Tests" verbose="2" preserve-order="false" parallel="tests" alwaysRun="true" thread-count="2">
<test name="Test1FF" preserve-order="true">
<parameter name="browser" value="ff" ></parameter>
<classes>
<class name="com.AutoTest.test.Test1" />
</classes>
</test>
<test name="Test1IE" preserve-order="true">
<parameter name="browser" value="ie" ></parameter>
<classes>
<class name="com.AutoTest.test.Test1" />
</classes>
</test>
</suite>
答案 0 :(得分:0)
我实现为整个套件维护一个webdriver的方式如下:
public class TestCaseOne extends TestSuiteOneBase{
//This contains the methods and classes for the test cases
@BeforeTest
@Test
@Test
@AfterTest
}
public class TestSuiteOne extends TestSuiteManager{
//some common methods to be used across the suite
}
public class TestSuiteManager{
//preCondition methods
//Driver is declared here so it's visible across all other objects.
}
希望这有帮助。