1
|
using System.Linq;
|
2
|
using System.Text;
|
3
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
4
|
using OpenQA.Selenium;
|
5
|
using OpenQA.Selenium.Chrome;
|
6
|
using OpenQA.Selenium.Firefox;
|
7
|
|
8
|
using System;
|
9
|
using System.Collections;
|
10
|
using System.Collections.Generic;
|
11
|
using System.Threading;
|
12
|
|
13
|
|
14
|
namespace FrontendTesting
|
15
|
{
|
16
|
[TestClass]
|
17
|
public class LoginTesting
|
18
|
{
|
19
|
//defining variables needed for testing
|
20
|
public string url = "http://localhost:3000/login";
|
21
|
public By usernameField = By.Id("login_username");
|
22
|
public By passwordField = By.Id("login_password");
|
23
|
public By loginButton = By.XPath("/html/body/div[1]/div/div/div[2]/main/form/div[3]/div/div/div/button");
|
24
|
public By userButton = By.XPath("/html/body/div[1]/div/div[1]/ul/li[2]/div/span");
|
25
|
public By logoutButton = By.XPath("/html/body/div[3]/div/div/ul/li/span");
|
26
|
public string[] usernames = { "aaa", "bbb", "ccc"};
|
27
|
public string[] passwords = { "aaa", "bbb", "ccc" };
|
28
|
|
29
|
|
30
|
/**
|
31
|
Names of tests should be self-explanatory
|
32
|
tests are separated, becouse there were problems with multiple tests runs in one method
|
33
|
tests contain thread.sleep becouse of waiting on components to load (if I find better and reasonable solution, I will change it)
|
34
|
*/
|
35
|
|
36
|
|
37
|
[TestMethod]
|
38
|
//dummy method for constructing tests
|
39
|
public void Login_Dummy()
|
40
|
{
|
41
|
var driver = Drivers.cDriver;
|
42
|
driver.Navigate().GoToUrl(url);
|
43
|
Thread.Sleep(3000);
|
44
|
driver.FindElement(usernameField).SendKeys("aaa"); //enter username
|
45
|
Thread.Sleep(1000);
|
46
|
driver.FindElement(passwordField).SendKeys("aaa"); //enter password
|
47
|
Thread.Sleep(1000);
|
48
|
driver.FindElement(loginButton).Click(); //click on login
|
49
|
Thread.Sleep(5000);
|
50
|
Assert.AreEqual(driver.Url, "http://localhost:3000/documents/annotator");
|
51
|
driver.Navigate().GoToUrl(url);
|
52
|
driver.Close();
|
53
|
driver.Quit();
|
54
|
}
|
55
|
|
56
|
|
57
|
// methods with correct usernames and passwords
|
58
|
[TestMethod]
|
59
|
public void Login_Correct_Annotator_Firefox()
|
60
|
{
|
61
|
var driver = new FirefoxDriver();
|
62
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
63
|
Thread.Sleep(3000);
|
64
|
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username
|
65
|
driver.FindElement(passwordField).SendKeys(passwords[0]); //enter password
|
66
|
driver.FindElement(loginButton).Click(); //click on login
|
67
|
Thread.Sleep(3000);
|
68
|
Assert.AreEqual(driver.Url, "http://localhost:3000/documents/annotator"); //check if your url is changed on this
|
69
|
driver.Navigate().GoToUrl(url); //return back on login screen (effectively logout, becouse logout button was too hard to click)
|
70
|
driver.Close();
|
71
|
driver.Quit();
|
72
|
}
|
73
|
[TestMethod]
|
74
|
public void Login_Correct_Admin_Firefox()
|
75
|
{
|
76
|
var driver = new FirefoxDriver();
|
77
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
78
|
Thread.Sleep(3000);
|
79
|
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username
|
80
|
driver.FindElement(passwordField).SendKeys(passwords[2]); //enter password
|
81
|
driver.FindElement(loginButton).Click(); //click on login
|
82
|
Thread.Sleep(3000);
|
83
|
Assert.AreEqual(driver.Url, "http://localhost:3000/documents/admin"); //check if url changed
|
84
|
driver.Navigate().GoToUrl(url); //return back on login screen (effectively logout, becouse logout button was too hard to click)
|
85
|
driver.Close();
|
86
|
driver.Quit();
|
87
|
}
|
88
|
[TestMethod]
|
89
|
public void Login_Correct_Annotator_Chrome()
|
90
|
{
|
91
|
var driver = new ChromeDriver();
|
92
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
93
|
Thread.Sleep(3000);
|
94
|
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username
|
95
|
driver.FindElement(passwordField).SendKeys(passwords[0]); //enter password
|
96
|
driver.FindElement(loginButton).Click(); //click on login
|
97
|
Thread.Sleep(3000);
|
98
|
Assert.AreEqual(driver.Url, "http://localhost:3000/documents/annotator"); //check if url changed
|
99
|
driver.Navigate().GoToUrl(url); //return back on login screen (effectively logout, becouse logout button was too hard to click)
|
100
|
driver.Close();
|
101
|
driver.Quit();
|
102
|
}
|
103
|
[TestMethod]
|
104
|
public void Login_Correct_Admin_Chrome()
|
105
|
{
|
106
|
var driver = new ChromeDriver();
|
107
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
108
|
Thread.Sleep(3000);
|
109
|
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username
|
110
|
driver.FindElement(passwordField).SendKeys(passwords[2]); //enter password
|
111
|
driver.FindElement(loginButton).Click(); //click on login
|
112
|
Thread.Sleep(3000);
|
113
|
Assert.AreEqual(driver.Url, "http://localhost:3000/documents/admin"); //check if url changed
|
114
|
driver.Navigate().GoToUrl(url); //return back on login screen (effectively logout, becouse logout button was too hard to click)
|
115
|
driver.Close();
|
116
|
driver.Quit();
|
117
|
}
|
118
|
|
119
|
// methods with incorrect username or password
|
120
|
[TestMethod]
|
121
|
public void Login_Incorrect_Annotator_Firefox()
|
122
|
{
|
123
|
var driver = new FirefoxDriver();
|
124
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
125
|
Thread.Sleep(3000);
|
126
|
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username
|
127
|
driver.FindElement(passwordField).SendKeys("abc"); //enter password
|
128
|
driver.FindElement(loginButton).Click(); //click on login
|
129
|
Thread.Sleep(3000);
|
130
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
131
|
Thread.Sleep(3000);
|
132
|
driver.Close();
|
133
|
driver.Quit();
|
134
|
}
|
135
|
[TestMethod]
|
136
|
public void Login_Incorrect_Admin_Firefox()
|
137
|
{
|
138
|
var driver = new FirefoxDriver();
|
139
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
140
|
Thread.Sleep(3000);
|
141
|
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username
|
142
|
driver.FindElement(passwordField).SendKeys("abc"); //enter password
|
143
|
driver.FindElement(loginButton).Click(); //click on login
|
144
|
Thread.Sleep(3000);
|
145
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
146
|
Thread.Sleep(3000);
|
147
|
driver.Close();
|
148
|
driver.Quit();
|
149
|
}
|
150
|
[TestMethod]
|
151
|
public void Login_Incorrect_Annotator_Chrome()
|
152
|
{
|
153
|
var driver = new ChromeDriver();
|
154
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
155
|
Thread.Sleep(3000);
|
156
|
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username
|
157
|
driver.FindElement(passwordField).SendKeys("abc"); //enter password
|
158
|
driver.FindElement(loginButton).Click(); //click on login
|
159
|
Thread.Sleep(3000);
|
160
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
161
|
Thread.Sleep(3000);
|
162
|
driver.Close();
|
163
|
driver.Quit();
|
164
|
}
|
165
|
[TestMethod]
|
166
|
public void Login_Incorrect_Admin_Chrome()
|
167
|
{
|
168
|
var driver = new ChromeDriver();
|
169
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
170
|
Thread.Sleep(3000);
|
171
|
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username
|
172
|
driver.FindElement(passwordField).SendKeys("abc"); //enter password
|
173
|
driver.FindElement(loginButton).Click(); //click on login
|
174
|
Thread.Sleep(3000);
|
175
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
176
|
Thread.Sleep(3000);
|
177
|
driver.Close();
|
178
|
driver.Quit();
|
179
|
}
|
180
|
[TestMethod]
|
181
|
public void Login_EmptyUsername_Firefox()
|
182
|
{
|
183
|
var driver = new FirefoxDriver();
|
184
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
185
|
Thread.Sleep(3000);
|
186
|
driver.FindElement(usernameField).SendKeys(""); //enter username
|
187
|
driver.FindElement(passwordField).SendKeys("abc"); //enter password
|
188
|
driver.FindElement(loginButton).Click(); //click on login
|
189
|
Thread.Sleep(3000);
|
190
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
191
|
Thread.Sleep(3000);
|
192
|
driver.Close();
|
193
|
driver.Quit();
|
194
|
}
|
195
|
[TestMethod]
|
196
|
public void Login_EmptyUsername_Chrome()
|
197
|
{
|
198
|
var driver = new ChromeDriver();
|
199
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
200
|
Thread.Sleep(3000);
|
201
|
driver.FindElement(usernameField).SendKeys(""); //enter username
|
202
|
driver.FindElement(passwordField).SendKeys("abc"); //enter password
|
203
|
driver.FindElement(loginButton).Click(); //click on login
|
204
|
Thread.Sleep(3000);
|
205
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
206
|
Thread.Sleep(3000);
|
207
|
driver.Close();
|
208
|
driver.Quit();
|
209
|
}
|
210
|
[TestMethod]
|
211
|
public void Login_EmptyPassword_Firefox()
|
212
|
{
|
213
|
var driver = new FirefoxDriver();
|
214
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
215
|
Thread.Sleep(3000);
|
216
|
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username
|
217
|
driver.FindElement(passwordField).SendKeys(""); //enter password
|
218
|
driver.FindElement(loginButton).Click(); //click on login
|
219
|
Thread.Sleep(3000);
|
220
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
221
|
Thread.Sleep(3000);
|
222
|
driver.Close();
|
223
|
driver.Quit();
|
224
|
}
|
225
|
[TestMethod]
|
226
|
public void Login_EmptyPassword_Chrome()
|
227
|
{
|
228
|
var driver = new ChromeDriver();
|
229
|
driver.Navigate().GoToUrl(url); //zakladni stranka
|
230
|
Thread.Sleep(3000);
|
231
|
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username
|
232
|
driver.FindElement(passwordField).SendKeys(""); //enter password
|
233
|
driver.FindElement(loginButton).Click(); //click on login
|
234
|
Thread.Sleep(3000);
|
235
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
236
|
Thread.Sleep(3000);
|
237
|
driver.Close();
|
238
|
driver.Quit();
|
239
|
}
|
240
|
|
241
|
|
242
|
}
|
243
|
}
|