Revize 53b8629c
Přidáno uživatelem Jakub Schenk před téměř 3 roky(ů)
Backend/FrontendTesting/LinksTesting.cs | ||
---|---|---|
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 |
} |
Backend/FrontendTesting/LoginTesting.cs | ||
---|---|---|
59 | 59 |
public void Login_Correct_Annotator_Firefox() |
60 | 60 |
{ |
61 | 61 |
var driver = new FirefoxDriver(); |
62 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
62 |
driver.Navigate().GoToUrl(url);
|
|
63 | 63 |
Thread.Sleep(3000); |
64 | 64 |
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username |
65 | 65 |
driver.FindElement(passwordField).SendKeys(passwords[0]); //enter password |
... | ... | |
74 | 74 |
public void Login_Correct_Admin_Firefox() |
75 | 75 |
{ |
76 | 76 |
var driver = new FirefoxDriver(); |
77 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
77 |
driver.Navigate().GoToUrl(url);
|
|
78 | 78 |
Thread.Sleep(3000); |
79 | 79 |
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username |
80 | 80 |
driver.FindElement(passwordField).SendKeys(passwords[2]); //enter password |
... | ... | |
89 | 89 |
public void Login_Correct_Annotator_Chrome() |
90 | 90 |
{ |
91 | 91 |
var driver = new ChromeDriver(); |
92 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
92 |
driver.Navigate().GoToUrl(url);
|
|
93 | 93 |
Thread.Sleep(3000); |
94 | 94 |
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username |
95 | 95 |
driver.FindElement(passwordField).SendKeys(passwords[0]); //enter password |
... | ... | |
104 | 104 |
public void Login_Correct_Admin_Chrome() |
105 | 105 |
{ |
106 | 106 |
var driver = new ChromeDriver(); |
107 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
107 |
driver.Navigate().GoToUrl(url);
|
|
108 | 108 |
Thread.Sleep(3000); |
109 | 109 |
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username |
110 | 110 |
driver.FindElement(passwordField).SendKeys(passwords[2]); //enter password |
... | ... | |
121 | 121 |
public void Login_Incorrect_Annotator_Firefox() |
122 | 122 |
{ |
123 | 123 |
var driver = new FirefoxDriver(); |
124 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
124 |
driver.Navigate().GoToUrl(url); |
|
125 | 125 |
Thread.Sleep(3000); |
126 | 126 |
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username |
127 | 127 |
driver.FindElement(passwordField).SendKeys("abc"); //enter password |
... | ... | |
136 | 136 |
public void Login_Incorrect_Admin_Firefox() |
137 | 137 |
{ |
138 | 138 |
var driver = new FirefoxDriver(); |
139 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
139 |
driver.Navigate().GoToUrl(url);
|
|
140 | 140 |
Thread.Sleep(3000); |
141 | 141 |
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username |
142 | 142 |
driver.FindElement(passwordField).SendKeys("abc"); //enter password |
... | ... | |
151 | 151 |
public void Login_Incorrect_Annotator_Chrome() |
152 | 152 |
{ |
153 | 153 |
var driver = new ChromeDriver(); |
154 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
154 |
driver.Navigate().GoToUrl(url);
|
|
155 | 155 |
Thread.Sleep(3000); |
156 | 156 |
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username |
157 | 157 |
driver.FindElement(passwordField).SendKeys("abc"); //enter password |
... | ... | |
166 | 166 |
public void Login_Incorrect_Admin_Chrome() |
167 | 167 |
{ |
168 | 168 |
var driver = new ChromeDriver(); |
169 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
169 |
driver.Navigate().GoToUrl(url);
|
|
170 | 170 |
Thread.Sleep(3000); |
171 | 171 |
driver.FindElement(usernameField).SendKeys(usernames[2]); //enter username |
172 | 172 |
driver.FindElement(passwordField).SendKeys("abc"); //enter password |
... | ... | |
181 | 181 |
public void Login_EmptyUsername_Firefox() |
182 | 182 |
{ |
183 | 183 |
var driver = new FirefoxDriver(); |
184 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
184 |
driver.Navigate().GoToUrl(url);
|
|
185 | 185 |
Thread.Sleep(3000); |
186 | 186 |
driver.FindElement(usernameField).SendKeys(""); //enter username |
187 | 187 |
driver.FindElement(passwordField).SendKeys("abc"); //enter password |
... | ... | |
196 | 196 |
public void Login_EmptyUsername_Chrome() |
197 | 197 |
{ |
198 | 198 |
var driver = new ChromeDriver(); |
199 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
199 |
driver.Navigate().GoToUrl(url);
|
|
200 | 200 |
Thread.Sleep(3000); |
201 | 201 |
driver.FindElement(usernameField).SendKeys(""); //enter username |
202 | 202 |
driver.FindElement(passwordField).SendKeys("abc"); //enter password |
... | ... | |
211 | 211 |
public void Login_EmptyPassword_Firefox() |
212 | 212 |
{ |
213 | 213 |
var driver = new FirefoxDriver(); |
214 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
214 |
driver.Navigate().GoToUrl(url);
|
|
215 | 215 |
Thread.Sleep(3000); |
216 | 216 |
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username |
217 | 217 |
driver.FindElement(passwordField).SendKeys(""); //enter password |
... | ... | |
226 | 226 |
public void Login_EmptyPassword_Chrome() |
227 | 227 |
{ |
228 | 228 |
var driver = new ChromeDriver(); |
229 |
driver.Navigate().GoToUrl(url); //zakladni stranka
|
|
229 |
driver.Navigate().GoToUrl(url);
|
|
230 | 230 |
Thread.Sleep(3000); |
231 | 231 |
driver.FindElement(usernameField).SendKeys(usernames[0]); //enter username |
232 | 232 |
driver.FindElement(passwordField).SendKeys(""); //enter password |
Backend/FrontendTesting/MainTestingClass.cs | ||
---|---|---|
1 |
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|
2 |
|
|
3 |
namespace FrontendTesting |
|
4 |
{ |
|
5 |
[TestClass] |
|
6 |
public class MainTestingClass |
|
7 |
{ |
|
8 |
[TestMethod] |
|
9 |
public void RunAll() |
|
10 |
{ |
|
11 |
|
|
12 |
} |
|
13 |
} |
|
14 |
} |
Také k dispozici: Unified diff
Annotator redirecting
testing if annotator doesnt see page content if tried to get on url they shouldnt