-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChromeJSTest.java
76 lines (62 loc) · 2.61 KB
/
ChromeJSTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package tests.web;
import org.junit.Test;
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.JavascriptExecutor;
public class ChromeJSTest {
private WebDriver driver;
public ChromeJSTest() {
System.setProperty("webdriver.chrome.driver", "C:/Drivers/chromedriver.exe");
driver = new ChromeDriver();
}
@Test
public void testSelenium() {
driver.get("https://experitest.com");
WebElement footer = driver.findElement(By.className("book-demo-btn"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", footer);
}
@Test
public void locateElement() {
driver.get("https://experitest.com");
WebElement startButton = ((JavascriptExecutor) driver).executeScript("document.getElementsByTagName('a')[13];");
}
@Test
public void clickElement1() {
driver.get("https://experitest.com");
((JavascriptExecutor) driver).executeScript("document.getElementsByTagName('a')[13].click();");
}
@Test
public void clickElement2() {
driver.get("https://experitest.com");
WebElement startButton = ((JavascriptExecutor) driver).executeScript("document.getElementsByTagName('a')[13];");
((JavascriptExecutor) driver).executeScript("arguments[0].click();", startButton );
}
@Test
public void printAlert() {
driver.get("https://experitest.com");
((JavascriptExecutor) driver).executeScript("alert('Welcome to Experitest');");
}
@Test
public void scrollToElement() {
driver.get("https://experitest.com");
WebElement footerBtn = driver.findElement(By.className("book-demo-btn"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", footerBtn);
}
@Test
public void changeStyle() {
driver.get("https://experitest.com");
((JavascriptExecutor) driver).executeScript("document.getElementsByTagName('a')[13].style.border = '3px dotted blue'");
}
@Test
public void implementWaits() {
driver.get("https://experitest.com");
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
long start = System.currentTimeMillis();
((JavascriptExecutor) driver).executeAsyncScript(
"window.setTimeout(arguments[arguments.length - 1], 5000);");
((JavascriptExecutor) driver).executeScript("alert('Waited for ' + arguments[0] + ' seconds');",
(System.currentTimeMillis() - start) / 1000);
}
}