Skip to content

Commit

Permalink
fix(java): 🐛 fixed issue when clicking hovered element
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB committed Oct 2, 2024
1 parent 1ded715 commit 079c3e9
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 184 deletions.
13 changes: 7 additions & 6 deletions core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,6 @@
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven.gpg.version}</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${nexus.version}</version>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
Expand Down Expand Up @@ -479,7 +474,7 @@
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
<value>true</value>
</property>
</properties>
<systemPropertyVariables>
Expand Down Expand Up @@ -585,6 +580,12 @@
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>${failsafe.jacoco.args}</argLine>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>true</value>
</property>
</properties>
<suiteXmlFiles>
<suiteXmlFile>${suite-xml}</suiteXmlFile>
</suiteXmlFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void click () {
.getApplication ()
.getType () == WEB && session.getPlatformType () == IOS)) {
pause (this.delaySetting.getBeforeClick ());
scrollIntoView ();
performElementAction (WebElement::click, this.locator);
} else {
tap ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public boolean isDisplayed () {
LOGGER.traceEntry ();
LOGGER.info ("Checking if element located by: {} is displayed", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onIsDisplayed (this.locator));
return LOGGER.traceExit (getElementAttribute (WebElement::isDisplayed, this.locator, false));
return LOGGER.traceExit (displayed ());
}

@Override
Expand All @@ -138,7 +138,11 @@ public void scrollIntoView () {
LOGGER.info ("Scrolling element located by [{}] into view", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onScrollIntoView (this.locator));
pause (this.delaySetting.getBeforeMouseMove ());
performElementAction (e -> withDriver ().executeScript ("arguments[0].scrollIntoView(true);", e), this.locator);
performElementAction (e -> {
if (!displayed ()) {
withDriver ().executeScript ("arguments[0].scrollIntoView(true);", e);
}
}, this.locator);
}

@Override
Expand Down Expand Up @@ -205,4 +209,8 @@ public StringSubject verifyText () {
protected String getAttributeValue (final String attribute) {
return getElementAttribute (e -> e.getAttribute (attribute), this.locator, EMPTY);
}

private boolean displayed () {
return getElementAttribute (WebElement::isDisplayed, this.locator, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* MIT License
*
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package io.github.boykaframework.testng.ui.ecomm;

import static io.github.boykaframework.actions.drivers.NavigateActions.navigate;
import static io.github.boykaframework.actions.drivers.WindowActions.onWindow;
import static io.github.boykaframework.actions.elements.ClickableActions.withMouse;
import static io.github.boykaframework.actions.elements.ElementActions.onElement;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static io.github.boykaframework.testng.ui.ecomm.pages.HomePage.homePage;

import io.github.boykaframework.enums.PlatformType;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class AddCartTest {
@AfterMethod
public void afterMethod (final ITestResult result) {
if (!result.isSuccess ()) {
onWindow ().takeScreenshot ();
}
}

@BeforeClass
@Parameters ({ "platformType", "driverKey" })
public void setupTestClass (final PlatformType platformType, final String chromeConfig) {
createSession (platformType, chromeConfig);
}

@AfterClass
public void tearDownClass () {
clearSession ();
}

@Test
public void testAddCart () {
navigate ().to ("https://ecommerce-playground.lambdatest.io/");
withMouse (homePage ().getProduct1 ()).hover ();
withMouse (homePage ().getAddToCart ()).click ();
withMouse (homePage ().getCloseToast ()).click ();

onElement (homePage ().getCartCount ()).verifyText ()
.isEqualTo ("1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* MIT License
*
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package io.github.boykaframework.testng.ui.ecomm.pages;

import static org.openqa.selenium.By.cssSelector;

import io.github.boykaframework.builders.Locator;
import lombok.Getter;

/**
* E-Comm Home Page
*
* @author Wasiq Bhamla
* @since 02-Oct-2024
*/
@Getter
public class HomePage {
private static final HomePage HOME_PAGE = new HomePage ();

/**
* Gets the Home page instance
*
* @return Home page
*/
public static HomePage homePage () {
return HOME_PAGE;
}

private final Locator addToCart = Locator.buildLocator ()
.name ("Add To Cart")
.web (cssSelector ("div.product-action button[title=\"Add to Cart\"]"))
.build ();
private final Locator cartCount = Locator.buildLocator ()
.name ("Cart Count")
.web (cssSelector ("div.cart-icon span"))
.build ();
private final Locator closeToast = Locator.buildLocator ()
.name ("Close Toast")
.web (cssSelector ("button[data-dismiss=\"toast\"]"))
.build ();
private final Locator product1 = Locator.buildLocator ()
.web (cssSelector ("div.entry-section div[aria-label=\"1 / 10\"] div.product-thumb-top"))
.name ("Product 1")
.build ();

private HomePage () {
// Utility class.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import static io.github.boykaframework.actions.drivers.DriverActions.withDriver;
import static io.github.boykaframework.actions.drivers.NavigateActions.navigate;
import static io.github.boykaframework.actions.drivers.WindowActions.onWindow;
import static io.github.boykaframework.actions.elements.ClickableActions.withMouse;
import static io.github.boykaframework.actions.elements.ElementActions.onElement;
import static io.github.boykaframework.actions.elements.TextBoxActions.onTextBox;
import static io.github.boykaframework.manager.ParallelSession.clearAllSessions;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static io.github.boykaframework.manager.ParallelSession.getSession;
Expand All @@ -31,8 +33,6 @@
import static io.github.boykaframework.testng.ui.jiomeet.pages.StartMeetingPage.startMeetingPage;
import static org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOfElementLocated;

import io.github.boykaframework.actions.drivers.WindowActions;
import io.github.boykaframework.actions.elements.TextBoxActions;
import io.github.boykaframework.enums.PlatformType;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
Expand All @@ -50,8 +50,7 @@ public class JioMeetTest {
@AfterMethod
public void afterMethod (final ITestResult result) {
if (!result.isSuccess ()) {
WindowActions.onWindow ()
.takeScreenshot ();
onWindow ().takeScreenshot ();
}
}

Expand Down Expand Up @@ -96,8 +95,7 @@ public void testGuestStartMeeting () {
switchPersona (GUEST_PERSONA);
navigate ().to (meetingUrl);

TextBoxActions.onTextBox (guestJoinPage ().getGuestName ())
.enterText (GUEST_PERSONA);
onTextBox (guestJoinPage ().getGuestName ()).enterText (GUEST_PERSONA);
withMouse (guestJoinPage ().getJoinButton ()).click ();

withDriver ().waitUntil (invisibilityOfElementLocated (homePage ().getLoader ()
Expand All @@ -118,11 +116,9 @@ public void testHostSignIn () {
navigate ().to ("https://jiomeetpro.jio.com/home");

withMouse (homePage ().getSignIn ()).click ();
TextBoxActions.onTextBox (signInPage ().getEmail ())
.enterText ("test-user1@mailinator.com");
onTextBox (signInPage ().getEmail ()).enterText ("test-user1@mailinator.com");
withMouse (signInPage ().getProceedButton ()).click ();
TextBoxActions.onTextBox (signInPage ().getPassword ())
.enterText ("Admin@1234");
onTextBox (signInPage ().getPassword ()).enterText ("Admin@1234");
withMouse (signInPage ().getSignInButton ()).click ();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package io.github.boykaframework.testng.ui.saucedemo;

import static io.github.boykaframework.actions.device.DeviceActions.onDevice;
import static io.github.boykaframework.actions.drivers.ContextActions.withContext;
import static io.github.boykaframework.actions.drivers.DriverActions.withDriver;
import static io.github.boykaframework.actions.drivers.WindowActions.onWindow;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static java.text.MessageFormat.format;

import io.github.boykaframework.actions.drivers.ContextActions;
import io.github.boykaframework.enums.PlatformType;
import io.github.boykaframework.exception.FrameworkError;
import io.github.boykaframework.testng.ui.saucedemo.actions.SauceDemoActions;
Expand Down Expand Up @@ -106,8 +106,7 @@ public void testCheckoutStep2 () {
*/
@Test (description = "Test context switching in Native app", dependsOnMethods = "testSignOut", expectedExceptions = FrameworkError.class)
public void testContextSwitching () {
ContextActions.withContext ()
.switchToWebView ("WEBVIEW");
withContext ().switchToWebView ("WEBVIEW");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package io.github.boykaframework.testng.ui.theinternet;

import static io.github.boykaframework.actions.drivers.AlertActions.onAlert;
import static io.github.boykaframework.actions.drivers.NavigateActions.navigate;
import static io.github.boykaframework.actions.drivers.WindowActions.onWindow;
import static io.github.boykaframework.actions.elements.ClickableActions.withMouse;
import static io.github.boykaframework.actions.elements.ElementActions.onElement;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static io.github.boykaframework.testng.ui.theinternet.pages.AlertPage.alertPage;
import static io.github.boykaframework.testng.ui.theinternet.pages.HomePage.homePage;

import io.github.boykaframework.actions.drivers.NavigateActions;
import io.github.boykaframework.actions.drivers.WindowActions;
import io.github.boykaframework.enums.PlatformType;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand All @@ -51,10 +51,8 @@ public class AlertsTest {
@Parameters ({ "platformType", "driverKey" })
public void setupClass (final PlatformType platformType, final String driverKey) {
createSession ("AlertsTest", platformType, driverKey);
WindowActions.onWindow ()
.fullScreen ();
NavigateActions.navigate ()
.to (URL);
onWindow ().fullScreen ();
navigate ().to (URL);
withMouse (homePage ().link ("JavaScript Alerts")).click ();
}

Expand All @@ -63,10 +61,8 @@ public void setupClass (final PlatformType platformType, final String driverKey)
*/
@AfterClass (description = "Tear down test class")
public void tearDownClass () {
NavigateActions.navigate ()
.back ();
NavigateActions.navigate ()
.verifyUrl ()
navigate ().back ();
navigate ().verifyUrl ()
.isEqualTo (URL);
clearSession ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package io.github.boykaframework.testng.ui.theinternet;

import static io.github.boykaframework.actions.drivers.NavigateActions.navigate;
import static io.github.boykaframework.actions.elements.ClickableActions.withMouse;
import static io.github.boykaframework.actions.elements.ElementActions.onElement;
import static io.github.boykaframework.manager.ParallelSession.clearSession;
import static io.github.boykaframework.manager.ParallelSession.createSession;
import static io.github.boykaframework.testng.ui.theinternet.pages.CheckboxPage.checkboxPage;

import io.github.boykaframework.actions.drivers.NavigateActions;
import io.github.boykaframework.enums.PlatformType;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand All @@ -42,8 +42,7 @@ public class CheckboxTest {
@Parameters ({ "platformType", "driverKey" })
public void setupClass (final PlatformType platformType, final String driverKey) {
createSession ("CheckboxTest", platformType, driverKey);
NavigateActions.navigate ()
.to (URL);
navigate ().to (URL);
}

/**
Expand Down
Loading

0 comments on commit 079c3e9

Please sign in to comment.