Skip to content

Instantly share code, notes, and snippets.

@Tarek-O
Created July 6, 2022 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tarek-O/81552f455712c9e2ecc58e37aab7ad81 to your computer and use it in GitHub Desktop.
Save Tarek-O/81552f455712c9e2ecc58e37aab7ad81 to your computer and use it in GitHub Desktop.
package pageObjects;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import util.hook;
public class explorePage {
public explorePage() {
PageFactory.initElements(new AppiumFieldDecorator(hook.getDriver()), this);
}
@AndroidFindBy(xpath = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/androidx.cardview.widget.CardView/android.view.ViewGroup/android.widget.TextView")
public WebElement loginButton;
public WebElement getLoginButton() {
return hook.getDriver().findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/androidx.cardview.widget.CardView/android.view.ViewGroup/android.widget.TextView"));
}
}
package util;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.cucumber.java.After;
import io.cucumber.java.Before;
public class hook {
private static WebDriver driver;
@Before
public void setUpAndroidAppium() throws MalformedURLException{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
cap.setCapability("fullReset", false);
cap.setCapability("automationName", "UiAutomator2");
//cap.setCapability("appWaitActivity", "");
cap.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir")+"//App//FILENAME.apk");
driver = new AndroidDriver<WebElement>(new URL("http://0.0.0.0:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@After
public void tearDown()
{
driver.quit();
}
public static WebDriver getDriver()
{
return driver;
}
}
package stepDefinitions;
import org.openqa.selenium.WebDriver;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import pageObjects.explorePage;
import pageObjects.onBoardingPage;
import util.hook;
public class testDef {
private WebDriver driver;
public explorePage explorePage = new explorePage();
public onBoardingPage onBoardingPage = new onBoardingPage();
public testDef() {
this.driver = hook.getDriver();
}
@Given("the Login button is clicked from the Dashboard")
public void the_login_button_is_clicked_from_the_dashboard() {
//WebElement englishBtn = onBoardingPage.onBoardingEnglish;
//assertTrue(englishBtn.isDisplayed());
//englishBtn.click();
onBoardingPage.selectEnglish();
}
@When("a valid mobile line {int} and password {string} is submitted")
public void a_valid_mobile_line_and_password_is_submitted(Integer int1, String string) {
// Write code here that turns the phrase above into concrete actions
}
@Then("the user should be successfully logged in")
public void the_user_should_be_successfully_logged_in() {
// Write code here that turns the phrase above into concrete actions
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment