forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImplicitWaitTest.cs
123 lines (107 loc) · 4.28 KB
/
ImplicitWaitTest.cs
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
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Collections.ObjectModel;
namespace OpenQA.Selenium
{
[TestFixture]
public class ImplicitWaitTest : DriverTestFixture
{
[TearDown]
public void ResetImplicitWaitTimeout()
{
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(0));
}
[Test]
[Category("JavaScript")]
public void ShouldImplicitlyWaitForASingleElement()
{
driver.Url = dynamicPage;
IWebElement add = driver.FindElement(By.Id("adder"));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(3000));
add.Click();
driver.FindElement(By.Id("box0")); // All is well if this doesn't throw.
}
[Test]
[Category("JavaScript")]
[ExpectedException(typeof(NoSuchElementException))]
public void ShouldStillFailToFindAnElementWhenImplicitWaitsAreEnabled()
{
driver.Url = dynamicPage;
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500));
driver.FindElement(By.Id("box0"));
}
[Test]
[Category("JavaScript")]
[NeedsFreshDriver]
[ExpectedException(typeof(NoSuchElementException))]
public void ShouldReturnAfterFirstAttemptToFindOneAfterDisablingImplicitWaits()
{
driver.Url = dynamicPage;
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(3000));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(0));
driver.FindElement(By.Id("box0"));
}
[Test]
[Category("JavaScript")]
[NeedsFreshDriver]
public void ShouldImplicitlyWaitUntilAtLeastOneElementIsFoundWhenSearchingForMany()
{
driver.Url = dynamicPage;
IWebElement add = driver.FindElement(By.Id("adder"));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(2000));
add.Click();
add.Click();
ReadOnlyCollection<IWebElement> elements = driver.FindElements(By.ClassName("redbox"));
Assert.GreaterOrEqual(elements.Count, 1);
}
[Test]
[Category("JavaScript")]
[NeedsFreshDriver]
public void ShouldStillFailToFindAnElemenstWhenImplicitWaitsAreEnabled()
{
driver.Url = dynamicPage;
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500));
ReadOnlyCollection<IWebElement> elements = driver.FindElements(By.ClassName("redbox"));
Assert.AreEqual(0, elements.Count);
}
[Test]
[Category("JavaScript")]
[NeedsFreshDriver]
public void ShouldReturnAfterFirstAttemptToFindManyAfterDisablingImplicitWaits()
{
driver.Url = dynamicPage;
IWebElement add = driver.FindElement(By.Id("adder"));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(1100));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(0));
add.Click();
ReadOnlyCollection<IWebElement> elements = driver.FindElements(By.ClassName("redbox"));
Assert.AreEqual(0, elements.Count);
}
[Test]
[IgnoreBrowser(Browser.IE)]
[IgnoreBrowser(Browser.PhantomJS)]
[IgnoreBrowser(Browser.Android)]
[IgnoreBrowser(Browser.IPhone)]
[IgnoreBrowser(Browser.Safari)]
public void ShouldImplicitlyWaitForAnElementToBeVisibleBeforeInteracting()
{
driver.Url = dynamicPage;
IWebElement reveal = driver.FindElement(By.Id("reveal"));
IWebElement revealed = driver.FindElement(By.Id("revealed"));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(5000));
Assert.IsFalse(revealed.Displayed, "revealed should not be visible");
reveal.Click();
try
{
revealed.SendKeys("hello world");
// This is what we want
}
catch (ElementNotVisibleException)
{
Assert.Fail("Element should have been visible");
}
}
}
}