forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestAlerts.cs
95 lines (89 loc) · 3.12 KB
/
TestAlerts.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
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Text.RegularExpressions;
namespace Selenium.Tests
{
[TestFixture]
public class TestAlerts : SeleniumTestCaseBase
{
[Test]
public void testAlerts()
{
selenium.Open("../tests/html/test_verify_alert.html");
Assert.IsFalse(selenium.IsAlertPresent());
selenium.Click("oneAlert");
Assert.IsTrue(selenium.IsAlertPresent());
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try { if (selenium.IsAlertPresent()) break; }
catch (Exception) { }
System.Threading.Thread.Sleep(1000);
}
Assert.IsTrue(selenium.IsAlertPresent());
Assert.AreEqual(selenium.GetAlert(), "Store Below 494 degrees K!");
selenium.Click("multipleLineAlert");
Assert.AreEqual(selenium.GetAlert(), "This alert spans multiple lines");
selenium.Click("oneAlert");
string myVar = selenium.GetAlert();
Assert.AreEqual(myVar, "Store Below 494 degrees K!");
selenium.Click("twoAlerts");
Assert.IsTrue(Regex.IsMatch(selenium.GetAlert(), "^[\\s\\S]* 220 degrees C!$"));
Assert.IsTrue(Regex.IsMatch(selenium.GetAlert(), "^Store Below 429 degrees F!"));
selenium.Click("alertAndLeave");
selenium.WaitForPageToLoad("30000");
//Assert.AreEqual(selenium.GetAlert(), "I'm Melting! I'm Melting!");
string alertText = string.Empty;
selenium.Open("../tests/html/test_verify_alert.html");
try
{
alertText = selenium.GetAlert();
Assert.AreEqual(alertText, "noAlert");
Assert.Fail("expected failure");
}
catch (Exception)
{
}
selenium.Click("oneAlert");
try
{
alertText = selenium.GetAlert();
Assert.AreEqual(alertText, "wrongAlert");
Assert.Fail("expected failure");
}
catch (Exception)
{
}
selenium.Click("twoAlerts");
try
{
alertText = selenium.GetAlert();
Assert.AreEqual(alertText, "Store Below 429 degrees F!");
Assert.Fail("expected failure");
}
catch (Exception)
{
}
try
{
alertText = selenium.GetAlert();
Assert.AreEqual(alertText, "Store Below 220 degrees C!");
Assert.Fail("expected failure");
}
catch (Exception)
{
}
selenium.Click("oneAlert");
try
{
selenium.Open("../tests/html/test_verify_alert.html");
Assert.Fail("expected failure");
}
catch (Exception)
{
}
}
}
}