1 |
d65e75d9
|
schenkj
|
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 |
2d8c65b5
|
schenkj
|
[TestClass]
|
17 |
d65e75d9
|
schenkj
|
public class LoginTesting
|
18 |
|
|
{
|
19 |
414636c0
|
schenkj
|
//defining variables needed for testing
|
20 |
2d8c65b5
|
schenkj
|
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 |
d65e75d9
|
schenkj
|
|
29 |
|
|
|
30 |
414636c0
|
schenkj
|
/**
|
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 |
d65e75d9
|
schenkj
|
[TestMethod]
|
38 |
414636c0
|
schenkj
|
//dummy method for constructing tests
|
39 |
2d8c65b5
|
schenkj
|
public void Login_Dummy()
|
40 |
d65e75d9
|
schenkj
|
{
|
41 |
2d8c65b5
|
schenkj
|
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 |
d65e75d9
|
schenkj
|
}
|
55 |
|
|
|
56 |
|
|
|
57 |
2d8c65b5
|
schenkj
|
// methods with correct usernames and passwords
|
58 |
d65e75d9
|
schenkj
|
[TestMethod]
|
59 |
2d8c65b5
|
schenkj
|
public void Login_Correct_Annotator_Firefox()
|
60 |
d65e75d9
|
schenkj
|
{
|
61 |
2d8c65b5
|
schenkj
|
var driver = new FirefoxDriver();
|
62 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
63 |
2d8c65b5
|
schenkj
|
Thread.Sleep(3000);
|
64 |
414636c0
|
schenkj
|
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 |
2d8c65b5
|
schenkj
|
Thread.Sleep(3000);
|
68 |
414636c0
|
schenkj
|
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 |
2d8c65b5
|
schenkj
|
driver.Close();
|
71 |
|
|
driver.Quit();
|
72 |
|
|
}
|
73 |
|
|
[TestMethod]
|
74 |
|
|
public void Login_Correct_Admin_Firefox()
|
75 |
|
|
{
|
76 |
|
|
var driver = new FirefoxDriver();
|
77 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
78 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
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 |
2d8c65b5
|
schenkj
|
driver.Close();
|
86 |
|
|
driver.Quit();
|
87 |
|
|
}
|
88 |
|
|
[TestMethod]
|
89 |
|
|
public void Login_Correct_Annotator_Chrome()
|
90 |
|
|
{
|
91 |
|
|
var driver = new ChromeDriver();
|
92 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
93 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
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 |
2d8c65b5
|
schenkj
|
driver.Close();
|
101 |
|
|
driver.Quit();
|
102 |
|
|
}
|
103 |
|
|
[TestMethod]
|
104 |
|
|
public void Login_Correct_Admin_Chrome()
|
105 |
|
|
{
|
106 |
|
|
var driver = new ChromeDriver();
|
107 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
108 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
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 |
2d8c65b5
|
schenkj
|
driver.Close();
|
116 |
|
|
driver.Quit();
|
117 |
d65e75d9
|
schenkj
|
}
|
118 |
|
|
|
119 |
2d8c65b5
|
schenkj
|
// methods with incorrect username or password
|
120 |
|
|
[TestMethod]
|
121 |
|
|
public void Login_Incorrect_Annotator_Firefox()
|
122 |
|
|
{
|
123 |
|
|
var driver = new FirefoxDriver();
|
124 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
125 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
131 |
2d8c65b5
|
schenkj
|
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 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
140 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
146 |
2d8c65b5
|
schenkj
|
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 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
155 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
161 |
2d8c65b5
|
schenkj
|
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 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
170 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
176 |
2d8c65b5
|
schenkj
|
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 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
185 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
191 |
2d8c65b5
|
schenkj
|
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 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
200 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
206 |
2d8c65b5
|
schenkj
|
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 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
215 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
221 |
2d8c65b5
|
schenkj
|
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 |
53b8629c
|
schenkj
|
driver.Navigate().GoToUrl(url);
|
230 |
2d8c65b5
|
schenkj
|
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 |
414636c0
|
schenkj
|
Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
|
236 |
2d8c65b5
|
schenkj
|
Thread.Sleep(3000);
|
237 |
|
|
driver.Close();
|
238 |
|
|
driver.Quit();
|
239 |
|
|
}
|
240 |
d65e75d9
|
schenkj
|
|
241 |
|
|
|
242 |
|
|
}
|
243 |
|
|
}
|