Skip to content

Commit

Permalink
updated test script with structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahbub091 committed Aug 16, 2023
1 parent 003cb04 commit 83fa9cf
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 85 deletions.
Binary file removed apps/MyDemoAppRN.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion src/test/java/BaseConfig/SettingAndroidEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AndroidDriver setup() throws MalformedURLException {
options.setPlatformName("android");
options.setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2);
options.setDeviceName("Google Pixel 6");
options.setApp(System.getProperty("user.dir") + "/apps/MyDemoAppRN.apk");
options.setApp(System.getProperty("user.dir") + "/apps/ApiDemos.apk");

driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), options);

Expand Down
55 changes: 0 additions & 55 deletions src/test/java/PageManagement/HomePage.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/test/java/TestCases/AndroidTestAutomation.java

This file was deleted.

13 changes: 4 additions & 9 deletions src/test/java/Utility/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package Utility;
package android.Utility;

import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.WebDriver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
Expand All @@ -11,15 +10,14 @@
import java.time.Duration;

public class TestUtils {

WebDriver driver;
Logger log = LogManager.getLogger("TestUtils");


public TestUtils(WebDriver driver) {
this.driver = driver;
}

public void wait(int seconds) {
log.info("Test Paused : [{}] Seconds", seconds);
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
Expand All @@ -36,7 +34,6 @@ public void assertText(WebElement locator, String text){
}

public void clickingOnElement(WebElement element) {
log.info("Clicking On Element: [{}]", element);
try {
element.click();
} catch (Exception e) {
Expand All @@ -45,13 +42,11 @@ public void clickingOnElement(WebElement element) {
}

public void elementIsDisplayed(WebElement element, long seconds) {
log.info("Waiting for [{}] seconds on Visibility of [{}]", seconds, element);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(seconds));
wait.until(ExpectedConditions.visibilityOf(element));
}

public void verifyText(WebElement element, String text) {
log.info("Fetching text from [{}] & verifying [{}]", element, text);
element.getText().equalsIgnoreCase(text);
Assert.assertEquals(element.getText(), text);
}
Expand Down
74 changes: 74 additions & 0 deletions src/test/java/android/PageObject/HomePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package android.PageManagement;

import BaseConfig.SettingAndroidEnv;
import android.Utility.TestUtils;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class HomePage extends SettingAndroidEnv {
int pause_Short = 1;
int pause_long = 2;
int pause_extended = 3;

WebDriver driver;

public static AndroidDriver andro;

TestUtils testUtils;

public HomePage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
testUtils = new TestUtils(driver);
}

/**
* Our Elements Will Be Stored Here.
*/

@FindBy(xpath = "(//android.widget.ImageView) [5]")
WebElement tshirtBox;

@FindBy(xpath = "(//android.widget.TextView) [1]")
WebElement tshirtText;

@FindBy(xpath = "//android.view.ViewGroup[@content-desc='open menu']/android.widget.ImageView")
WebElement menuButton;

@FindBy(linkText = "Catalog")
WebElement webviewMenu;

@iOSXCUITFindBy(accessibility = "messageSaveBtn")
@AndroidFindBy(xpath = "//android.view.ViewGroup[@content-desc='messageSaveBtn']")




public void clickingOnAppElement(){
testUtils.elementIsDisplayed(tshirtBox, 60);
testUtils.clickingOnElement(tshirtBox);
testUtils.wait(1);
testUtils.verifyText(tshirtText, "Sauce Labs Backpack");

}

public void menu() {
testUtils.elementIsDisplayed(menuButton, 60);
testUtils.wait(pause_Short);
testUtils.clickingOnElement(menuButton);
testUtils.wait(pause_Short);
testUtils.clickingOnElement(menuButton);
testUtils.wait(pause_Short);
driver.findElement(AppiumBy.accessibilityId("longpress reset app")).isDisplayed();
driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector()).click(text());"));
andro.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
}
}
46 changes: 46 additions & 0 deletions src/test/java/android/TestCases/AndroidTestAutomation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package TestCases;

import BaseConfig.SettingAndroidEnv;
import Utility.TestUtils;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import org.openqa.selenium.By;
import org.testng.annotations.Test;

public class AndroidTestAutomation extends SettingAndroidEnv {

@Test (testName = "Test01", description = " Android App Automation")
public void test01() {
TestUtils test = new TestUtils(driver);
test.wait(1);
String title = driver.findElements(By.xpath("//android.widget.TextView [1]")).get(0).getText();
System.out.println(title);
driver.findElement(By.id("android:id/text1")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK)); //Navigate back from current screen
test.wait(1);
driver.findElement(By.xpath("//android.widget.TextView[@text='Animation']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='App']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='Content']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='Graphics']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='Media']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='NFC']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='OS']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='Preference']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='Text']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
driver.findElement(By.xpath("//android.widget.TextView[@text='Views']")).click();
driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));


}
}

0 comments on commit 83fa9cf

Please sign in to comment.