-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test03.cs
112 lines (95 loc) · 3.69 KB
/
Test03.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
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/* Test Project #3 - NUnit Framework with Additional Web Elements
* User Registration Form
* SetUp & TearDown Attributes
*/
namespace TestingProject01
{
class Test03
{
// 2. Class properties
private IWebDriver driver;
private string webUrl = "http://sdettraining.com/trguitransactions/Account.aspx";
[SetUp]
public void Setup()
{
// 9. Cross-Browser Testing
string browserType = "Chrome";
if (browserType.Equals("chrome"))
{
driver = new ChromeDriver();
}
else if (browserType.Equals("Firefox"))
{
driver = new FirefoxDriver();
}
else if (browserType.Equals("IE"))
{
driver = new InternetExplorerDriver();
}
else
{
driver = new FirefoxDriver();
browserType = "Firefox";
}
// 1. Setup method
// driver = new FirefoxDriver();
// 8. Manage WebDriver
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
driver.Navigate().GoToUrl(webUrl);
Console.WriteLine("Starting Test using " + browserType.ToUpper());
}
[TearDown]
public void TearDown()
{
// 5. TearDown
driver.Quit();
Console.WriteLine("Ending Test");
}
[Test]
public void NewAccountTest()
{
Console.WriteLine("Running New Account Test");
// 4. Test Steps
driver.FindElement(By.Id("createaccount")).Click();
//Thread.Sleep(1000);
driver.FindElement(By.Id("MainContent_txtFirstName")).SendKeys("Tim");
driver.FindElement(By.Id("MainContent_txtLastName")).SendKeys("Short");
// Radio button: Click
driver.FindElement(By.Id("MainContent_Male")).Click();
driver.FindElement(By.Id("MainContent_txtEmail")).SendKeys("tim2@testemail.com");
driver.FindElement(By.Id("MainContent_txtPassword")).SendKeys("password");
driver.FindElement(By.Id("MainContent_txtVerifyPassword")).SendKeys("password");
driver.FindElement(By.Id("MainContent_txtHomePhone")).SendKeys("8887863033");
driver.FindElement(By.Id("MainContent_txtCellPhone")).SendKeys("8887863033");
// Drop-Down: new SelectElement from Selenium.Support
new SelectElement(driver.FindElement(By.Id("MainContent_menuCountry"))).SelectByText("Italy");
// Checkbox: Click
driver.FindElement(By.Id("MainContent_checkWeeklyEmail")).Click();
driver.FindElement(By.Id("MainContent_checkUpdates")).Click();
// TextArea: SendKeys
driver.FindElement(By.Id("MainContent_txtInstructions")).SendKeys("Signing up!");
//Thread.Sleep(2000);
driver.FindElement(By.Id("MainContent_btnSubmit")).Click();
// 9. Assert
Thread.Sleep(1000);
string result = driver.FindElement(By.Id("MainContent_lblTransactionResult")).Text;
string expected = "success";
Console.WriteLine("Confirmation: " + result);
// Assert.Equals(expected, result);
StringAssert.Contains(expected, result);
}
}
}