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 LinksTesting
|
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 string[] usernames = { "admin", "annotator1" };
|
25
|
public string[] passwords = { "admin", "password" };
|
26
|
public By shouldBeEmpty = By.Id("__next");
|
27
|
//urls 0-4 are for admin only, url 5 is for annotator only
|
28
|
public string[] urls = { "http://localhost:3000/documents/admin", "http://localhost:3000/users", "http://localhost:3000/tags", "http://localhost:3000/classes", "http://localhost:3000/export", "http://localhost:3000/documents/annotator" };
|
29
|
|
30
|
|
31
|
/**
|
32
|
Names of tests should be self-explanatory
|
33
|
tests are separated, becouse there were problems with multiple tests runs in one method
|
34
|
tests contain thread.sleep becouse of waiting on components to load (if I find better and reasonable solution, I will change it)
|
35
|
*/
|
36
|
|
37
|
|
38
|
//dummy method for constructing tests
|
39
|
public void Login_User(string username, string password, bool driverChrome)
|
40
|
{
|
41
|
IWebDriver driver;
|
42
|
if (driverChrome) driver = Drivers.cDriver;
|
43
|
else driver = Drivers.fDriver;
|
44
|
driver.Navigate().GoToUrl(url);
|
45
|
Thread.Sleep(1000);
|
46
|
driver.FindElement(usernameField).SendKeys(username); //enter username
|
47
|
Thread.Sleep(500);
|
48
|
driver.FindElement(passwordField).SendKeys(password); //enter password
|
49
|
Thread.Sleep(500);
|
50
|
driver.FindElement(loginButton).Click(); //click on login
|
51
|
Thread.Sleep(1000);
|
52
|
return;
|
53
|
}
|
54
|
|
55
|
|
56
|
// methods for annotator trying to get on admin pages
|
57
|
[TestMethod]
|
58
|
public void Annotator_AdminDocuments_Firefox()
|
59
|
{
|
60
|
var driver = new FirefoxDriver();
|
61
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
62
|
driver.Navigate().GoToUrl(urls[0]); //try to go on /documents/admin
|
63
|
Thread.Sleep(2000);
|
64
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
65
|
Thread.Sleep(3000);
|
66
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
67
|
driver.Close();
|
68
|
driver.Quit();
|
69
|
}
|
70
|
[TestMethod]
|
71
|
public void Annotator_AdminDocuments_Chrome()
|
72
|
{
|
73
|
var driver = new ChromeDriver();
|
74
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
75
|
driver.Navigate().GoToUrl(urls[0]); //try to go on /documents/admin
|
76
|
Thread.Sleep(2000);
|
77
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
78
|
Thread.Sleep(3000);
|
79
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
80
|
driver.Close();
|
81
|
driver.Quit();
|
82
|
}
|
83
|
|
84
|
[TestMethod]
|
85
|
public void Annotator_Users_Firefox()
|
86
|
{
|
87
|
var driver = new FirefoxDriver();
|
88
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
89
|
driver.Navigate().GoToUrl(urls[1]); //try to go on /documents/admin
|
90
|
Thread.Sleep(2000);
|
91
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
92
|
Thread.Sleep(3000);
|
93
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
94
|
driver.Close();
|
95
|
driver.Quit();
|
96
|
}
|
97
|
[TestMethod]
|
98
|
public void Annotator_Users_Chrome()
|
99
|
{
|
100
|
var driver = new ChromeDriver();
|
101
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
102
|
driver.Navigate().GoToUrl(urls[1]); //try to go on /documents/admin
|
103
|
Thread.Sleep(2000);
|
104
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
105
|
Thread.Sleep(3000);
|
106
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
107
|
driver.Close();
|
108
|
driver.Quit();
|
109
|
}
|
110
|
|
111
|
[TestMethod]
|
112
|
public void Annotator_Tags_Firefox()
|
113
|
{
|
114
|
var driver = new FirefoxDriver();
|
115
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
116
|
driver.Navigate().GoToUrl(urls[2]); //try to go on /documents/admin
|
117
|
Thread.Sleep(2000);
|
118
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
119
|
Thread.Sleep(3000);
|
120
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
121
|
driver.Close();
|
122
|
driver.Quit();
|
123
|
}
|
124
|
[TestMethod]
|
125
|
public void Annotator_Tags_Chrome()
|
126
|
{
|
127
|
var driver = new ChromeDriver();
|
128
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
129
|
driver.Navigate().GoToUrl(urls[2]); //try to go on /documents/admin
|
130
|
Thread.Sleep(2000);
|
131
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
132
|
Thread.Sleep(3000);
|
133
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
134
|
driver.Close();
|
135
|
driver.Quit();
|
136
|
}
|
137
|
|
138
|
[TestMethod]
|
139
|
public void Annotator_Classes_Firefox()
|
140
|
{
|
141
|
var driver = new FirefoxDriver();
|
142
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
143
|
driver.Navigate().GoToUrl(urls[3]); //try to go on /documents/admin
|
144
|
Thread.Sleep(2000);
|
145
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
146
|
Thread.Sleep(3000);
|
147
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
148
|
driver.Close();
|
149
|
driver.Quit();
|
150
|
}
|
151
|
[TestMethod]
|
152
|
public void Annotator_Classes_Chrome()
|
153
|
{
|
154
|
var driver = new ChromeDriver();
|
155
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
156
|
driver.Navigate().GoToUrl(urls[3]); //try to go on /documents/admin
|
157
|
Thread.Sleep(2000);
|
158
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
159
|
Thread.Sleep(3000);
|
160
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
161
|
driver.Close();
|
162
|
driver.Quit();
|
163
|
}
|
164
|
|
165
|
[TestMethod]
|
166
|
public void Annotator_Export_Firefox()
|
167
|
{
|
168
|
var driver = new FirefoxDriver();
|
169
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
170
|
driver.Navigate().GoToUrl(urls[4]); //try to go on /documents/admin
|
171
|
Thread.Sleep(2000);
|
172
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
173
|
Thread.Sleep(3000);
|
174
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
175
|
driver.Close();
|
176
|
driver.Quit();
|
177
|
}
|
178
|
[TestMethod]
|
179
|
public void Annotator_Export_Chrome()
|
180
|
{
|
181
|
var driver = new ChromeDriver();
|
182
|
Login_User(usernames[1], passwords[1], false); //should be on /documents/annotator
|
183
|
driver.Navigate().GoToUrl(urls[4]); //try to go on /documents/admin
|
184
|
Thread.Sleep(2000);
|
185
|
var div = driver.FindElement(shouldBeEmpty); //get element expected to be empty
|
186
|
Thread.Sleep(3000);
|
187
|
Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
|
188
|
driver.Close();
|
189
|
driver.Quit();
|
190
|
}
|
191
|
|
192
|
}
|
193
|
}
|