-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSynchronise.java
More file actions
113 lines (80 loc) · 3.28 KB
/
Synchronise.java
File metadata and controls
113 lines (80 loc) · 3.28 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package module3;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Synchronise {
static WebDriver driver;
private static String url = "https://www.edureka.co";
@BeforeClass
public static void setupTest() {
logInfo("Start chrome browser");
System.setProperty("webdriver.chrome.driver", "C:\\2018\\edureka\\selenium\\EXEs\\chromedriver.exe");
driver = new ChromeDriver();
logInfo("Set the page load timeout for any page load");
driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS);
logInfo("Navigate to url : " + url);
driver.navigate().to(url);
logInfo("Maximize window");
driver.manage().window().maximize();
}
@Test
public void browserWaitExampleTest() throws Exception {
JavascriptExecutor js = (JavascriptExecutor) driver;
logInfo("Set implicit wait for all the activities on the browser");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
logInfo("Set selenium script timeout");
driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
logInfo("Execute any asynchronous script");
js.executeAsyncScript("window.setTimeout(arguments[arguments.length - 1], 500);");
// Start to find web elements
logInfo("Search for Selenium course in the search box");
WebElement searchBox = FindElement(driver, By.id("homeSearchBar"), 4);
searchBox.sendKeys("Selenium");
searchBox.sendKeys(Keys.RETURN);
logInfo("Click selenium course");
FindElement(driver, By.linkText("Selenium Certification Training"), 4).click();
String validTitle = "Selenium 3.0 WebDriver Online Training | Selenium Certification Course | Edureka";
String pageTitle = driver.getTitle();
logInfo("getTitle : " + pageTitle);
boolean result = pageTitle.equals(validTitle);
logInfo("Validate the page title : Result *** " + result);
logInfo("Navigate back");
driver.navigate().back();
logInfo("Click All Courses");
String xpath_AllCourses = "(//a[contains(text(),'All Courses')])[2]";
FindElement(driver, By.xpath(xpath_AllCourses), 4).click();
WebElement element = FindElement(driver, By.id("loadMoreCoursesAll"), 4);
logInfo("JavaScript page loading complete");
}
@AfterClass
public static void quitDriver() {
logInfo("Closing the browser");
driver.quit();
logInfo("DONE!");
}
private static WebElement FindElement(WebDriver driver, By by, int timeoutInSeconds) {
try {
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.presenceOfElementLocated(by));
logInfo( "FindElement *** " + by + " *** Found");
return driver.findElement(by);
} catch (Exception e) {
e.printStackTrace();
}
logInfo( "FindElement --> " + by + " --> Not found");
return null;
}
public static void logInfo(String msg) {
System.out.println( LocalDateTime.now() + " : " + msg );
}
}