Skip to content

Commit

Permalink
1385 bug fix broken system tests (#1386)
Browse files Browse the repository at this point in the history
* fix FrameTests.switchToIFrameAndTypeIntoElement

FrameTests.switchToIFrameAndTypeIntoElement:61 Failed to identify unique element using this locator "By.xpath: //input[@name='cardnumber']" Root cause: "org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//iframe[@title='Secure card payment input frame']"}"

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* enabler for mocked API unit tests

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* fix for cucumberTestRunner.CucumberTests.runScenario["Element visual assertions"

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* handling java.lang.RuntimeException:

Unexpected result for screenshot command: com.google.common.collect.Maps$TransformedEntriesMap instance

related to a timeout from renderer and happens on MacOSX_Safari_BrowserStack while navigating back/forward

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* hashing Android_Native_Emulator tests

- these tests add no coverage as the same scope is handled by browserstack, in addition to the fact that they are very flaky due to the nature of emulator tests.

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* updating app url to fix false failure

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* handling null exception

thrown due to failed driver initialization, fixed by a previous commit

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* upgrade local edge installation

this job [Windows_Edge_Local] is facing unreproducible flakiness. upgrading the local edge browser version on the github machine to attempt to neutralize this issue.

TODO: consider removing this job entirely if not needed.
Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* set chrome to latest stable not snapshot

this job [MacOSX_Chrome_Local] is facing unreproducible flakiness. switching the local chrome browser version on the github machine to the latest stable release (default was latest snapshot) to attempt to neutralize this issue.

TODO: consider removing this job entirely if not needed.
Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* fix frameName method bug & enhance test

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* force fail rather than returning empty screenshot

this is better as an empty screenshot is just an unhandled exception waiting to blow up in someone else's face

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* force upgrade edge and chrome to latest

- upgrading browser version should stabilize these pipelines:
-- Windows_Chrome_Local
-- Windows_Edge_Cucumber

- increase retry attempts from '0' to '1'

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* refactor navigation (forward, back, refresh)

- ensure current navigation has stopped before attempting a new navigation action.
- ensure lazy loading operations have finished before attempting a new navigation action.

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* increase default scriptExecutionTimeout

- change from 30 to 60 as it now has impact on executing BiDi scripts, this should improve stability for navigation actions against BiDi-enabled remote webdriver sessions.

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* Refactor some screenshot logic

- switch instead of chained if conditions. (better performance)
- depend on the target browser name rather than the webdriver instance (has a lower chance of failure due to casting issues)
- commenting one of the new exceptions for later tracking

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* removing redundant condition

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

* removing redundant minor test refactoring

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

---------

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

@MahmoudElSharkawy FYI
  • Loading branch information
MohabMohie authored Dec 6, 2023
1 parent 59962e4 commit bd1b243
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 327 deletions.
348 changes: 182 additions & 166 deletions .github/workflows/e2eTests.yml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main/java/com/shaft/api/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import lombok.AccessLevel;
import lombok.Getter;

import java.util.List;
import java.util.Map;
Expand All @@ -15,6 +17,7 @@

import static io.restassured.RestAssured.config;

@Getter(AccessLevel.PACKAGE) //for unit tests
@SuppressWarnings("unused")
public class RequestBuilder {
private RestActions session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ private static void setRemoteDriverInstance(Capabilities capabilities) {
}
}

// stage 2: create remove driver instance (requires some time with dockerized appium)
// stage 2: create remote driver instance (requires some time with dockerized appium)
ReportManager.logDiscrete("Attempting to instantiate remote driver instance for up to " + TimeUnit.SECONDS.toMinutes(remoteServerInstanceCreationTimeout) + "min.");
try {
driver = attemptRemoteServerConnection(capabilities);
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/com/shaft/gui/browser/BrowserActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,23 +323,8 @@ public BrowserActions navigateToURL(String targetUrl, String targetUrlAfterRedir
ReportManager.logDiscrete(
"Target URL: \"" + modifiedTargetUrl + "\", and after redirection: \"" + targetUrlAfterRedirection + "\"");
}
// force stop any current navigation
//noinspection SpellCheckingInspection
forceStopCurrentNavigation();
try {
((JavascriptExecutor) DriverFactoryHelper.getDriver()).executeScript("return window.stop;");
} catch (Exception rootCauseException) {
ReportManagerHelper.logDiscrete(rootCauseException);
/*
* org.openqa.selenium.NoSuchSessionException: Session ID is null. Using
* WebDriver after calling quit()? Build info: version: '3.141.59', revision:
* 'e82be7d358', time: '2018-11-14T08:17:03' System info: host:
* 'gcp-test-automation-sys-187-jenkins-fullaccess', ip: '10.128.0.11', os.name:
* 'Linux', os.arch: 'amd64', os.version: '4.15.0-1027-gcp', java.version:
* '1.8.0_202' Driver info: driver.version: RemoteWebDriver
*/
}
try {
JavaScriptWaitManager.waitForLazyLoading();
String initialURL = "";

if (DriverFactoryHelper.getDriver() instanceof AppiumDriver appiumDriver) {
Expand Down Expand Up @@ -373,6 +358,23 @@ public BrowserActions navigateToURL(String targetUrl, String targetUrlAfterRedir
return this;
}

private void forceStopCurrentNavigation() {
try {
JavaScriptWaitManager.waitForLazyLoading();
((JavascriptExecutor) DriverFactoryHelper.getDriver()).executeScript("return window.stop;");
} catch (Exception rootCauseException) {
ReportManagerHelper.logDiscrete(rootCauseException);
/*
* org.openqa.selenium.NoSuchSessionException: Session ID is null. Using
* WebDriver after calling quit()? Build info: version: '3.141.59', revision:
* 'e82be7d358', time: '2018-11-14T08:17:03' System info: host:
* 'gcp-test-automation-sys-187-jenkins-fullaccess', ip: '10.128.0.11', os.name:
* 'Linux', os.arch: 'amd64', os.version: '4.15.0-1027-gcp', java.version:
* '1.8.0_202' Driver info: driver.version: RemoteWebDriver
*/
}
}

@SuppressWarnings("UnusedReturnValue")
public BrowserActions navigateToURLWithBasicAuthentication(String targetUrl, String username, String password, String targetUrlAfterAuthentication) {
try {
Expand Down Expand Up @@ -436,6 +438,7 @@ private BrowserActions performNavigationAction(NavigationAction navigationAction
var newURL = "";
try {
initialURL = DriverFactoryHelper.getDriver().getCurrentUrl();
forceStopCurrentNavigation();
switch (navigationAction) {
case FORWARD -> DriverFactoryHelper.getDriver().navigate().forward();
case BACK -> DriverFactoryHelper.getDriver().navigate().back();
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/com/shaft/gui/element/ElementActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,11 @@ public ElementActions submitFormUsingJavaScript(By elementLocator) {
*/
public ElementActions switchToIframe(By elementLocator) {
try {
// DriverFactoryHelper.getDriver().switchTo().frame(
var elementInformation = ElementInformation.fromList(
ElementActionsHelper.identifyUniqueElement(DriverFactoryHelper.getDriver(), elementLocator));
// .getFirstElement());
LocatorBuilder.setIFrameLocator(elementInformation.getLocator());
// note to self: remove elementLocator in case of bug in screenshot manager
DriverFactoryHelper.getDriver().switchTo().frame(elementInformation.getFirstElement());
boolean discreetLoggingState = ReportManagerHelper.getDiscreteLogging();
ReportManagerHelper.setDiscreteLogging(true);
ElementActionsHelper.passAction(DriverFactoryHelper.getDriver(), elementLocator, Thread.currentThread().getStackTrace()[1].getMethodName(), String.valueOf(elementLocator), null, elementInformation.getElementName());
Expand Down Expand Up @@ -870,18 +869,8 @@ public ElementActions switchToDefaultContent() {
* @return currentFrame the current frame name
*/
public String getCurrentFrame() {
String currentFrame = "";
try {
if (LocatorBuilder.getIFrameLocator() != null) {
currentFrame = (String) ((JavascriptExecutor) DriverFactoryHelper.getDriver().switchTo().frame(DriverFactoryHelper.getDriver().findElement(LocatorBuilder.getIFrameLocator())))
.executeScript("return self.name");
} else {
currentFrame = (String) ((JavascriptExecutor) DriverFactoryHelper.getDriver()).executeScript("return self.name");
}
ReportManager.logDiscrete("Current frame name: \"" + currentFrame + "\"");
} catch (Exception rootCauseException) {
ReportManager.logDiscrete(String.valueOf(rootCauseException));
}
String currentFrame = (String) ((JavascriptExecutor) DriverFactoryHelper.getDriver()).executeScript("return self.name");
ReportManager.logDiscrete("Current frame name: \"" + currentFrame + "\"");
return currentFrame;
}

Expand Down Expand Up @@ -916,6 +905,7 @@ public String getCurrentFrame() {
*/
public ElementActions type(By elementLocator, String text){
//TODO: refactor to reduce number of webdriver calls
//getting element information using locator
var elementInformation = ElementInformation.fromList(ElementActionsHelper.identifyUniqueElementIgnoringVisibility(DriverFactoryHelper.getDriver(), elementLocator));
String actualTextAfterTyping = ElementActionsHelper.newTypeWrapper(elementInformation, text);
Expand All @@ -926,10 +916,6 @@ public ElementActions type(By elementLocator, String text){
ElementActionsHelper.failAction(DriverFactoryHelper.getDriver(), "Expected to type: \"" + text + "\", but ended up with: \"" + actualTextAfterTyping + "\"",
elementLocator);
}
// } catch (Throwable throwable) {
// // has to be throwable to catch assertion errors in case element was not found
// ElementActionsHelper.failAction(DriverFactoryHelper.getDriver(), elementLocator, throwable);
// }
return this;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ public static List<Object> waitForElementPresence(WebDriver driver, By elementLo
}

private static String performAction(ElementInformation elementInformation, ElementAction action, Object parameter) {
if (LocatorBuilder.getIFrameLocator() != null) {
DriverFactoryHelper.getDriver().switchTo().frame(DriverFactoryHelper.getDriver().findElement(LocatorBuilder.getIFrameLocator()));
}
switch (action) {
case CLICK -> {
//move to element
Expand Down Expand Up @@ -828,9 +825,7 @@ public static String typeWrapper(ElementInformation elementInformation, String t
}
}
public static String readElementText(ElementInformation elementInformation) {

// var elementInformation = ElementInformation.fromList(ElementActionsHelper.identifyUniqueElementIgnoringVisibility(DriverFactoryHelper.getDriver(), elementLocator));
String elementText;
String elementText;
try {
elementText = (elementInformation.getFirstElement()).getText();
} catch (WebDriverException webDriverException) {
Expand All @@ -855,13 +850,10 @@ public static String readElementText(ElementInformation elementInformation) {
}
return elementText;
}
private static void newClearBeforeTyping(By elementLocator){
var elementInformation = ElementInformation.fromList(ElementActionsHelper.performActionAgainstUniqueElement(DriverFactoryHelper.getDriver(), elementLocator));
var attemptClearBeforeTyping = SHAFT.Properties.flags.attemptClearBeforeTyping();
var attemptClearBeforeTypingUsingBackspace = SHAFT.Properties.flags.attemptClearBeforeTypingUsingBackspace();

if (attemptClearBeforeTyping) {
if(attemptClearBeforeTypingUsingBackspace){

private static void newClearBeforeTyping(ElementInformation elementInformation) {
if (SHAFT.Properties.flags.attemptClearBeforeTyping()) {
if (SHAFT.Properties.flags.attemptClearBeforeTypingUsingBackspace()) {
clearBeforeTypingUsingBackSpace(elementInformation);
}
else {
Expand All @@ -871,7 +863,11 @@ private static void newClearBeforeTyping(By elementLocator){
}
private static void clearBeforeTypingUsingNativeClear(ElementInformation elementInformation) {
// try clearing text
ElementActionsHelper.performActionAgainstUniqueElement(DriverFactoryHelper.getDriver(), elementInformation.getLocator(), ElementAction.CLEAR);
try {
elementInformation.getFirstElement().clear();
} catch (Throwable throwable) {
ElementActionsHelper.performActionAgainstUniqueElement(DriverFactoryHelper.getDriver(), elementInformation.getLocator(), ElementAction.CLEAR);
}
var currentTextAfterClearingUsingNativeClear = readElementText(elementInformation);
if (currentTextAfterClearingUsingNativeClear.isBlank()) {
ReportManager.logDiscrete("text cleared Using Native Clear");
Expand Down Expand Up @@ -923,7 +919,7 @@ private static String confirmTextWasTypedCorrectly(ElementInformation elementInf
// and performing type ,
// and double check if typed correctly 'if user enabled the flag'
public static String newTypeWrapper(ElementInformation elementInformation, String targetText) {
newClearBeforeTyping(elementInformation.getLocator());
newClearBeforeTyping(elementInformation);
var adjustedTargetText = targetText != null && !targetText.isEmpty() ? targetText : "";
performType(elementInformation, adjustedTargetText);
//sometimes the text is returned as empty
Expand Down
Loading

0 comments on commit bd1b243

Please sign in to comment.