|
1 | 1 | package hellocucumber; |
2 | 2 |
|
3 | 3 | import io.cucumber.java.en.*; |
4 | | -import io.cucumber.java.AfterAll; |
5 | 4 | import io.cucumber.java.BeforeAll; |
6 | 5 | import org.junit.jupiter.api.AfterEach; |
7 | 6 | import org.junit.jupiter.api.BeforeEach; |
8 | 7 | import org.openqa.selenium.*; |
9 | 8 | import org.openqa.selenium.chrome.ChromeDriver; |
10 | 9 | import org.openqa.selenium.support.ui.ExpectedConditions; |
11 | | -import org.openqa.selenium.support.ui.Select; |
12 | 10 | import org.openqa.selenium.support.ui.WebDriverWait; |
13 | 11 |
|
| 12 | +import java.io.Console; |
14 | 13 | import java.io.File; |
15 | 14 | import java.io.FileInputStream; |
16 | | -import java.io.FileWriter; |
17 | | -import java.io.IOException; |
18 | 15 | import java.time.Duration; |
19 | 16 | import java.util.List; |
20 | 17 | import java.util.Properties; |
@@ -45,9 +42,19 @@ public class StepDefinitions { |
45 | 42 | private final String Add_Participant_Save_Button= "//*[@id=\"participant-modal\"]/div/div/button[2]"; |
46 | 43 | // remove participant |
47 | 44 | 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\"]"; |
48 | 53 |
|
49 | 54 | private final String username = "admin"; |
50 | 55 | 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\"]"; |
51 | 58 |
|
52 | 59 | private String URL; |
53 | 60 |
|
@@ -101,12 +108,13 @@ public void afterEach() throws InterruptedException { |
101 | 108 |
|
102 | 109 | // ----------------------------------------------------------------------------------------- |
103 | 110 | // ----------------------------------------------------------------------------------------- |
104 | | - // First scenario: Manager adds new participant |
| 111 | + // First scenario: Admin adds new participant. |
105 | 112 | // ----------------------------------------------------------------------------------------- |
106 | 113 | // ----------------------------------------------------------------------------------------- |
107 | 114 |
|
108 | 115 | @Given("A logged in admin user with username and password") |
109 | 116 | public void adminLogin() throws InterruptedException { |
| 117 | + System.out.println("\nhi1\n"); |
110 | 118 | driver = new ChromeDriver(); |
111 | 119 | driver.get(URL); |
112 | 120 | Thread.sleep(2500); |
@@ -211,7 +219,7 @@ public void theParticipantAddedSuccessfully(String email) throws InterruptedExce |
211 | 219 |
|
212 | 220 | // ----------------------------------------------------------------------------- |
213 | 221 | // ----------------------------------------------------------------------------- |
214 | | - // Second scenario: Teacher reduces the maximum size of the file to submit to 1. |
| 222 | + // Second scenario: Admin remove participant. |
215 | 223 | // ----------------------------------------------------------------------------- |
216 | 224 | // ----------------------------------------------------------------------------- |
217 | 225 |
|
@@ -291,4 +299,215 @@ public void theParticipantRemovedSuccessfully(String email) throws InterruptedEx |
291 | 299 | driver.quit(); |
292 | 300 | } |
293 | 301 |
|
| 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 | + |
294 | 513 | } |
0 commit comments