@@ -56,6 +56,9 @@ public class StepDefinitions {
5656 private final String main_Menu_URL = "https://ims-project.cs.bgu.ac.il/main_menu" ;
5757 private final String disconnect_Button = "//*[@id=\" disconnect-btn\" ]" ;
5858
59+ private final String lobbies_Button = "/html/body/div/button[1]" ;
60+ private final String session_Data_Button = "/html/body/div/button[4]" ;
61+
5962 private String URL ;
6063
6164 public StepDefinitions () throws InterruptedException {
@@ -114,7 +117,6 @@ public void afterEach() throws InterruptedException {
114117
115118 @ Given ("A logged in admin user with username and password" )
116119 public void adminLogin () throws InterruptedException {
117- System .out .println ("\n hi1\n " );
118120 driver = new ChromeDriver ();
119121 driver .get (URL );
120122 Thread .sleep (2500 );
@@ -410,12 +412,10 @@ public void operatorCanLogin(String username, String password) throws Interrupte
410412 public void thereIsAnOperatorWithTheUsername (String username , String password ) throws InterruptedException {
411413 WebElement Operators_Button = driver .findElement (By .xpath (operators_Button ));
412414 Operators_Button .click ();
413- System .out .println ("\n hi2\n " );
414415 Thread .sleep (DELAY_BETWEEN_STEPS );
415416
416417 List <WebElement > adminCells = driver .findElements (By .cssSelector (Participants_Table ));
417418 int result = check_if_exists_record_with_email (adminCells , username );
418- System .out .println ("\n hi " + Integer .toString (result ) + "\n " );
419419 if (result == -1 ){
420420 WebElement addOperatorButton = driver .findElement (By .xpath (add_Operator ));
421421 addOperatorButton .click ();
@@ -510,4 +510,134 @@ public void operatorCantLogin(String username, String password) throws Interrupt
510510 driver .quit ();
511511 }
512512
513+ // -----------------------------------------------------------------------------
514+ // -----------------------------------------------------------------------------
515+ // 5th scenario: Operator can see Lobbies and Session Data functionality.
516+ // -----------------------------------------------------------------------------
517+ // -----------------------------------------------------------------------------
518+
519+ @ Given ("Exists an operator with the username {string} and password {string}" )
520+ public void existsOperator (String username , String password ) throws InterruptedException {
521+ driver = new ChromeDriver ();
522+ driver .get (URL );
523+ Thread .sleep (2500 );
524+
525+ WebElement UserNameButton = driver .findElement (By .xpath (Username_Text_Box ));
526+ UserNameButton .sendKeys (this .username );
527+ Thread .sleep (DELAY_BETWEEN_STEPS );
528+
529+ WebElement PasswordButton = driver .findElement (By .xpath (Password_Text_Box ));
530+ PasswordButton .sendKeys (this .password );
531+ Thread .sleep (DELAY_BETWEEN_STEPS );
532+
533+ WebElement loginButton = driver .findElement (By .xpath (LoginButton_In_Login_Page ));
534+ loginButton .click ();
535+ Thread .sleep (DELAY_BETWEEN_STEPS );
536+
537+ WebElement Operators_Button = driver .findElement (By .xpath (operators_Button ));
538+ Operators_Button .click ();
539+ Thread .sleep (DELAY_BETWEEN_STEPS );
540+
541+ List <WebElement > adminCells = driver .findElements (By .cssSelector (Participants_Table ));
542+ int result = check_if_exists_record_with_email (adminCells , username );
543+ if (result == -1 ){
544+ WebElement addOperatorButton = driver .findElement (By .xpath (add_Operator ));
545+ addOperatorButton .click ();
546+ Thread .sleep (DELAY_BETWEEN_STEPS );
547+
548+ //add the details of the operator
549+ WebElement userNameButton = driver .findElement (By .xpath (add_Operator_Username_Textbox ));
550+ userNameButton .sendKeys (username );
551+ WebElement passwordButton = driver .findElement (By .xpath (add_Operator_Password_Textbox ));
552+ passwordButton .sendKeys (password );
553+ Thread .sleep (DELAY_BETWEEN_STEPS );
554+
555+ WebElement saveButton = driver .findElement (By .xpath (add_Operator_Save_Button ));
556+ saveButton .click ();
557+
558+ //handles the opened window
559+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
560+ wait .until (ExpectedConditions .alertIsPresent ());
561+ Alert alert = driver .switchTo ().alert ();
562+ alert .accept ();
563+
564+ Thread .sleep (DELAY_BETWEEN_STEPS );
565+ }
566+ }
567+
568+ @ And ("The operator with the username {string} and password {string} is logged in" )
569+ public void operatorLogin (String username , String password ) throws InterruptedException {
570+ driver .get (main_Menu_URL );
571+ try {
572+ WebElement disconnectButton = driver .findElement (By .xpath (disconnect_Button ));
573+ disconnectButton .click ();
574+ }
575+ catch (Exception ignored ) {
576+
577+ }
578+ WebElement UserNameButton = driver .findElement (By .xpath (Username_Text_Box ));
579+ UserNameButton .sendKeys (username );
580+ Thread .sleep (DELAY_BETWEEN_STEPS );
581+
582+ WebElement PasswordButton = driver .findElement (By .xpath (Password_Text_Box ));
583+ PasswordButton .sendKeys (password );
584+ Thread .sleep (DELAY_BETWEEN_STEPS );
585+
586+ WebElement loginButton = driver .findElement (By .xpath (LoginButton_In_Login_Page ));
587+ loginButton .click ();
588+ Thread .sleep (DELAY_BETWEEN_STEPS );
589+ }
590+
591+ @ When ("The operator is in the main menu page" )
592+ public void operatorIsInMainMenu () throws InterruptedException {
593+ driver .get (main_Menu_URL );
594+ }
595+
596+ @ Then ("The operator can see the Lobbies and Session Data buttons" )
597+ public void operatorCanSeeTheLobbiesAndSessionData () throws InterruptedException {
598+ try {
599+ WebElement lobbiesButton = driver .findElement (By .xpath (lobbies_Button ));
600+ lobbiesButton .click ();
601+ WebElement sessionDataButton = driver .findElement (By .xpath (session_Data_Button ));
602+ sessionDataButton .click ();
603+ }
604+ catch (Exception e ) {
605+ fail ("can't find the button" );
606+ }
607+ driver .quit ();
608+ }
609+
610+ // -----------------------------------------------------------------------------
611+ // -----------------------------------------------------------------------------
612+ // 6th scenario: Operator can't see Participants and Operators functionality.
613+ // -----------------------------------------------------------------------------
614+ // -----------------------------------------------------------------------------
615+
616+ @ Then ("The operator can't see the Participants and Operators buttons" )
617+ public void operatorCantSeeTheParticipantsAndOperators () throws InterruptedException {
618+ try {
619+ WebElement participantsButton = driver .findElement (By .xpath (participants_Button ));
620+ participantsButton .click ();
621+ fail ("Can find the participant button" );
622+ }
623+ catch (WebDriverException e ) {
624+ assertTrue (true );
625+ }
626+ catch (Exception e ) {
627+ assertTrue (true );
628+ }
629+ try {
630+ WebElement sessionDataButton = driver .findElement (By .xpath (session_Data_Button ));
631+ sessionDataButton .click ();
632+ fail ("Can find the session data button" );
633+ }
634+ catch (WebDriverException e ) {
635+ assertTrue (true );
636+ }
637+ catch (Exception e ) {
638+ assertTrue (true );
639+ }
640+ driver .quit ();
641+ }
642+
513643}
0 commit comments