Java selenium中的Testng------建议适合哪些注释
我在Eclipse中创建了如下项目(页面对象模型) 项目名称 包1 src 箱子 方案2 src 垃圾箱 包1中包含元素说明和方法 在包2中包含: BaseScript.java--------- 预断Java selenium中的Testng------建议适合哪些注释,java,selenium-webdriver,testng,testng-eclipse,Java,Selenium Webdriver,Testng,Testng Eclipse,我在Eclipse中创建了如下项目(页面对象模型) 项目名称 包1 src 箱子 方案2 src 垃圾箱 包1中包含元素说明和方法 在包2中包含: BaseScript.java--------- 预断 webdriver driver=new FirefoxDriver(); driver.get("url"); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
webdriver driver=new FirefoxDriver();
driver.get("url");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().window().maximize();
LoginPage l=new LoginPage(driver);
l.setusername("");
l.setpassword("");
l.LoginBut();
后置条件
driver.quit()
我已经将T1.java、T2.java转换为.xml(testng.xml)并使用testng文件(testng.xml)运行
我想用一个浏览器一次执行所有的测试用例,但当我执行测试用例时,我得到了它的调用BaseScript.java
Selenium
是一个像用户一样控制浏览器/网站的工具。它模拟用户在页面中单击。了解web应用程序的功能后,可以设置测试。现在一起运行一组测试用例,即测试套件TestNG
提供了管理测试执行的功能
我建议您阅读这个简单的TestNG测试套件
我希望一次执行所有测试用例
Selenium网格是Selenium套件的一部分,用于并行运行测试。您可以在基类中设置驱动程序
public class TestBase {
protected ThreadLocal<RemoteWebDriver> threadDriver = null;
@BeforeMethod
public void setUp() throws MalformedURLException {
threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities dc = new DesiredCapabilities();
FirefoxProfile fp = new FirefoxProfile();
dc.setCapability(FirefoxDriver.PROFILE, fp);
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
threadDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc));
}
public WebDriver getDriver() {
return threadDriver.get();
}
@AfterMethod
public void closeBrowser() {
getDriver().quit();
}
}
您可以以与上面类似的方式添加更多测试
public class Test02 extends TestBase {
@Test
public void testLink()throws Exception {
// test goes here
}
}
TestNG配置:
testng.xml
testFiles.xml
我知道如何转换testng.xml,但我对注释感到困惑
public class Test02 extends TestBase {
@Test
public void testLink()throws Exception {
// test goes here
}
}
<suite name="My Test Suite">
<suite-files>
<suite-file path="./testFiles.xml" />
</suite-files>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test runs" parallel="tests" thread-count="2">
<test name="T_01">
<classes>
<class name="com.package.name.Test01" ></class>
</classes>
</test>
<test name="T_02">
<classes>
<class name="com.package.name.Test02" ></class>
</classes>
</test>
<!-- more tests -->
</suite>