forked from TalhaBinAshraf1/SeleniumTestingInternetHerokuApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowActions.java
More file actions
54 lines (46 loc) · 1.7 KB
/
Copy pathWindowActions.java
File metadata and controls
54 lines (46 loc) · 1.7 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
package allTests;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.NoSuchWindowException;
public class WindowActions extends BaseTest{
public void switchToParentWindow() {
Set<String> parentWindowHandle = driver.getWindowHandles();
List<String> windowList = new ArrayList<String>(parentWindowHandle);
if(windowList.size() > 0) {
driver.switchTo().window(windowList.get(0));
}else {
throw new NoSuchWindowException("Parent window does not exist");
}
}
public void switchToWindow(int windowindex) {
Set<String> windowHandle = driver.getWindowHandles();
List<String> windowList = new ArrayList<String>(windowHandle);
if(windowindex < windowHandle.size()) {
driver.switchTo().window(windowList.get(windowindex));
}else {
throw new NoSuchWindowException("Window does not exist with index: "+windowindex);
}
}
public void closeWindow(int windowindex) {
Set<String> windowHandle = driver.getWindowHandles();
List<String> windowList = new ArrayList<String>(windowHandle);
if(windowindex < windowHandle.size()) {
driver.switchTo().window(windowList.get(windowindex)).close();
}else {
throw new NoSuchWindowException("Window with index: "+windowindex+" does not exist ");
}
}
public void closeAllChildWindows() {
Set<String> windowHandle = driver.getWindowHandles();
List<String> windowList = new ArrayList<String>(windowHandle);
for(int i=1; i < windowList.size(); i++) {
driver.switchTo().window(windowList.get(i)).close();
}
}
public int getWindowCount() {
Set<String> windowHandle = driver.getWindowHandles();
List<String> windowList = new ArrayList<String>(windowHandle);
return windowList.size();
}
}