Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
First Appium Test Java
package rightqa.appiumAndroidDemo;
//This is a Library for Appium Android driver
import io.appium.java_client.android.AndroidDriver;
//This is a Library to create path to the application under test (APK)
import java.io.File;
//This is a Library to verify if the URL is malformed
import java.net.MalformedURLException;
//This is a Library to create a URL for the Appium Server
import java.net.URL;
//This is a Library to configure Desired Capabilities
import org.openqa.selenium.remote.DesiredCapabilities;
public class FirstAppiumTest {
protected static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
//Path to Eclipe Project
File classpathRoot = new File(System.getProperty("user.dir"));
//This will get the path to the apps folder that holds the application under test (APK)
File appDir = new File(classpathRoot, "/apps/");
//This will get the full path to the apk file
File app = new File(appDir, "api.apk");
//Create an object for Desired Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
//These are mandatory capabilities that define the device name and platform name. Platform name could be iOS, Android or FirefoxOS
capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformName","Android");
//Some other capabilities that gets the actual app
capabilities.setCapability("app", app.getAbsolutePath());
//Initialize the driver object with the URL to Appium Server and passing the capabilities
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
//Just added wait so that you can see the actual app loaded in the emulator
Thread.sleep(5000);
//Quitting the driver session
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.