1818
1919import static io .github .boykaframework .actions .CommonActions .pause ;
2020import static io .github .boykaframework .actions .CommonActions .performElementAction ;
21- import static io .github .boykaframework .actions .elements .ElementFinder .find ;
22- import static io .github .boykaframework .enums .ApplicationType .WEB ;
21+ import static io .github .boykaframework .actions .CommonActions .performMobileGestures ;
2322import static io .github .boykaframework .enums .ListenerType .CLICKABLE_ACTION ;
24- import static io .github .boykaframework .enums .PlatformType .IOS ;
25- import static io .github .boykaframework .enums .WaitStrategy .CLICKABLE ;
2623import static io .github .boykaframework .manager .ParallelSession .getSession ;
27- import static io . github . boykaframework . utils . Validator . validateDelay ;
24+ import static java . util . Collections . singletonList ;
2825import static java .util .Optional .ofNullable ;
2926import static org .apache .logging .log4j .LogManager .getLogger ;
3027
3128import io .github .boykaframework .actions .interfaces .elements .IClickableActions ;
3229import io .github .boykaframework .actions .interfaces .listeners .elements .IClickableActionsListener ;
3330import io .github .boykaframework .builders .Locator ;
34- import io .github .boykaframework .enums .PlatformType ;
3531import org .apache .logging .log4j .Logger ;
3632import org .openqa .selenium .WebElement ;
37- import org .openqa .selenium .interactions .Actions ;
3833
3934/**
4035 * Handles all mouse related actions
@@ -68,16 +63,11 @@ public void click () {
6863 LOGGER .traceEntry ();
6964 LOGGER .info ("Clicking on element: {}" , this .locator .getName ());
7065 ofNullable (this .listener ).ifPresent (l -> l .onClick (this .locator ));
71- final var session = getSession ();
72- if (session .getPlatformType () == PlatformType .WEB || (session .getMobileSetting ()
73- .getDevice ()
74- .getApplication ()
75- .getType () == WEB && session .getPlatformType () == IOS )) {
76- pause (this .delaySetting .getBeforeClick ());
77- performElementAction (WebElement ::click , this .locator );
78- } else {
79- tap ();
80- }
66+ pause (this .delaySetting .getBeforeClick ());
67+ MouseActionBuilder .builder ()
68+ .sourceLocator (this .locator )
69+ .build ()
70+ .click ();
8171 LOGGER .traceExit ();
8272 }
8373
@@ -86,12 +76,10 @@ public void clickAndHold () {
8676 LOGGER .traceEntry ();
8777 LOGGER .info ("Click and hold on element: {}" , this .locator .getName ());
8878 ofNullable (this .listener ).ifPresent (l -> l .onClickAndHold (this .locator ));
89- performElementAction ((driver , element ) -> {
90- final var actions = new Actions (driver );
91- actions .pause (validateDelay (this .delaySetting .getBeforeClick ()))
92- .clickAndHold (element )
93- .perform ();
94- }, this .locator );
79+ MouseActionBuilder .builder ()
80+ .sourceLocator (this .locator )
81+ .build ()
82+ .clickAndHold ();
9583 LOGGER .traceExit ();
9684 }
9785
@@ -100,12 +88,10 @@ public void doubleClick () {
10088 LOGGER .traceEntry ();
10189 LOGGER .info ("Double Click on element: {}" , this .locator .getName ());
10290 ofNullable (this .listener ).ifPresent (l -> l .onDoubleClick (this .locator ));
103- performElementAction ((driver , element ) -> {
104- final var actions = new Actions (driver );
105- actions .pause (validateDelay (this .delaySetting .getBeforeClick ()))
106- .doubleClick (element )
107- .perform ();
108- }, this .locator );
91+ MouseActionBuilder .builder ()
92+ .sourceLocator (this .locator )
93+ .build ()
94+ .doubleClick ();
10995 LOGGER .traceExit ();
11096 }
11197
@@ -114,12 +100,10 @@ public void dragTo (final Locator destination) {
114100 LOGGER .traceEntry ();
115101 LOGGER .info ("Drag and Drop on element: {} , {}" , this .locator .getName (), destination .getName ());
116102 ofNullable (this .listener ).ifPresent (l -> l .onDragTo (this .locator , destination ));
117- performElementAction ((driver , element ) -> {
118- final var actions = new Actions (driver );
119- actions .pause (validateDelay (this .delaySetting .getBeforeMouseMove ()))
120- .dragAndDrop (element , find (destination , CLICKABLE ))
121- .perform ();
122- }, this .locator );
103+ MouseActionBuilder .builder ()
104+ .sourceLocator (this .locator )
105+ .build ()
106+ .dragAndDrop (destination );
123107 LOGGER .traceExit ();
124108 }
125109
@@ -128,12 +112,34 @@ public void hover () {
128112 LOGGER .traceEntry ();
129113 LOGGER .info ("Hover on element: {}" , this .locator .getName ());
130114 ofNullable (this .listener ).ifPresent (l -> l .onHover (this .locator ));
131- performElementAction ((driver , element ) -> {
132- final var actions = new Actions (driver );
133- actions .pause (validateDelay (this .delaySetting .getBeforeMouseMove ()))
134- .moveToElement (element )
135- .perform ();
136- }, this .locator );
115+ MouseActionBuilder .builder ()
116+ .sourceLocator (this .locator )
117+ .build ()
118+ .moveTo ();
119+ LOGGER .traceExit ();
120+ }
121+
122+ @ Override
123+ public void pressBackButton () {
124+ LOGGER .traceEntry ();
125+ LOGGER .info ("Pressing the Mouse Back button..." );
126+ ofNullable (this .listener ).ifPresent (IClickableActionsListener ::onPressBackButton );
127+ final var sequence = MouseActionBuilder .builder ()
128+ .build ()
129+ .backButtonClick ();
130+ performMobileGestures (singletonList (sequence ));
131+ LOGGER .traceExit ();
132+ }
133+
134+ @ Override
135+ public void pressForwardButton () {
136+ LOGGER .traceEntry ();
137+ LOGGER .info ("Pressing the Mouse Forward button..." );
138+ ofNullable (this .listener ).ifPresent (IClickableActionsListener ::onPressForwardButton );
139+ final var sequence = MouseActionBuilder .builder ()
140+ .build ()
141+ .forwardButtonClick ();
142+ performMobileGestures (singletonList (sequence ));
137143 LOGGER .traceExit ();
138144 }
139145
@@ -142,12 +148,22 @@ public void rightClick () {
142148 LOGGER .traceEntry ();
143149 LOGGER .info ("Right Click on element: {}" , this .locator .getName ());
144150 ofNullable (this .listener ).ifPresent (l -> l .onRightClick (this .locator ));
145- performElementAction ((driver , element ) -> {
146- final var actions = new Actions (driver );
147- actions .pause (validateDelay (this .delaySetting .getBeforeClick ()))
148- .contextClick (element )
149- .perform ();
150- }, this .locator );
151+ MouseActionBuilder .builder ()
152+ .sourceLocator (this .locator )
153+ .build ()
154+ .rightClick ();
155+ LOGGER .traceExit ();
156+ }
157+
158+ @ Override
159+ public void scrollToElement () {
160+ LOGGER .traceEntry ();
161+ LOGGER .info ("Scrolling to element: {}" , this .locator .getName ());
162+ ofNullable (this .listener ).ifPresent (l -> l .onScrollToElement (this .locator ));
163+ MouseActionBuilder .builder ()
164+ .sourceLocator (this .locator )
165+ .build ()
166+ .scrollTo ();
151167 LOGGER .traceExit ();
152168 }
153169
0 commit comments