Created
July 27, 2015 03:27
-
-
Save anonymous/89de52e0339bc28c25a4 to your computer and use it in GitHub Desktop.
First Appium Test Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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