使用TestNG对IE /Chrome/firefox 进行兼容性并发测试 ;
package testNGTest; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test; public class MultipleBrowserSearchTest {
public WebDriver driver;
String baseUrl = "http://www.sogou.com/"; @Parameters("browser")
@BeforeClass
public void beforeTest(String Browser) {
if (Browser.equals("firefox")) {
System.setProperty("webdriver.firefox.bin", "D:\\softerWare\\firefox\\firefox\\firefox.exe");
driver = new FirefoxDriver(); } else if (Browser.equals("ie")) {
System.setProperty("webdriver.ie.driver", "D:\\softerWare\\selenium\\IE\\IE_Driver\\IEDriverServer.exe");
driver = new InternetExplorerDriver(); } else if (Browser.equals("chrome")) { System.setProperty("webdriver.chrome.driver", "D:\\softerWare\\selenium\\chromeDriver\\chromedriver.exe");
driver = new ChromeDriver();
}
}
@Test
public void testSogouSearch() {
driver.get(baseUrl);
WebElement inputBox = driver.findElement(By.id("query"));
Assert.assertTrue(inputBox.isDisplayed());
inputBox.sendKeys("关荣的自动化测试 !");
driver.findElement(By.id("stb")).click(); Assert.assertTrue(driver.getPageSource().contains("关荣的自动化测试"));
} @AfterClass
public void afterTest() {
driver.close(); } }
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="3">
<test name="FirefoxTest">
<parameter name="browser" value="firefox"></parameter>
<classes>
<class name="testNGTest.MultipleBrowserSearchTest"/>
</classes>
</test>
<test name="IEText" >
<parameter name="browser" value="ie"/>
<classes>
<class name="testNGTest.MultipleBrowserSearchTest"/>
</classes>
</test>
<test name="ChromeTest">
<parameter name="browser" value="chrome"/>
<classes>
<class name="testNGTest.MultipleBrowserSearchTest"/>
</classes>
</test>
</suite>
说明:直接执行xml中的测试代码;
转自:http://blog.csdn.net/u011138533/article/details/52174446
thread-count
与parallel配套使用,线程池的大小,决定并行线程数量 |
parallel
该参数的值false,methods,tests,classes,instances。默认false
parallel必须和thread-count配套使用,否则相当于无效参数,thread-count决定了并行测试时开启的线程数量
parallel="mehods" TestNG将并行执行所有的测试方法在不同的线程里
parallel="tests" TestNG将并行执行在同一个<test>下的所有方法在不同线程里
parallel="classes" TestNG将并行执行在相同<class>下的方法在不同线程里
parallel="instances" TestNG将并行执行相同实例下的所有方法在不同的线程里