1. Multi Browser Testing là gì ?
- Multi Browser Test có nghĩa là test trên nhiều trình duyệt khác nhau
2. Làm sao để có thể test trên nhiều trình duyệt khác nhau ?
3. Ví dụ về Multi Browser
File MultiBrowserTest.java
package tests;
import org.testng.annotations.Test;
import utils.Constants;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
public class MultiBrowserTest {
WebDriver driver;
@Test
//Phương thức này chứa test case login
public void LoginTest() {
driver.findElement(By.className("login")).click();
driver.findElement(By.id("email")).sendKeys("hocautotest@gmail.com");
driver.findElement(By.id("passwd")).sendKeys("12345678");
driver.findElement(By.id("SubmitLogin")).click();
driver.findElement(By.className("logout")).click();
}
@BeforeMethod
@Parameters("browser")
//Parameters này sẽ có tên giống với Parameter trong file MultiBrowserTest.xml
public void Setup(String browser) {
System.setProperty("webdriver.chrome.driver",
"D:\\Work\\Automation Test\\Selenium\\Tool\\Selenium\\Library\\Selenium-java-3.141.59 and Driver\\chromedriver.exe");
System.setProperty("webdriver.gecko.driver",
"D:\\Work\\Automation Test\\Selenium\\Tool\\Selenium\\Library\\Selenium-java-3.141.59 and Driver\\geckodriver.exe");
System.setProperty("webdriver.ie.driver",
"D:\\Work\\Automation Test\\Selenium\\Tool\\Selenium\\Library\\Selenium-java-3.141.59 and Driver\\IEDriverServer.exe");
//Nếu biến browser có có giá trị bằng firefox thì khởi tạo FireFox Driver, nếu biến browser có có giá trị bằng ie thì khởi tạo IE Driver, còn nếu không thì khởi tạo Chrome Driver
if (browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("ie")) {
driver = new InternetExplorerDriver();
} else {
driver = new ChromeDriver();
}
driver.manage().window().maximize();
driver.get("http://automationpractice.com/index.php");
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
0 Bình luận:
Đăng nhận xét