-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestFluentWait.java
More file actions
132 lines (100 loc) · 3.47 KB
/
Copy pathTestFluentWait.java
File metadata and controls
132 lines (100 loc) · 3.47 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package testcase;
import java.util.concurrent.TimeUnit;
import helper.LinkHelper;
import helper.StartWebDriver;
import helper.TextBoxHelper;
import helper.WindowHelper;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
* @author - rahul.rathore
* @date - 16-Nov-2014
* @project - Webdriver
* @package - testcase
* @file name - TestFluentWait.java
*/
public class TestFluentWait extends StartWebDriver {
@Test
public static void fwait() {
WindowHelper.navigateToPage("http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_suggest");
//driver.switchTo().frame(driver.findElement(By.id("iframeResult")));
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
FluentWait<WebDriver> fw = new FluentWait<WebDriver>(driver);
fw.withTimeout(5, TimeUnit.SECONDS);
fw.pollingEvery(1, TimeUnit.SECONDS);
fw.ignoring(NoSuchElementException.class);
Function<WebDriver,WebElement> fun= new Function<WebDriver,WebElement> (){
public WebElement apply(WebDriver driver) {
System.out.println("Element searching");
return driver.findElement(By.id("twotabsearchtextbox"));
}
};
fw.until(fun).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("Element Found");
}
@Test
public void testWait(){
// driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//1 driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
/*LinkHelper.clickLink("File");
//step- 1
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
//step - 2
wait.withTimeout(30, TimeUnit.SECONDS);
//step - 3
wait.pollingEvery(5, TimeUnit.MILLISECONDS);
//step - 4
wait.ignoring(NoSuchElementException.class);
Function<WebDriver, WebElement> fun = new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver arg0) {
System.out.println("Not Found");
return arg0.findElement(By.id("log_in"));
}
};
wait.until(fun).click();
System.out.println("Element Found");*/
WindowHelper.navigateToPage("http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_suggest");
driver.switchTo().frame(driver.findElement(By.id("iframeResult")));
FluentWait<WebElement> wait = new FluentWait<WebElement>(driver.findElement(By.id("txtHint")));
wait.withTimeout(30, TimeUnit.SECONDS);
wait.pollingEvery(1, TimeUnit.MILLISECONDS);
Function<WebElement, Boolean> fun = new Function<WebElement, Boolean>() {
@Override
public Boolean apply(WebElement arg0) {
if(!arg0.getText().equalsIgnoreCase("")){
System.out.println("Text : " + arg0.getText());
return true;
}
else{
System.err.println("Not Found");
return false;
}
}
};
/*Predicate<WebElement> p = new Predicate<WebElement>() {
@Override
public boolean apply(WebElement arg0) {
if(!arg0.getText().equalsIgnoreCase("")){
System.out.println("Text : " + arg0.getText());
return true;
}
else{
System.err.println("Not Found");
return false;
}
}
};*/
TextBoxHelper.typeInTextBox("txt1", "j");
wait.until(fun);
}
}