forked from TalhaBinAshraf1/SeleniumTestingInternetHerokuApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewTab.java
More file actions
63 lines (53 loc) · 2.15 KB
/
Copy pathNewTab.java
File metadata and controls
63 lines (53 loc) · 2.15 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
package allTests;
import java.util.Set;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import resources.UITestPracticePage;
import utility.FrameworkConstants;
public class NewTab {
public static void main(String[] args) {
System.setProperty(FrameworkConstants.CHROME_DRIVER_KEY,FrameworkConstants.CHROME_DRIVER_PATH);
WebDriver driver = new ChromeDriver();
driver.get("http://uitestpractice.com/Students/");
System.out.println(driver.getCurrentUrl());
String parentHandle = driver.getWindowHandle();
System.out.println("Parent handle id : "+parentHandle);
UITestPracticePage.using(driver).clickNewTabLink(driver);
waitForPageLoadComplete(driver);
Set<String> handles = driver.getWindowHandles();
System.out.println("no of tabs : "+handles.size());
for(String handleStr:handles) {
if(!handleStr.equals(parentHandle)) {
System.out.println(handleStr);
driver.switchTo().window(handleStr);
}
}
String childHandle = driver.getWindowHandle();
System.out.println("Child handle id : "+childHandle);
driver.switchTo().window(parentHandle);
// WebDriverWait wait = new WebDriverWait(driver, 5);
// wait.until(ExpectedConditions.visibilityOf(UITestPracticePage.using(driver).containerBlue));
// UITestPracticePage.using(driver).body.sendKeys(Keys.CONTROL + "\t");
//
driver.quit();
}
public static void waitForPageLoadComplete(WebDriver driver){
ExpectedCondition<Boolean> pageLoadCondition = new
ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}
}