Skip to content

Commit 0b17858

Browse files
committed
add UI tests for operators checking
1 parent 300f426 commit 0b17858

2 files changed

Lines changed: 246 additions & 8 deletions

File tree

tests/2023-mbt-04-14/Cucumber/src/test/java/hellocucumber/StepDefinitions.java

Lines changed: 225 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package hellocucumber;
22

33
import io.cucumber.java.en.*;
4-
import io.cucumber.java.AfterAll;
54
import io.cucumber.java.BeforeAll;
65
import org.junit.jupiter.api.AfterEach;
76
import org.junit.jupiter.api.BeforeEach;
87
import org.openqa.selenium.*;
98
import org.openqa.selenium.chrome.ChromeDriver;
109
import org.openqa.selenium.support.ui.ExpectedConditions;
11-
import org.openqa.selenium.support.ui.Select;
1210
import org.openqa.selenium.support.ui.WebDriverWait;
1311

12+
import java.io.Console;
1413
import java.io.File;
1514
import java.io.FileInputStream;
16-
import java.io.FileWriter;
17-
import java.io.IOException;
1815
import java.time.Duration;
1916
import java.util.List;
2017
import java.util.Properties;
@@ -45,9 +42,19 @@ public class StepDefinitions {
4542
private final String Add_Participant_Save_Button= "//*[@id=\"participant-modal\"]/div/div/button[2]";
4643
// remove participant
4744
private final String Remove_Participant_Button = "//*[@id=\"remove-participant-btn\"]";
45+
//navigate to operators
46+
private final String Remove_Operator_Button = "//*[@id=\"remove-operator-btn\"]";
47+
private final String operators_Button = "//*[@id=\"operators-btn\"]";
48+
//add operator
49+
private final String add_Operator = "//*[@id=\"add-operator-btn\"]";
50+
private final String add_Operator_Username_Textbox = "//*[@id=\"username\"]";
51+
private final String add_Operator_Password_Textbox = "//*[@id=\"password\"]";
52+
private final String add_Operator_Save_Button = "//*[@id=\"save-operator-btn\"]";
4853

4954
private final String username = "admin";
5055
private final String password = "pass";
56+
private final String main_Menu_URL = "https://ims-project.cs.bgu.ac.il/main_menu";
57+
private final String disconnect_Button = "//*[@id=\"disconnect-btn\"]";
5158

5259
private String URL;
5360

@@ -101,12 +108,13 @@ public void afterEach() throws InterruptedException {
101108

102109
// -----------------------------------------------------------------------------------------
103110
// -----------------------------------------------------------------------------------------
104-
// First scenario: Manager adds new participant
111+
// First scenario: Admin adds new participant.
105112
// -----------------------------------------------------------------------------------------
106113
// -----------------------------------------------------------------------------------------
107114

108115
@Given("A logged in admin user with username and password")
109116
public void adminLogin() throws InterruptedException {
117+
System.out.println("\nhi1\n");
110118
driver = new ChromeDriver();
111119
driver.get(URL);
112120
Thread.sleep(2500);
@@ -211,7 +219,7 @@ public void theParticipantAddedSuccessfully(String email) throws InterruptedExce
211219

212220
// -----------------------------------------------------------------------------
213221
// -----------------------------------------------------------------------------
214-
// Second scenario: Teacher reduces the maximum size of the file to submit to 1.
222+
// Second scenario: Admin remove participant.
215223
// -----------------------------------------------------------------------------
216224
// -----------------------------------------------------------------------------
217225

@@ -291,4 +299,215 @@ public void theParticipantRemovedSuccessfully(String email) throws InterruptedEx
291299
driver.quit();
292300
}
293301

302+
303+
// -----------------------------------------------------------------------------
304+
// -----------------------------------------------------------------------------
305+
// 3rd scenario: Admin adds new operator.
306+
// -----------------------------------------------------------------------------
307+
// -----------------------------------------------------------------------------
308+
309+
@And("There is no operator with the username {string}")
310+
public void thereIsNoOperatorWithTheUsername(String username) throws InterruptedException {
311+
WebElement Operators_Button = driver.findElement(By.xpath(operators_Button));
312+
Operators_Button.click();
313+
Thread.sleep(DELAY_BETWEEN_STEPS);
314+
List<WebElement> adminCells = driver.findElements(By.cssSelector(Participants_Table));
315+
int result = check_if_exists_record_with_email(adminCells, username);
316+
if(result != -1){
317+
adminCells.get(result).click();
318+
319+
//click on the delete button to remove the user
320+
WebElement deleteButton = driver.findElement(By.xpath(Remove_Operator_Button));
321+
deleteButton.click();
322+
323+
//accept the alert
324+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
325+
wait.until(ExpectedConditions.alertIsPresent());
326+
Alert alert = driver.switchTo().alert();
327+
alert.accept();
328+
329+
//accept the second alert
330+
WebDriverWait wait2 = new WebDriverWait(driver, Duration.ofSeconds(10));
331+
wait2.until(ExpectedConditions.alertIsPresent());
332+
Alert alert2 = driver.switchTo().alert();
333+
alert2.accept();
334+
335+
}
336+
}
337+
338+
@When("Add operator with the username {string} and password {string}")
339+
public void addOperator(String username, String password) throws InterruptedException {
340+
WebElement addOperatorButton = driver.findElement(By.xpath(add_Operator));
341+
addOperatorButton.click();
342+
Thread.sleep(DELAY_BETWEEN_STEPS);
343+
344+
//add the details of the operator
345+
WebElement UserNameButton = driver.findElement(By.xpath(add_Operator_Username_Textbox));
346+
UserNameButton.sendKeys(username);
347+
WebElement PasswordButton = driver.findElement(By.xpath(add_Operator_Password_Textbox));
348+
PasswordButton.sendKeys(password);
349+
Thread.sleep(DELAY_BETWEEN_STEPS);
350+
351+
WebElement saveButton = driver.findElement(By.xpath(add_Operator_Save_Button));
352+
saveButton.click();
353+
354+
//handles the opened window
355+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
356+
wait.until(ExpectedConditions.alertIsPresent());
357+
Alert alert = driver.switchTo().alert();
358+
alert.accept();
359+
360+
Thread.sleep(DELAY_BETWEEN_STEPS);
361+
}
362+
363+
@Then("The operator with username {string} added successfully")
364+
public void theOperatorAddedSuccessfully(String username) throws InterruptedException {
365+
List<WebElement> operatorsCells = driver.findElements(By.cssSelector(Participants_Table));
366+
assertNotEquals(check_if_exists_record_with_email(operatorsCells, username), -1);
367+
Thread.sleep(2500);
368+
}
369+
370+
@And("The operator with username {string} and password {string} can log in")
371+
public void operatorCanLogin(String username, String password) throws InterruptedException {
372+
driver.get(main_Menu_URL);
373+
try {
374+
WebElement disconnectButton = driver.findElement(By.xpath(disconnect_Button));
375+
disconnectButton.click();
376+
}
377+
catch (Exception ignored) {
378+
379+
}
380+
WebElement UserNameButton = driver.findElement(By.xpath(Username_Text_Box));
381+
UserNameButton.sendKeys(username);
382+
Thread.sleep(DELAY_BETWEEN_STEPS);
383+
384+
WebElement PasswordButton = driver.findElement(By.xpath(Password_Text_Box));
385+
PasswordButton.sendKeys(password);
386+
Thread.sleep(DELAY_BETWEEN_STEPS);
387+
388+
WebElement loginButton = driver.findElement(By.xpath(LoginButton_In_Login_Page));
389+
loginButton.click();
390+
Thread.sleep(DELAY_BETWEEN_STEPS);
391+
392+
try {
393+
WebElement disconnectButton = driver.findElement(By.xpath(disconnect_Button));
394+
disconnectButton.click();
395+
assertTrue(true);
396+
}
397+
catch (Exception ignored) {
398+
fail();
399+
}
400+
driver.quit();
401+
}
402+
403+
// -----------------------------------------------------------------------------
404+
// -----------------------------------------------------------------------------
405+
// 4th scenario: Admin removes operator.
406+
// -----------------------------------------------------------------------------
407+
// -----------------------------------------------------------------------------
408+
409+
@And("There is an operator with the username {string} and password {string}")
410+
public void thereIsAnOperatorWithTheUsername(String username, String password) throws InterruptedException {
411+
WebElement Operators_Button = driver.findElement(By.xpath(operators_Button));
412+
Operators_Button.click();
413+
System.out.println("\nhi2\n");
414+
Thread.sleep(DELAY_BETWEEN_STEPS);
415+
416+
List<WebElement> adminCells = driver.findElements(By.cssSelector(Participants_Table));
417+
int result = check_if_exists_record_with_email(adminCells, username);
418+
System.out.println("\nhi " + Integer.toString(result) + "\n");
419+
if(result == -1){
420+
WebElement addOperatorButton = driver.findElement(By.xpath(add_Operator));
421+
addOperatorButton.click();
422+
Thread.sleep(DELAY_BETWEEN_STEPS);
423+
424+
//add the details of the operator
425+
WebElement UserNameButton = driver.findElement(By.xpath(add_Operator_Username_Textbox));
426+
UserNameButton.sendKeys(username);
427+
WebElement PasswordButton = driver.findElement(By.xpath(add_Operator_Password_Textbox));
428+
PasswordButton.sendKeys(password);
429+
Thread.sleep(DELAY_BETWEEN_STEPS);
430+
431+
WebElement saveButton = driver.findElement(By.xpath(add_Operator_Save_Button));
432+
saveButton.click();
433+
434+
//handles the opened window
435+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
436+
wait.until(ExpectedConditions.alertIsPresent());
437+
Alert alert = driver.switchTo().alert();
438+
alert.accept();
439+
440+
Thread.sleep(DELAY_BETWEEN_STEPS);
441+
}
442+
}
443+
444+
@When("Remove the operator with the username {string}")
445+
public void reomoveOperator(String username) throws InterruptedException {
446+
List<WebElement> adminCells = driver.findElements(By.cssSelector(Participants_Table));
447+
int result = check_if_exists_record_with_email(adminCells, username);
448+
if(result != -1){
449+
adminCells.get(result).click();
450+
451+
//click on the delete button to remove the user
452+
WebElement deleteButton = driver.findElement(By.xpath(Remove_Operator_Button));
453+
deleteButton.click();
454+
455+
//accept the alert
456+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
457+
wait.until(ExpectedConditions.alertIsPresent());
458+
Alert alert = driver.switchTo().alert();
459+
alert.accept();
460+
461+
//accept the second alert
462+
WebDriverWait wait2 = new WebDriverWait(driver, Duration.ofSeconds(10));
463+
wait2.until(ExpectedConditions.alertIsPresent());
464+
Alert alert2 = driver.switchTo().alert();
465+
alert2.accept();
466+
467+
}
468+
else {
469+
fail("the operator " + username + " was not found");
470+
}
471+
}
472+
473+
@Then("The operator with username {string} removed successfully")
474+
public void theOperatorRemovedSuccessfully(String username) throws InterruptedException {
475+
List<WebElement> operatorsCells = driver.findElements(By.cssSelector(Participants_Table));
476+
assertEquals(check_if_exists_record_with_email(operatorsCells, username), -1);
477+
Thread.sleep(2500);
478+
}
479+
480+
@And("The operator with username {string} and password {string} can't log in")
481+
public void operatorCantLogin(String username, String password) throws InterruptedException {
482+
driver.get(main_Menu_URL);
483+
try {
484+
WebElement disconnectButton = driver.findElement(By.xpath(disconnect_Button));
485+
disconnectButton.click();
486+
}
487+
catch (Exception ignored) {
488+
489+
}
490+
WebElement UserNameButton = driver.findElement(By.xpath(Username_Text_Box));
491+
UserNameButton.sendKeys(username);
492+
Thread.sleep(DELAY_BETWEEN_STEPS);
493+
494+
WebElement PasswordButton = driver.findElement(By.xpath(Password_Text_Box));
495+
PasswordButton.sendKeys(password);
496+
Thread.sleep(DELAY_BETWEEN_STEPS);
497+
498+
WebElement loginButton = driver.findElement(By.xpath(LoginButton_In_Login_Page));
499+
loginButton.click();
500+
Thread.sleep(DELAY_BETWEEN_STEPS);
501+
502+
try {
503+
WebElement disconnectButton = driver.findElement(By.xpath(disconnect_Button));
504+
disconnectButton.click();
505+
fail();
506+
}
507+
catch (Exception ignored) {
508+
assertTrue(true);
509+
}
510+
driver.quit();
511+
}
512+
294513
}
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Feature: add and remove participants
22

3-
Scenario Outline: Manager adds new participant
3+
Scenario Outline: Admin adds new participant
44
Given A logged in admin user with username and password
55
And There is no participant with the email "<email>"
66
When Add participant with the email "<email>"
@@ -9,7 +9,7 @@ Feature: add and remove participants
99
| email |
1010
| tamirosh@post.bgu.ac.il |
1111

12-
Scenario Outline: Manager remove participant
12+
Scenario Outline: Admin remove participant
1313
Given A logged in admin user with username and password
1414
And There is a participant with the email "<email>"
1515
When remove the participant with the email "<email>"
@@ -18,3 +18,22 @@ Feature: add and remove participants
1818
| email |
1919
| tamirosh@post.bgu.ac.il |
2020

21+
Scenario Outline: Admin adds new operator
22+
Given A logged in admin user with username and password
23+
And There is no operator with the username "<username>"
24+
When Add operator with the username "<username>" and password "<password>"
25+
Then The operator with username "<username>" added successfully
26+
And The operator with username "<username>" and password "<password>" can log in
27+
Examples:
28+
| username | password |
29+
| tamirosh | Pass1234 |
30+
31+
Scenario Outline: Admin removes operator
32+
Given A logged in admin user with username and password
33+
And There is an operator with the username "<username>" and password "<password>"
34+
When Remove the operator with the username "<username>"
35+
Then The operator with username "<username>" removed successfully
36+
And The operator with username "<username>" and password "<password>" can't log in
37+
Examples:
38+
| username | password |
39+
| tamirosh | Pass1234 |

0 commit comments

Comments
 (0)