package webdriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Topic_11_Action_Part_II_Thaontp {
WebDriver driver;
String projectPath = System.getProperty("user.dir");
Actions action;
String osName = System.getProperty("os.name");
JavascriptExecutor jsExecutor;
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.gecko.driver", projectPath + "\\browserDrivers\\geckodriver.exe");
// Khởi tạo browser lên
driver = new FirefoxDriver();
jsExecutor = (JavascriptExecutor) driver;
// Set thời gian chờ để tìm được element
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@Test
public void TC_01_Right_Click() {
}
@Test
public void TC_02_Double_Click() {
driver.get("https://automationfc.github.io/basic-form/index.html");
//Double click
WebElement doubleClickButton = driver.findElement(By.xpath("//button[text()='Double click me']"));
// Nếu không Scroll thì trên FF sẽ bị lỗi nên cần sroll
// arguments[0] đại diện cho doubleClick
jsExecutor.executeScript("arguments[0].scrollIntoView(true);", doubleClickButton);
sleepInSecond(3);
action.doubleClick(doubleClickButton).perform();
sleepInSecond(3);
Assert.assertEquals(driver.findElement(By.xpath("//p[text()='Hello Automation Guys!']")).getText(), "Hello Automation Guys!");
}
@Test
public void TC_03_Drag_And_Drop_HTML4() {
}
@Test
public void TC_04_Drag_And_Drop_HTML5() {
}
@Test
public void TC_05_Drag_And_Drop_Xpath() {
}
@AfterClass
public void afterClass() {
driver.quit();
}
public void sleepInSecond(long second) {
try {
Thread.sleep(second * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}