Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b11af9b1

Přidáno uživatelem Jakub Schenk před asi 2 roky(ů)

Testing cleanup + readme

cleaning testing, adding new comments to user creation frontend, adding readme

Zobrazit rozdíly:

Backend/BackendTesting/AnotationTesting.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace BackendTesting
8
{
9
    public class AnotationTesting
10
    {
11
    }
12
}
Backend/BackendTesting/README.md
1
# Anotace pro analýzu smluvních podmínek a skrytých reklam - Testování
2
### Backend testování
3
Při testování backendu je potřeba převážně testovat Core/Services. Z této oblasti bylo nejprve testováno to, co bylo kritické a zároveň ve stavu, ve kterém to bylo možné testovat.
4
Pro testování backendu je potřeba prázdná databáze inicializovaná tak jak je v readme projektu, které se nachází v dev větvi.
5
Testování probíhalo jako blackbox testing, není tedy obtížné přidat další podobné testy. Dosavadní testy jsou komentované a nejsou obtížné na pochopení.
6
##### Testování dokumentů
7
Testování dokumentů probíhá tak, že je nad prázdnou databází vytvořena množina dokumentů a admin, který je má přiřazené. Tyto dokumenty jsou nahrávány a získávány z databáze s cílem určit, zda jsou do databáze správně uloženy a zpětně navráceny.
8
Toto testování bohužel neodhalí, pokud je dokument poškozen při přenosu. To je zapříčiněno sanitizací a úpravou daného dokumentu při nahrání do databáze.
9
##### Testování uživatelů
10
Testování uživatelů testuje všechny metody, které UserService systému poskytuje. Sem je zahrnuto vytváření, mazání, změna, změna hesla, přihlášení a získávání uživatelského účtu z databáze různými způsoby.
11
Přihlášení je testováno jak na validní, tak nevalidní data, stejně tak vytváření a změna uživatele.
12
##### Další možné testování
13
Testování na které nevyšel čas, nebo nebylo dost dobře možné testovat dostatečně brzo.
14
Jedná se o testování značek a anotace. Obě tyto třídy procházely změnami a bylo obtížné a časově neefektivní jim věnovat pozornost, kterou by si zasloužily.
15

  
16
### Frontend testování
17
Frontend testování probíhá na inicializované databázi. Automatické frontend testování probíhalo na stejném stroji, na kterém běžel server. 
18
Část kódu v C# byla spouštěna klasickým způsobem. Frondend byl spouštěn příkazy
19
```sh
20
yarn
21
yarn dev
22
```
23
Po spuštění obou částí bylo možné aplikaci automaticky testovat.
24
Automatické testy probíhají pomocí nástroje Selenium. To simuluje uživatelské akce.
25
Selenium použité na tyto testy využívalo prohlížeče Google Chrome a Mozilla Firefox.
26
Opět, z časových důvodů nebylo možné automaticky otestovat vše, co by automaticky testováno být mělo.
27

  
28
#### Testování přihlášení
29
Testování automatického přihlášení probíhá stejným stylem, jako na backend. Jedná se o sérii testů, které mají ověřit, zda se může přihlásit uživatel se správnými uživatelskými údaji, a zároveň nemůže uživatel s těmi špatnými, případně jestli se přihlášený uživatel dostal na stránku, na kterou měl.
30
Tyto testy naneštěstí jako jediné z této oblasti pracují s databází vytvořenou testama na backendu. Jedná se o defekt z vývoje aplikace, na který se zapomnělo a bylo by náročné jej nyní měnit z pohledu finalizace.
31

  
32
#### Testování přesměrování
33
Toto testování slouží k zajištění, aby anotátor neviděl administrátorské prostřední, ani tak že by se dokázal přesměrovat na stránky administrátora. Jelikož uživatele nepřesměrováváme, test kontroluje, zda element s obsahem stránky má nulové rozměry.
34
Test by mohl být postavený rozumněji, ale svoji funkci ve stávající implementaci plní.
35

  
36
#### Testování vytváření uživatele
37
Protože v nástroji spousta elementů, které nejsou nahrané v DOM ve chvíli načtení stránky, selenium může mít problémy s jejich získáváním. Tento test funguje asi hlavně jako inspirace pro vytváření dalších testů, na které v projektu nevyzbyl čas.
38
Test probíhá přihlášením administrátora, změnou stránku na seznam uživatelů a vytvořením uživatele ve vyskakujícím okně. Poslední krok je aktualizace stránky, získání všech uživatelů v tabulce uživatelů a zjištění, zda se uživatel úspěšně vytvořil.
39
Tato testovací sada je rozšiřitelná na editaci a mazání úživatele.
40

  
41
### Manuální testování
42
Manuální testování je velkou součástí testování tohoto nástroje. Jedná se o testování, které bylo převážně aplikováno během dokončování projektu a jeho finalizace.
43
Jednoduchý scénář pro takové testování se zaměřením na uživatele by mohl vypadat následovně:
44
```sh
45
Přihlásit se jako administrátor
46
Vytvořit uživatele anotátora
47
Odhlásit se
48
Přihlásit se jako nový anotátor
49
Odhlásit se
50
Přihlásit se jako administrátor
51
Změnit nového anotátora - jméno
52
Změnit nového anotátora - příjmení
53
Změnit nového anotátora - uživatelské jméno
54
Změnit nového anotátora - jméno, příjmení i uživatelské jméno
55
Změnit nového anotátora - heslo
56
Odhlásit se
57
Přihlásit se jako změněný anotátor
58
Odhlásit se
59
Přihlásit se jako administrátor
60
Změnit měněného anotátora na administrátora
61
Odhlásit se
62
Přihlásit se jako nový administrátor (změněný anotátor)
63
Zkusit vytvořit a editovat uživatele
64
Smazat nového uživatele
65
Odhlásit se
66
Přihlásit se jako původní administrátor
67
Změnit nového administrátora - jméno
68
Změnit nového administrátora - příjmení
69
Změnit nového administrátora - uživatelské jméno
70
Změnit nového administrátora - jméno, příjmení i uživatelské jméno
71
Změnit nového administrátora - heslo
72
Odhlásit se
73
Přihlásit se jako změněný administrátor
74
Odhlásit se
75
Přihlásit se jako původní administrátor
76
Smazat nového administrátora
77
Odhlásit se
78
```
79
Podobné scénáře lze napsat pro testování značek, dokumentů a anotace.
80
Důležité při manuálním testování ale je dávat si pozor na detaily, které jsou strojově těžko odhalitelné, jako například velikost tlačítek, nebo intuitivnost a celková použitelnost aplikace.
Backend/BackendTesting/TagsManagementTesting.cs
1
using Microsoft.VisualStudio.TestTools.UnitTesting;
2
using Models.Enums;
3
using Core.Entities;
4
using Serilog;
5

  
6
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9
using System.Text;
10
using System.Threading.Tasks;
11
using Microsoft.EntityFrameworkCore;
12
using AutoMapper;
13
using Core.MapperProfiles;
14
using Core.Contexts;
15
using Microsoft.Extensions.Configuration;
16
using Models.Documents;
17
using Core.Services;
18

  
19
namespace BackendTesting
20
{
21
    [TestClass]
22
    public class TagsManagementTesting
23
    {
24
        private static readonly IConfiguration configuration = new ConfigurationBuilder().Build();
25
        public DatabaseContext ctx;
26
        //public Core.Services.DocumentService.IDocumentService DS;
27
        //public Core.Services.IUserService US;
28
        public Core.Services.TagService.ITagService TS;
29
        //public DocumentAddRequest docList;
30
        public User user;
31

  
32
        //constructor for testing tags and anotations
33
        public TagsManagementTesting()
34
        {
35
            //creating new database
36
            this.ctx = new DatabaseContext(configuration);
37
            //this.DS = new Core.Services.DocumentService.DocumentServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
38
            //this.US = new UserServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
39
            this.TS = new Core.Services.TagService.TagServiceEF(ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
40

  
41
            AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
42

  
43
            //ensure the database is fresh without unwanted users from previous testings
44
            ctx.Database.EnsureDeleted();
45
            ctx.Database.EnsureCreated();
46

  
47
            //user = new() { Id = Guid.NewGuid(), Name = "aa", Surname = "aa", Password = "aa", Role = ERole.ADMINISTRATOR, Username = "aa" };
48
            //ctx.Users.Add(user);
49
            //ctx.SaveChanges();
50

  
51
            //docList = MakeRequest();
52
            //FillUsers();
53
            //ctx.SaveChanges();
54
        }
55

  
56
        [TestMethod]
57
        public void GetTagTree_Testing()
58
        {
59
            try
60
            {
61
                //var tagTree = TS.GetTagTree();
62
                
63
                //TODO - pridavat kategorie, tagy a podtagy
64
                //kontrolovat zda jsou tam vsechny a spravne
65
                //pripadne je zkusit odebirat (az budou na backendu doresene)
66

  
67

  
68

  
69
            }
70
            catch(Exception ex)
71
            {
72
                Assert.Fail("GetTagTree() failed on exception: " + ex);
73
            }
74
            
75

  
76

  
77
        }
78

  
79

  
80

  
81

  
82

  
83

  
84

  
85

  
86
        /*
87
        private void FillUsers()
88
        {
89
            var userList = new List<User>();
90
            userList.Add(new User() { Username = "aaa", Name = "aaa", Surname = "aaa", Password = "aaa", Role = Models.Enums.ERole.ANNOTATOR });
91
            userList.Add(new User() { Username = "bbb", Name = "bbb", Surname = "bbb", Password = "bbb", Role = Models.Enums.ERole.ANNOTATOR });
92
            userList.Add(new User() { Username = "ccc", Name = "ccc", Surname = "ccc", Password = "ccc", Role = Models.Enums.ERole.ADMINISTRATOR });
93
            userList.Add(new User() { Username = "ddd", Name = "ddd", Surname = "ddd", Password = "ddd", Role = Models.Enums.ERole.ANNOTATOR });
94
            userList.Add(new User() { Username = "eee", Name = "eee", Surname = "eee", Password = "eee", Role = Models.Enums.ERole.ANNOTATOR });
95
            userList.Add(new User() { Username = "fff", Name = "fff", Surname = "fff", Password = "fff", Role = Models.Enums.ERole.ANNOTATOR });
96
            userList.Add(new User() { Username = "ggg", Name = "ggg", Surname = "ggg", Password = "ggg", Role = Models.Enums.ERole.ANNOTATOR });
97
            userList.Add(new User() { Username = "hhh", Name = "hhh", Surname = "hhh", Password = "hhh", Role = Models.Enums.ERole.ADMINISTRATOR });
98
            userList.Add(new User() { Username = "iii", Name = "iii", Surname = "iii", Password = "iii", Role = Models.Enums.ERole.ADMINISTRATOR });
99
            userList.Add(new User() { Username = "jjj", Name = "jjj", Surname = "jjj", Password = "jjj", Role = Models.Enums.ERole.ADMINISTRATOR });
100

  
101
            //filling up the database
102
            foreach (var user in userList)
103
            {
104
                US.CreateUser(user.Username, user.Name, user.Surname, user.Password, user.Role);
105
            }
106
            ctx.SaveChanges();
107
        }
108

  
109
        private DocumentAddRequest MakeRequest()
110
        {
111
            docList = new DocumentAddRequest() { Documents = new() };
112
            var dc = new DocumentContent();
113
            string content = "aaa <html> bbb";
114
            content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content));
115
            dc.Content = content;
116
            var dt = new DateTime(2022, 4, 11);
117
            DocumentAddInfo info = new DocumentAddInfo();
118
            info.Name = "a";
119
            info.Content = content;
120
            info.Format = EAddDocumentFormat.TEXTFILE;
121
            docList.Documents.Add(info);
122

  
123
            content = "aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb";
124
            dc.Content = content;
125
            dt = new DateTime(2022, 4, 12);
126
            docList.Documents.Add(new DocumentAddInfo() { Name = "b", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
127

  
128
            content = "aaa <html> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?>" +
129
                " bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc>" +
130
                " nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html>" +
131
                " <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?>" +
132
                " bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb ";
133
            dc.Content = content;
134
            dt = new DateTime(2022, 4, 13);
135
            docList.Documents.Add(new DocumentAddInfo() { Name = "c", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
136

  
137
            content = "aaa";
138
            dc.Content = content;
139
            dt = new DateTime(2022, 4, 14);
140
            docList.Documents.Add(new DocumentAddInfo() { Name = "d", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
141

  
142
            content = "aaa <html> edfgckvhbjno§mpoizuzcjtjczkutvlzibůuoni§piuoůbzivlutkczjxzcktuvlziůuoi§ouůizvlutckzxjzckguvl h.gjcutfgýíáéphuoůizltukridýžáflizv bbb";
143
            dc.Content = content;
144
            dt = new DateTime(2022, 4, 15);
145
            docList.Documents.Add(new DocumentAddInfo() { Name = "e", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
146

  
147
            return docList;
148
        }
149
        */
150
    }
151
}
Backend/BackendTesting/UserManagementTesting.cs
27 27
        private static readonly IConfiguration configuration = new ConfigurationBuilder().Build();
28 28
        public DatabaseContext ctx;
29 29
        public Core.Services.IUserService US;
30
        
30

  
31 31
        //constructor for creating database and filling it with dummy data
32 32
        public UserManagementTesting()
33 33
        {
......
87 87
            }
88 88

  
89 89
            //check for empty atributes
90
            if((username == null || username == "")&& output!=null)
90
            if ((username == null || username == "") && output != null)
91 91
            {
92 92
                Assert.Fail("user with no username created");
93 93
                return;
......
184 184
        {
185 185
            //new user creation
186 186
            User? newUser = US.CreateUser(oldUsername, oldName, oldSurname, password, oldRole);
187
            if(newUser == null)
187
            if (newUser == null)
188 188
            {
189 189
                Assert.Fail("user not created (maybe already user username?)");
190 190
            }
......
204 204
        [DataRow("bbb", "")]//set to none password
205 205
        [DataRow("eee", "eee")]//keep old password
206 206
        //test of changing password
207
        public void ChangePassword_Test(string username, string newPassword) 
207
        public void ChangePassword_Test(string username, string newPassword)
208 208
        {
209 209
            //get user using GetUserByUsername
210 210
            User? changingUser = US.GetUserByUsername(username);
211
            if(changingUser == null)
211
            if (changingUser == null)
212 212
            {
213 213
                Assert.Fail("user not found");
214 214
                return;
......
244 244

  
245 245
                Assert.AreNotEqual(oldPassword, renewedPassword, "password was not changed or it was changed on same value");
246 246
            }
247
            catch(Exception ex)
247
            catch (Exception ex)
248 248
            {
249
                if (newPassword == null || newPassword == "") Assert.IsTrue(true,"Try to change password on empty resulted in exception - expected and wanted outcome");
249
                if (newPassword == null || newPassword == "") Assert.IsTrue(true, "Try to change password on empty resulted in exception - expected and wanted outcome");
250 250
            }
251
            
251

  
252 252

  
253 253
        }
254 254
        [TestMethod]
......
259 259
        public void CheckUsernamePassword_Correct(string username, string password)
260 260
        {
261 261
            User? checkedUser = US.CheckUsernamePassword(username, password);
262
            if(checkedUser == null)
262
            if (checkedUser == null)
263 263
            {
264 264
                //there are just correct users - this should have returned user
265 265
                Assert.Fail("there are just correct users - this should have returned user");
266 266
                return;
267 267
            }
268 268
            User? expected = US.GetUserByUsername(username);
269
            if(expected == null)
269
            if (expected == null)
270 270
            {
271 271
                Assert.Fail("There is mistake in tested data");
272 272
                return;
......
299 299
        {
300 300
            //get user from database
301 301
            User? oldUser = US.CheckUsernamePassword(username, oldPassword);
302
            if (oldUser == null) 
302
            if (oldUser == null)
303 303
            {
304 304
                Assert.Fail("This should have returned user - there are wrong input data or CheckUsernamePassword isnt working properly");
305 305
                return;
......
314 314
            }
315 315
            //check if new password is in place
316 316
            User? newUser = US.CheckUsernamePassword(username, newPassword);
317
            if(newUser == null)
317
            if (newUser == null)
318 318
            {
319 319
                Assert.Fail("No user was returned - password probably wasnt changed");
320 320
            }
......
325 325

  
326 326
            //check if there is no way to login with old password
327 327
            User? oldPasswordTester = US.CheckUsernamePassword(username, oldPassword);
328
            if(oldPasswordTester != null)
328
            if (oldPasswordTester != null)
329 329
            {
330 330
                Assert.Fail("old password is still viable after password change");
331 331
            }
Backend/FrontendTesting/LinksTesting.cs
21 21
        public By usernameField = By.Id("login_username");
22 22
        public By passwordField = By.Id("login_password");
23 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"};
24
        public string[] usernames = { "admin", "annotator1" };
25
        public string[] passwords = { "admin", "password" };
26 26
        public By shouldBeEmpty = By.Id("__next");
27 27
        //urls 0-4 are for admin only, url 5 is for annotator only
28 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" };
......
39 39
        public void Login_User(string username, string password, bool driverChrome)
40 40
        {
41 41
            IWebDriver driver;
42
            if(driverChrome) driver= Drivers.cDriver;
42
            if (driverChrome) driver = Drivers.cDriver;
43 43
            else driver = Drivers.fDriver;
44 44
            driver.Navigate().GoToUrl(url);
45 45
            Thread.Sleep(1000);
Backend/FrontendTesting/LoginTesting.cs
23 23
        public By loginButton = By.XPath("/html/body/div[1]/div/div/div[2]/main/form/div[3]/div/div/div/button");
24 24
        public By userButton = By.XPath("/html/body/div[1]/div/div[1]/ul/li[2]/div/span");
25 25
        public By logoutButton = By.XPath("/html/body/div[3]/div/div/ul/li/span");
26
        public string[] usernames = { "aaa", "bbb", "ccc"};
26
        public string[] usernames = { "aaa", "bbb", "ccc" };
27 27
        public string[] passwords = { "aaa", "bbb", "ccc" };
28 28

  
29 29

  
......
59 59
        public void Login_Correct_Annotator_Firefox()
60 60
        {
61 61
            var driver = new FirefoxDriver();
62
            driver.Navigate().GoToUrl(url);                                      
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);                              
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);                              
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);                              
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);                             
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);                              
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);                              
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
......
165 165
        [TestMethod]
166 166
        public void Login_Incorrect_Admin_Chrome()
167 167
        {
168
            var driver = new ChromeDriver(); 
169
            driver.Navigate().GoToUrl(url);                              
168
            var driver = new ChromeDriver();
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);                              
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);                              
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);                              
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);                              
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/UserManagementTesting.cs
49 49
        [DataRow(true, "ggg", "ggg", "", "ggg")]
50 50
        [DataRow(false, "hhh", "hhh", "", "hhh")]
51 51
        [DataRow(true, "iii", "iii", "iii", "")]
52
        [DataRow(false, "jjj", "jjj", "jjj", "")]*/
52
        [DataRow(false, "jjj", "jjj", "jjj", "")]
53
        there were some problems with multiple tests runs*/
53 54
        [TestMethod]
54 55
        [DataRow(false, "aaa", "aaa", "aaa", "aaa")]
55 56
        public void CreateUser(bool isAdmin, string Username, string Name, string Surname, string Password)
56 57
        {
57 58
            var driver = new ChromeDriver();
58 59
            WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
59
            
60

  
60 61
            if (!Login(driver)) Assert.Fail("Login failed");
61 62
            driver.Manage().Window.Maximize();
62 63
            //Thread.Sleep(1000);
......
66 67
            //popup handling
67 68
            string currentHandle = driver.CurrentWindowHandle;
68 69
            ReadOnlyCollection<string> originalHandles = driver.WindowHandles;
69
            
70

  
70 71
            //popup window actions
71 72
            if (isAdmin)
72 73
            {
......
83 84

  
84 85
            driver.Navigate().Refresh();
85 86

  
86
            
87

  
87 88
            //Here should be new user in database if creditals were valid
88 89
            var table = getTable(driver);
89 90
            bool found = false;
90 91
            string nm, srnm, usrnm, rl, dcks;
91
            for(int i = 0; i < table.Count-5; i+=6)
92
            for (int i = 0; i < table.Count - 5; i += 6)
92 93
            {
93
                nm= table[i];
94
                srnm= table[i+1];
95
                usrnm= table[i+2];
94
                nm = table[i];
95
                srnm = table[i + 1];
96
                usrnm = table[i + 2];
96 97
                //rl= table[i+3];
97 98
                //dcks= table[i+4];
98 99
                if (nm == Name && srnm == Surname && usrnm == Username) found = true;
99 100
            }
100
            if(Username!="" || Password != "" || Name!="" || Surname!="")
101
            if (Username != "" || Password != "" || Name != "" || Surname != "")
101 102
            {
102 103
                //valid creditals - user should be in db
103 104
                Assert.IsTrue(found, "There should be new user but he was not found.");
......
108 109
                //invalids creditals - user shouldnt be in db
109 110
                Assert.IsFalse(found, "There should NOT be new user but he was found in the table. ");
110 111
            }
111
            driver.Navigate().GoToUrl(url);            
112
            driver.Navigate().GoToUrl(url);
112 113
            driver.Close();
113 114
            driver.Quit();
114 115
        }
115 116

  
116 117

  
117 118

  
118

  
119
        //getting table of users from page for comparison if there is/is not user there should/should not be
119 120
        private List<string> getTable(IWebDriver driver)
120 121
        {
121 122
            List<string> cont = new List<string>();
......
128 129
            return cont;
129 130
        }
130 131

  
132
        //easy login to run on start of the test
131 133
        private bool Login(IWebDriver driver)
132 134
        {
133 135
            driver.Navigate().GoToUrl(url);
Backend/FrontendTesting/Utils.cs
14 14
{
15 15
    public class Utils
16 16
    {
17
        
17

  
18 18
    }
19 19

  
20 20
    public static class Drivers
21 21
    {
22
        
22

  
23 23
        public static IWebDriver fDriver = new FirefoxDriver();
24 24
        public static IWebDriver cDriver = new ChromeDriver();
25 25
        public static IWebDriver[] drivers = { fDriver, cDriver };

Také k dispozici: Unified diff