使用TestNG对IE /Chrome/firefox 进行兼容性并发测试 ;
![]()
1 package testNGTest;
2
3 import org.openqa.selenium.By;
4 import org.openqa.selenium.WebDriver;
5 import org.openqa.selenium.WebElement;
6 import org.openqa.selenium.chrome.ChromeDriver;
7 import org.openqa.selenium.firefox.FirefoxDriver;
8 import org.openqa.selenium.ie.InternetExplorerDriver;
9 import org.testng.Assert;
10 import org.testng.annotations.AfterClass;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.Parameters;
13 import org.testng.annotations.Test;
14
15
16 public class MultipleBrowserSearchTest {
17 public WebDriver driver;
18 String baseUrl = "http://www.sogou.com/";
19
20 @Parameters("browser")
21 @BeforeClass
22 public void beforeTest(String Browser) {
23 if (Browser.equals("firefox")) {
24 System.setProperty("webdriver.firefox.bin", "D:\\softerWare\\firefox\\firefox\\firefox.exe");
25 driver = new FirefoxDriver();
26
27
28 } else if (Browser.equals("ie")) {
29 System.setProperty("webdriver.ie.driver", "D:\\softerWare\\selenium\\IE\\IE_Driver\\IEDriverServer.exe");
30 driver = new InternetExplorerDriver();
31
32 } else if (Browser.equals("chrome")) {
33
34 System.setProperty("webdriver.chrome.driver", "D:\\softerWare\\selenium\\chromeDriver\\chromedriver.exe");
35 driver = new ChromeDriver();
36 }
37 }
38 @Test
39 public void testSogouSearch() {
40 driver.get(baseUrl);
41 WebElement inputBox = driver.findElement(By.id("query"));
42 Assert.assertTrue(inputBox.isDisplayed());
43 inputBox.sendKeys("关荣的自动化测试 !");
44 driver.findElement(By.id("stb")).click();
45
46 Assert.assertTrue(driver.getPageSource().contains("关荣的自动化测试"));
47 }
48
49 @AfterClass
50 public void afterTest() {
51 driver.close();
52
53 }
54
55 }
View Code