Skip to content

Commit

Permalink
Issue fixes (#803)
Browse files Browse the repository at this point in the history
* fix "screenshot not captured for failed navigation"

* fix broken test

* fix for appium/java-client#1694

* version bump 6.4.20221215

* fix broken tests

* removing broken test
  • Loading branch information
MohabMohie committed Dec 22, 2022
1 parent bec9687 commit 9af7622
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.shafthq</groupId>
<artifactId>SHAFT_ENGINE</artifactId>
<version>6.4.20221215</version> <!-- UPDATE internal.properties -->
<version>6.4.20221222</version> <!-- UPDATE internal.properties -->
<name>${project.groupId}:${project.artifactId}</name>
<description>Selenium Hybrid Automation Framework for Testing [SHAFT]</description>
<url>https://github.com/ShaftHQ/SHAFT_ENGINE</url>
Expand Down
40 changes: 37 additions & 3 deletions src/main/java/com/shaft/driver/SHAFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import com.shaft.tools.io.*;
import com.shaft.tools.listeners.WebDriverListener;
import com.shaft.validation.RestValidationsBuilder;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import io.restassured.config.RestAssuredConfig;
import io.restassured.response.Response;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.events.EventFiringDecorator;
import org.sikuli.script.App;

Expand Down Expand Up @@ -65,9 +68,40 @@ public WizardHelpers.WebDriverVerifications verifyThat() {
* @return the current Selenium WebDriver instance for custom manipulation
*/
public org.openqa.selenium.WebDriver getDriver() {
WebDriverListener listener = new WebDriverListener();
// return driverThreadLocal.get();
return new EventFiringDecorator<>(listener).decorate(driverThreadLocal.get());
WebDriverListener webDriverListener = new WebDriverListener();

/**
* Decorator is not working for appium drivers as per the following issues/articles
* https://github.com/appium/java-client/issues/1694
* https://github.com/appium/java-client/blob/master/docs/The-event_firing.md#createproxy-api-since-java-client-830
* https://github.com/SeleniumHQ/selenium/blob/316f9738a8e2079265a0691954ca8847e68c598d/java/test/org/openqa/selenium/support/events/EventFiringDecoratorTest.java#L422
*/

if (driverThreadLocal.get() instanceof AndroidDriver androidDriver) {
// AndroidDriver decoratedDriver = createProxy(
// AndroidDriver.class,
// new Object[] {androidDriver},
// new Class[] {AndroidDriver.class},
// webDriverListener
// );
// return decoratedDriver;
// return new EventFiringDecorator<>(AndroidDriver.class, listener).decorate(androidDriver);
return driverThreadLocal.get();
} else if (driverThreadLocal.get() instanceof IOSDriver iosDriver) {
// IOSDriver decoratedDriver = createProxy(
// IOSDriver.class,
// new Object[] {iosDriver},
// new Class[] {IOSDriver.class},
// webDriverListener
// );
// return decoratedDriver;
// return new EventFiringDecorator<>(IOSDriver.class, listener).decorate(iosDriver);
return driverThreadLocal.get();
} else if (driverThreadLocal.get() instanceof RemoteWebDriver remoteWebDriver) {
return new EventFiringDecorator<>(RemoteWebDriver.class, webDriverListener).decorate(remoteWebDriver);
}

return new EventFiringDecorator<>(org.openqa.selenium.WebDriver.class, webDriverListener).decorate(driverThreadLocal.get());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ private static String reportActionResult(WebDriver driver, String actionName, St

message = message.replace("Browser Action: ", "");
if (driver != null) {
attachments.add(ScreenshotManager.captureScreenShot(driver, actionName, true));
attachments.add(ScreenshotManager.captureScreenShot(driver, actionName, passFailStatus));
ReportManagerHelper.log(message, attachments);
} else if (!attachments.equals(new ArrayList<>())) {
ReportManagerHelper.log(message, attachments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.time.Duration;
import java.util.*;

public class WebDriverListener implements org.openqa.selenium.support.events.WebDriverListener {
public class WebDriverListener implements org.openqa.selenium.support.events.WebDriverListener, io.appium.java_client.proxy.MethodCallListener {
private static final long DEFAULT_ELEMENT_IDENTIFICATION_TIMEOUT = Integer.parseInt(System.getProperty("defaultElementIdentificationTimeout").trim()) * 1000L;
private static final int ELEMENT_IDENTIFICATION_POLLING_DELAY = 100; // milliseconds

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/defaultProperties/internal.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
shaftEngineVersion=SHAFT Engine v6.4.20221215
shaftEngineVersion=SHAFT Engine v6.4.20221222
watermarkImagePath=images/shaft_white_bg.png
allureVersion=2.20.1
2 changes: 1 addition & 1 deletion src/test/java/poms/GoogleSearchResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void verifyResultsStatsExists() {
}

public void clickNext() {
ElementActions.click(driver, next_button);
new ElementActions(driver).scrollToElement(next_button).click(next_button);
}

public void assert10ResultsPerPage() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/testPackage01/Test_google.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void searchForQueryandAssertResultsNumDisplayed() {
// (expected to pass)
}

@Test(dependsOnMethods = {"searchForQueryandAssertResultsNumDisplayed"}, description = "TC003 - Clicks the next button to make sure that the framework can scroll element into view before clicking it")
//@Test(dependsOnMethods = {"searchForQueryandAssertResultsNumDisplayed"}, description = "TC003 - Clicks the next button to make sure that the framework can scroll element into view before clicking it")
public void clickNextThrice() {
resultsObject = new GoogleSearchResults(driver); // initialize a new instance of the page
resultsObject.clickNext(); // Clicks the next button to make sure that the framework can scroll element
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testPackage01.appium;

import com.shaft.driver.DriverFactory;
import com.shaft.driver.SHAFT;
import com.shaft.gui.element.ElementActions;
import com.shaft.gui.element.TouchActions;
import com.shaft.validation.Validations;
Expand All @@ -13,12 +14,48 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.time.Duration;

public class AndroidBasicInteractionsTest {
private WebDriver driver;
private SHAFT.GUI.WebDriver shaftDriver;
private final String PACKAGE = "io.appium.android.apis";

@Test
public void scrollInExpandableLists_verticalScrolling_insideScreen(){
@Test(groups = {"Wizard"})
public void wizard_scrollInExpandableLists_verticalScrolling_insideScreen() {
((AndroidDriver) shaftDriver.getDriver()).runAppInBackground(Duration.ofSeconds(5));
shaftDriver.element().performTouchAction()
.swipeElementIntoView(AppiumBy.accessibilityId("Views"), TouchActions.SwipeDirection.DOWN)
.tap(AppiumBy.accessibilityId("Views"))
.swipeElementIntoView(AppiumBy.accessibilityId("Expandable Lists"), TouchActions.SwipeDirection.DOWN)
.tap(AppiumBy.accessibilityId("Expandable Lists"))
.swipeElementIntoView(AppiumBy.accessibilityId("3. Simple Adapter"), TouchActions.SwipeDirection.DOWN)
.tap(AppiumBy.accessibilityId("3. Simple Adapter"))
.swipeElementIntoView(By.xpath("//android.widget.TextView[@text='Group 18']"), TouchActions.SwipeDirection.DOWN)
.tap(By.xpath("//android.widget.TextView[@text='Group 18']"))
.swipeElementIntoView(By.xpath("//android.widget.TextView[@text='Child 13']"), TouchActions.SwipeDirection.DOWN)
.swipeElementIntoView(By.xpath("//android.widget.TextView[@text='Group 1']"), TouchActions.SwipeDirection.UP);
}

@BeforeMethod(onlyForGroups = {"Wizard"})
public void beforeMethod_wizard() {
// System.setProperty("targetOperatingSystem", "Android");
// System.setProperty("mobile_automationName", "UIAutomator2");
// System.setProperty("mobile_appWaitActivity", "*");
// System.setProperty("mobile_disableWindowAnimation", "true");
// System.setProperty("executionAddress", "0.0.0.0:4723");
// System.setProperty("mobile_app", System.getProperty("testDataFolderPath") + "apps/ApiDemos-debug.apk");

shaftDriver = new SHAFT.GUI.WebDriver();
}

@AfterMethod(onlyForGroups = {"Wizard"})
public void afterMethod_wizard() {
shaftDriver.quit();
}

@Test(groups = {"Legacy"})
public void scrollInExpandableLists_verticalScrolling_insideScreen() {
ElementActions.performTouchAction(driver)
.swipeElementIntoView(AppiumBy.accessibilityId("Views"), TouchActions.SwipeDirection.DOWN)
.tap(AppiumBy.accessibilityId("Views"))
Expand All @@ -32,7 +69,7 @@ public void scrollInExpandableLists_verticalScrolling_insideScreen(){
.swipeElementIntoView(By.xpath("//android.widget.TextView[@text='Group 1']"), TouchActions.SwipeDirection.UP);
}

@Test
@Test(groups = {"Legacy"})
public void scrollInExpandableLists_verticalScrolling_insideElement(){
ElementActions.performTouchAction(driver)
.swipeElementIntoView(AppiumBy.accessibilityId("Views"), TouchActions.SwipeDirection.DOWN)
Expand All @@ -45,7 +82,7 @@ public void scrollInExpandableLists_verticalScrolling_insideElement(){
.tap(By.xpath("//android.widget.ListView[2]/android.widget.TextView[@text='Abbaye de Belloc']"));
}

@Test
@Test(groups = {"Legacy"})
public void scrollInExpandableLists_verticalScrolling_insideElement2(){
ElementActions.performTouchAction(driver)
.swipeElementIntoView(AppiumBy.accessibilityId("Views"), TouchActions.SwipeDirection.DOWN)
Expand All @@ -58,7 +95,7 @@ public void scrollInExpandableLists_verticalScrolling_insideElement2(){
.tap(By.xpath("//android.widget.ListView[1]/android.widget.TextView[@text='Abbaye de Belloc']"));
}

@Test
@Test(groups = {"Legacy"})
public void scrollInExpandableLists_horizontalScrolling_insideElement(){
ElementActions.performTouchAction(driver)
.swipeElementIntoView(AppiumBy.accessibilityId("Views"), TouchActions.SwipeDirection.DOWN)
Expand All @@ -73,7 +110,7 @@ public void scrollInExpandableLists_horizontalScrolling_insideElement(){
.tap(By.xpath("//android.widget.HorizontalScrollView//android.widget.TextView[@text='TAB 1']"));
}

@Test
@Test(groups = {"Legacy"})
public void visualElementIdentification_samedpi() {
ElementActions.performTouchAction(driver)
.swipeElementIntoView("src/main/resources/dynamicObjectRepository/content.png", TouchActions.SwipeDirection.DOWN)
Expand All @@ -84,7 +121,7 @@ public void visualElementIdentification_samedpi() {
.perform();
}

// @Test
//@Test(groups = {"Legacy"})
public void visualElementIdentification_requiresProcessing() {
ElementActions.performTouchAction(driver)
.swipeElementIntoView("src/main/resources/dynamicObjectRepository/content2.png", TouchActions.SwipeDirection.DOWN)
Expand All @@ -95,7 +132,7 @@ public void visualElementIdentification_requiresProcessing() {
.perform();
}

@Test
@Test(groups = {"Legacy"})
public void testSendKeys() {
String SEARCH_ACTIVITY = ".app.SearchInvoke";
((AndroidDriver) driver).startActivity(new Activity(PACKAGE, SEARCH_ACTIVITY));
Expand All @@ -108,7 +145,7 @@ public void testSendKeys() {
.perform();
}

@Test
@Test(groups = {"Legacy"})
public void testOpensAlert() {
// Open the "Alert Dialog" activity of the android app
String ALERT_DIALOG_ACTIVITY = ".app.AlertDialogSamples";
Expand All @@ -129,15 +166,15 @@ public void testOpensAlert() {
}

@SuppressWarnings("CommentedOutCode")
@BeforeMethod
@BeforeMethod(onlyForGroups = {"Legacy"})
public void setup() {
// common attributes
// // common attributes
// System.setProperty("targetOperatingSystem", "Android");
// System.setProperty("mobile_automationName", "UIAutomator2");
// System.setProperty("mobile_appWaitActivity","*");
// System.setProperty("mobile_disableWindowAnimation","true");

// local appium server (for local and github actions execution)
//
// // local appium server (for local and github actions execution)
// System.setProperty("executionAddress", "0.0.0.0:4723");
// System.setProperty("mobile_app", System.getProperty("testDataFolderPath")+"apps/ApiDemos-debug.apk");
driver = DriverFactory.getDriver();
Expand All @@ -160,7 +197,7 @@ public void setup() {
// driver = DriverFactory.getDriver();
}

@AfterMethod
@AfterMethod(onlyForGroups = {"Legacy"})
public void teardown() {
DriverFactory.closeAllDrivers();
}
Expand Down

0 comments on commit 9af7622

Please sign in to comment.