Udemy: Use of appium in base and derived class

Jar dependencies:
Java Client 6.1.0 or 7.0.0
Appium Server 1.9 or 1.10
Selenium 3.141.0
Java jdk version 1.8
commons-lang3-3.7.jar

Base Class:
---------------------------------------------------
package com.udemy.query;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;



public class Base {

static AndroidDriver<MobileElement> driver;
static DesiredCapabilities cap = new DesiredCapabilities();
public static AndroidDriver<MobileElement> setcapabilites() throws MalformedURLException
{
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "0797818a87d4f5cb");
cap.setCapability(MobileCapabilityType.VERSION, "5.0");
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

              cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis");
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".ApiDemos");
        
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
return driver;
}
}

====================================================

Derived class
---------------------------------------
package com.udemy.query;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidTouchAction;
import io.appium.java_client.android.Connection;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;

import java.net.MalformedURLException;
import java.time.Duration;
import java.util.List;
import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class derived extends Base {

public static void main(String[] args) throws MalformedURLException {
AndroidDriver<MobileElement> driver = setcapabilites();
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"Views\").instance(0))");

driver.findElement(By.xPath("//android.widget.TextView[@text='Preference']")).click();
}

}

Comments

Post a Comment

Popular posts from this blog

[Android] How to perform parallel testing in Appium using Selenium Grid.

Install and Invoke App.

How to execute appium scripts in could (Saucelabs)