@@ -51,12 +51,19 @@ public class StepDefinitions {
5151 private final String add_Operator_Password_Textbox = "//*[@id=\" password\" ]" ;
5252 private final String add_Operator_Save_Button = "//*[@id=\" save-operator-btn\" ]" ;
5353
54+
5455 private final String username = "admin" ;
5556 private final String password = "pass" ;
5657 private final String main_Menu_URL = "https://ims-project.cs.bgu.ac.il/main_menu" ;
5758 private final String disconnect_Button = "//*[@id=\" disconnect-btn\" ]" ;
5859
60+
5961 private final String lobbies_Button = "/html/body/div/button[1]" ;
62+ private final String create_Lobby_Button = "//*[@id=\" create-lobby-btn\" ]" ;
63+ private final String lobby_Participants_Table = "//*[@id='create-lobby-modal']/div/form/div/div[1]/table/tbody/tr" ;
64+ private final String save_Lobby_Button = "//*[@id=\" create-lobby-modal\" ]/div/form/div/div[2]/button[2]" ;
65+ private final String remove_Lobby_Buton = "//*[@id=\" delete-lobby-btn\" ]" ;
66+
6067 private final String session_Data_Button = "/html/body/div/button[4]" ;
6168
6269 private String URL ;
@@ -640,4 +647,200 @@ public void operatorCantSeeTheParticipantsAndOperators() throws InterruptedExcep
640647 driver .quit ();
641648 }
642649
650+ // -----------------------------------------------------------------------------
651+ // -----------------------------------------------------------------------------
652+ // 7th scenario: Admin creates a lobby.
653+ // -----------------------------------------------------------------------------
654+ // -----------------------------------------------------------------------------
655+
656+ @ And ("There is a participant with the email {string} and name {string} {string}" )
657+ public void existsParticipantWithTheEmail (String email , String firstname , String lastname ) throws InterruptedException {
658+ driver .get (main_Menu_URL );
659+ WebElement Participants_Button = driver .findElement (By .xpath (participants_Button ));
660+ Participants_Button .click ();
661+ Thread .sleep (DELAY_BETWEEN_STEPS );
662+
663+ List <WebElement > emailCells = driver .findElements (By .cssSelector (Participants_Table ));
664+ int result = check_if_exists_record_with_email (emailCells , email );
665+ if (result != -1 ){
666+ //choose the specific row at the table
667+ emailCells .get (result ).click ();
668+
669+ //click on the delete button to remove the user
670+ WebElement deleteButton = driver .findElement (By .xpath (Remove_Participant_Button ));
671+ deleteButton .click ();
672+
673+ //accept the alert
674+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
675+ wait .until (ExpectedConditions .alertIsPresent ());
676+ Alert alert = driver .switchTo ().alert ();
677+ alert .accept ();
678+
679+ //accept the second alert
680+ WebDriverWait wait2 = new WebDriverWait (driver , Duration .ofSeconds (10 ));
681+ wait2 .until (ExpectedConditions .alertIsPresent ());
682+ Alert alert2 = driver .switchTo ().alert ();
683+ alert2 .accept ();
684+ Thread .sleep (DELAY_BETWEEN_STEPS );
685+ }
686+ WebElement addParticipantButton = driver .findElement (By .xpath (Add_Participant_Button ));
687+ addParticipantButton .click ();
688+ Thread .sleep (DELAY_BETWEEN_STEPS );
689+
690+ //add the details of the participant
691+ WebElement UserNameButton = driver .findElement (By .xpath (New_Participant_Name_Textbox ));
692+ UserNameButton .sendKeys (firstname );
693+ WebElement LastNameButton = driver .findElement (By .xpath (New_Participant_Last_Name_Textbox ));
694+ LastNameButton .sendKeys (lastname );
695+ WebElement ageButton = driver .findElement (By .xpath (New_Participant_Age_Textbox ));
696+ ageButton .sendKeys (New_Participant_Age_Value );
697+ WebElement phoneButton = driver .findElement (By .xpath (New_Participant_Phone_Number_Textbox ));
698+ phoneButton .sendKeys (New_Participant_Phone_Number_Value );
699+ WebElement emailButton = driver .findElement (By .xpath (New_Participant_Email_Textbox ));
700+ emailButton .sendKeys (email );
701+ Thread .sleep (DELAY_BETWEEN_STEPS );
702+
703+ WebElement saveButton = driver .findElement (By .xpath (Add_Participant_Save_Button ));
704+ saveButton .click ();
705+
706+ //handles the opened window
707+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
708+ wait .until (ExpectedConditions .alertIsPresent ());
709+ Alert alert = driver .switchTo ().alert ();
710+ alert .accept ();
711+ }
712+
713+ @ When ("Creates a lobby with the participants {string} {string} and {string} {string}" )
714+ public void createsLobby (String firstname1 , String lastname1 , String firstname2 , String lastname2 ) throws InterruptedException {
715+ driver .get (main_Menu_URL );
716+ WebElement lobbiesButton = driver .findElement (By .xpath (lobbies_Button ));
717+ lobbiesButton .click ();
718+ Thread .sleep (DELAY_BETWEEN_STEPS );
719+
720+ WebElement createLobbyButton = driver .findElement (By .xpath (create_Lobby_Button ));
721+ createLobbyButton .click ();
722+ Thread .sleep (DELAY_BETWEEN_STEPS );
723+
724+ List <WebElement > rows = driver .findElements (By .xpath (lobby_Participants_Table ));
725+ for (WebElement row : rows ) {
726+ try {
727+ WebElement nameCell = row .findElement (By .xpath ("./td[2]" ));
728+ String name = nameCell .getText ().trim ();
729+
730+ if (name .compareTo (firstname1 + " " + lastname1 ) == 0 ) {
731+ WebElement checkbox = row .findElement (By .xpath ("./td[3]/input[@type='checkbox']" ));
732+ if (!checkbox .isSelected ()) {
733+ checkbox .click ();
734+ }
735+ }
736+ else if (name .compareTo (firstname2 + " " + lastname2 ) == 0 ) {
737+ WebElement checkbox = row .findElement (By .xpath ("./td[3]/input[@type='checkbox']" ));
738+ if (!checkbox .isSelected ()) {
739+ checkbox .click ();
740+ }
741+ }
742+ } catch (Exception e ) {
743+ fail ("can't find the lobby participants table" );
744+ }
745+ }
746+
747+ WebElement saveLobbyButton = driver .findElement (By .xpath (save_Lobby_Button ));
748+ saveLobbyButton .click ();
749+ Thread .sleep (DELAY_BETWEEN_STEPS );
750+ }
751+
752+ @ Then ("The lobby with the participants {string} {string} and {string} {string} created successfully" )
753+ public void lobbyExists (String firstname1 , String lastname1 , String firstname2 , String lastname2 ) throws InterruptedException {
754+ List <WebElement > lobbyCells = driver .findElements (By .cssSelector (Participants_Table ));
755+ assertNotEquals (lobbyCells .size (), 0 );
756+ Thread .sleep (2500 );
757+
758+ //remove it for initialize the state of the system
759+ lobbyCells .get (lobbyCells .size ()-1 ).click ();
760+
761+ //click on the delete button to remove the user
762+ WebElement deleteButton = driver .findElement (By .xpath (remove_Lobby_Buton ));
763+ deleteButton .click ();
764+
765+ //accept the alert
766+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
767+ wait .until (ExpectedConditions .alertIsPresent ());
768+ Alert alert = driver .switchTo ().alert ();
769+ alert .accept ();
770+ driver .quit ();
771+ }
772+
773+ // -----------------------------------------------------------------------------
774+ // -----------------------------------------------------------------------------
775+ // 8th scenario: Admin removes a lobby.
776+ // -----------------------------------------------------------------------------
777+ // -----------------------------------------------------------------------------
778+
779+ @ When ("Exists a lobby with the participants {string} {string} and {string} {string}" )
780+ public void lobbyExist (String firstname1 , String lastname1 , String firstname2 , String lastname2 ) throws InterruptedException {
781+ driver .get (main_Menu_URL );
782+ WebElement lobbiesButton = driver .findElement (By .xpath (lobbies_Button ));
783+ lobbiesButton .click ();
784+ Thread .sleep (DELAY_BETWEEN_STEPS );
785+
786+ WebElement createLobbyButton = driver .findElement (By .xpath (create_Lobby_Button ));
787+ createLobbyButton .click ();
788+ Thread .sleep (DELAY_BETWEEN_STEPS );
789+
790+ List <WebElement > rows = driver .findElements (By .xpath (lobby_Participants_Table ));
791+ for (WebElement row : rows ) {
792+ try {
793+ WebElement nameCell = row .findElement (By .xpath ("./td[2]" ));
794+ String name = nameCell .getText ().trim ();
795+
796+ if (name .compareTo (firstname1 + " " + lastname1 ) == 0 ) {
797+ WebElement checkbox = row .findElement (By .xpath ("./td[3]/input[@type='checkbox']" ));
798+ if (!checkbox .isSelected ()) {
799+ checkbox .click ();
800+ }
801+ }
802+ else if (name .compareTo (firstname2 + " " + lastname2 ) == 0 ) {
803+ WebElement checkbox = row .findElement (By .xpath ("./td[3]/input[@type='checkbox']" ));
804+ if (!checkbox .isSelected ()) {
805+ checkbox .click ();
806+ }
807+ }
808+ } catch (Exception e ) {
809+ fail ("can't find the lobby participants table" );
810+ }
811+ }
812+
813+ WebElement saveLobbyButton = driver .findElement (By .xpath (save_Lobby_Button ));
814+ saveLobbyButton .click ();
815+ Thread .sleep (DELAY_BETWEEN_STEPS );
816+ }
817+
818+ @ Then ("The lobby with the participants {string} {string} and {string} {string} can removed successfully" )
819+ public void removeLobby (String firstname1 , String lastname1 , String firstname2 , String lastname2 ) throws InterruptedException {
820+ List <WebElement > lobbyCells = driver .findElements (By .cssSelector (Participants_Table ));
821+ assertNotEquals (lobbyCells .size (), 0 );
822+ Thread .sleep (2500 );
823+
824+ try {
825+ //remove it for initialize the state of the system
826+ lobbyCells .get (lobbyCells .size () - 1 ).click ();
827+
828+ //click on the delete button to remove the user
829+ WebElement deleteButton = driver .findElement (By .xpath (remove_Lobby_Buton ));
830+ deleteButton .click ();
831+
832+ //accept the alert
833+ WebDriverWait wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
834+ wait .until (ExpectedConditions .alertIsPresent ());
835+ Alert alert = driver .switchTo ().alert ();
836+ alert .accept ();
837+ }
838+ catch (WebDriverException e ) {
839+ fail ("cant find the lobby participants table" );
840+ }
841+ catch (Exception e ) {
842+ fail ("can't find the lobby participants table" );
843+ }
844+ driver .quit ();
845+ }
643846}
0 commit comments