forked from florentbr/SeleniumBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTS_Alert.cs
More file actions
81 lines (70 loc) · 3 KB
/
TS_Alert.cs
File metadata and controls
81 lines (70 loc) · 3 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
using Selenium.Tests.Internals;
using A = NUnit.Framework.Assert;
using TestCase = NUnit.Framework.TestCaseAttribute;
using TestFixture = NUnit.Framework.TestFixtureAttribute;
using ExpectedException = NUnit.Framework.ExpectedExceptionAttribute;
namespace Selenium.Tests {
[TestFixture(Browser.Firefox)]
[TestFixture(Browser.Opera)]
[TestFixture(Browser.Chrome)]
[TestFixture(Browser.IE)]
//[TestFixture(Browser.PhantomJS)]
class TS_Alert : BaseBrowsers {
public TS_Alert(Browser browser)
: base(browser) { }
[TestCase]
public void ShouldCloseAlert() {
driver.Get("/input.html");
driver.ExecuteScript("window.setTimeout(function(){alert('test close');}, 100);");
var alert = driver.SwitchToAlert();
A.AreEqual("test close", alert.Text);
alert.Accept();
A.Null(driver.SwitchToAlert(0, false));
}
[TestCase]
public void ShouldDismissAlert() {
driver.Get("/input.html");
driver.ExecuteScript("window.setTimeout(function(){window.res=window.confirm('test accept');}, 100);");
var alert = driver.SwitchToAlert();
A.AreEqual("test accept", alert.Text);
alert.Accept();
A.True((bool)driver.ExecuteScript("return window.res;"));
A.Null(driver.SwitchToAlert(0, false));
}
[TestCase]
public void ShouldAcceptAlert() {
driver.Get("/input.html");
driver.ExecuteScript("window.setTimeout(function(){window.res=window.confirm('test dismiss');}, 100);");
var alert = driver.SwitchToAlert();
A.AreEqual("test dismiss", alert.Text);
alert.Dismiss();
A.False((bool)driver.ExecuteScript("return window.res;"));
A.Null(driver.SwitchToAlert(0, false));
}
[TestCase]
public void ShouldSendKeysToAlert() {
driver.Get("/input.html");
driver.ExecuteScript("window.setTimeout(function(){window.res=window.prompt('test prompt','defaultText');}, 100);");
var alert = driver.SwitchToAlert();
A.AreEqual("test prompt", alert.Text);
alert.SendKeys("abcd");
alert.Accept();
A.AreEqual("abcd", (string)driver.ExecuteScript("return window.res;"));
A.Null(driver.SwitchToAlert(0, false));
}
[TestCase]
[ExpectedException(typeof(Selenium.Errors.NoAlertPresentError))]
public void ShouldThrowMissingAlert() {
driver.Get("/input.html");
var alert = driver.SwitchToAlert(0);
}
[TestCase]
[ExpectedException(typeof(Selenium.Errors.UnexpectedAlertOpenError))]
public void ShouldThrowUnexpectedAlert() {
driver.Get("/input.html");
driver.ExecuteScript("window.setTimeout(function(){window.alert('na');}, 0);");
var ele = driver.FindElementById("input__search");
ele.Clear();
}
}
}