forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestConfirmations.cs
76 lines (72 loc) · 2.94 KB
/
TestConfirmations.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
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Text.RegularExpressions;
namespace Selenium.Tests
{
[TestFixture]
public class TestConfirmations : SeleniumTestCaseBase
{
[Ignore("setting property on window object cross-navigation does not work properly")]
public void Confirmations()
{
selenium.Open("../tests/html/test_confirm.html");
selenium.ChooseCancelOnNextConfirmation();
selenium.Click("confirmAndLeave");
Assert.IsTrue(selenium.IsConfirmationPresent());
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if (selenium.IsConfirmationPresent())
{
break;
}
}
catch (Exception) { }
System.Threading.Thread.Sleep(1000);
}
Assert.IsTrue(selenium.IsConfirmationPresent());
Assert.AreEqual(selenium.GetConfirmation(), "You are about to go to a dummy page.");
Assert.AreEqual(selenium.GetTitle(), "Test Confirm");
selenium.Click("confirmAndLeave");
selenium.WaitForPageToLoad("30000");
Assert.IsTrue(Regex.IsMatch(selenium.GetConfirmation(), "^[\\s\\S]*dummy page[\\s\\S]*$"));
Assert.AreEqual(selenium.GetTitle(), "Dummy Page");
selenium.Open("../tests/html/test_confirm.html");
Assert.AreEqual(selenium.GetTitle(), "Test Confirm");
selenium.ChooseCancelOnNextConfirmation();
selenium.ChooseOkOnNextConfirmation();
selenium.Click("confirmAndLeave");
selenium.WaitForPageToLoad("30000");
Assert.IsTrue(Regex.IsMatch(selenium.GetConfirmation(), "^[\\s\\S]*dummy page[\\s\\S]*$"));
Assert.AreEqual(selenium.GetTitle(), "Dummy Page");
selenium.Open("../tests/html/test_confirm.html");
try
{
Assert.AreEqual(selenium.GetConfirmation(), "This should fail - there are no confirmations");
Assert.Fail("expected failure");
}
catch (Exception) { }
selenium.Click("confirmAndLeave");
selenium.WaitForPageToLoad("30000");
try
{
Assert.AreEqual(selenium.GetConfirmation(), "this should fail - wrong confirmation");
Assert.Fail("expected failure");
}
catch (Exception) { }
selenium.Open("../tests/html/test_confirm.html");
selenium.Click("confirmAndLeave");
selenium.WaitForPageToLoad("30000");
try
{
selenium.Open("../tests/html/test_confirm.html");
Assert.Fail("expected failure");
}
catch (Exception) { }
}
}
}