0% found this document useful (0 votes)
30 views11 pages

Appium Tutorials Can Be Found On: Java - Home

The document provides steps to set up an Android development environment and configure an Android device for testing with Appium. It also outlines how to download and install Appium, start the Appium server, deploy apps, and write sample test code to launch apps and webpages on an Android device.

Uploaded by

adiall4u
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views11 pages

Appium Tutorials Can Be Found On: Java - Home

The document provides steps to set up an Android development environment and configure an Android device for testing with Appium. It also outlines how to download and install Appium, start the Appium server, deploy apps, and write sample test code to launch apps and webpages on an Android device.

Uploaded by

adiall4u
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Appium Tutorials can be found on www.way2automation.

com

Initial Android installation:


1. JAVA_HOME configured
2. Download ANDROIDSTUDIO
[Link]
3.

Environment variable setup for ANDROID_HOME


a. VARIABLE NAME: ANDROID_HOME
b. VARIABLE VALUE: C:\Users\Selenium\AppData\Local\Android\sdk
PATH: %ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

c. Open CMD and type: android


d. Inside AVD Manager Select the Tools checkbox.
e. Select the checkbox for the latest Android SDK, Android 6.0 Android 4.4.2 (API
Level 19) as of this writing.
f. From the Extras folder, select the checkbox for the Android Support Library.
g. Click the Install packages button to complete the download and installation.

[Link]

[Link]

CONFIGURING ANDROID DEVICE


Connect the Device to a Genuine USB cable and make sure drivers are installed
completely on your Desktop / Laptop
In some cases if the drivers are not fully installed follow these troubleshooting
steps:
[Link]

Once the drivers are fully installed and your machine is able to detect your device
Go to Settings -> General and look for the option Developer Options

[Link]

If you dont see the Developer Option go to About Device and tap 6 times on Build Number

Go to Developer Options and check USB Debugging and Stay awake


options (Make sure to turn off Stay awake once done with the
testing

[Link]

Go to Command Prompt and type adb devices and make sure you
see your device id

[Link]

DOWNLOAD APPIUM
Appium comes in 2 parts
1. GUI Tool
[Link]

2. Java client (API)


[Link]

Maven Dependency
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>java-client</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>

[Link]

JAVA Document path

[Link]
STARTING APPIUM SERVER
1: Through Appium App:

2: Through Command Prompt:


Navigate to the bin folder in command prompt where Appium is installed C:\Program Files
(x86)\Appium\node_modules\appium\bin

3: Through Java Code:


AppiumDriverLocalService service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("c:/Program
Files/nodejs/[Link]"))
.withAppiumJS(new File("C:/Program Files
(x86)/Appium/node_modules/appium/bin/[Link]"))
.withLogFile(new
File("c:/appiumlogs/[Link]")));
[Link]();
//To stop the services
[Link]();
[Link]

DEPLOYING APPS
1: Through Appium App
a) Get the capabilities from Android Settings

b) Check the Pre-launch under general settings and hit RUN while the device is
connected

2: Deploying APK files through code


File app = new File("C:\\Users\\Selenium\\Downloads\\[Link]");
DesiredCapabilities capabilities = new
DesiredCapabilities();
[Link](CapabilityType.BROWSER_NAME,
"");
[Link]("device", "Android");
[Link]

[Link]("deviceName", "Galaxy
Note3");
[Link]("platformVersion", "5.0");
[Link]("platformName","Android");
[Link]("app",
[Link]());

3: Launching already deployed app through Java code


DesiredCapabilities capabilities = new DesiredCapabilities();
[Link](CapabilityType.BROWSER_NAME,
"");
[Link]("device", "Android");
[Link]("deviceName", "Galaxy
Note3");
[Link]("platformVersion", "5.0");
[Link]("platformName","Android");
//Give the App package and Activity info to launch the already
//installed app
[Link]("appPackage",
"[Link]");
[Link]("appActivity",
"[Link]");

[Link]

Basic Test for Launching WebApp on Chrome Browser


public class BasicWebAppTest {
public static AndroidDriver<MobileElement> driver;
public static void main(String[] args) throws
MalformedURLException, InterruptedException {
AppiumDriverLocalService service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("c:/Program
Files/nodejs/[Link]"))
.withAppiumJS(new File("C:/Program Files
(x86)/Appium/node_modules/appium/bin/[Link]"))
.withLogFile(new
File("c:/appiumlogs/[Link]")));
[Link]();
DesiredCapabilities capabilities = new
DesiredCapabilities();
[Link](CapabilityType.BROWSER_NAME,
"Chrome");
[Link]("device", "Android");
[Link]("deviceName", "Galaxy Note3");
[Link]("platformVersion", "5.0");
[Link]("platformName","Android");
driver = new AndroidDriver<MobileElement>(new
URL("[Link] capabilities);
[Link]().timeouts().implicitlyWait(20L,
[Link]);
[Link]().to("[Link]
[Link]([Link]());

[Link](3000);

[Link]();
[Link]();
}
}

[Link]

Basic Test for Launching Native / Hybrid App on a Real Device /


Emulator when app is already installed
DesiredCapabilities capabilities = new DesiredCapabilities();
[Link](CapabilityType.BROWSER_NAME,
"");
[Link]("device", "Android");
[Link]("deviceName", "Galaxy
Note3");
[Link]("platformVersion", "5.0");
[Link]("platformName","Android");
//Give Package Name and Launchable Activity of the APK
file
[Link]("appPackage",
"[Link]");
[Link]("appActivity",
"[Link]");
driver = new AndroidDriver<MobileElement>(new
URL("[Link] capabilities);
[Link]().timeouts().implicitlyWait(20L,
[Link]);

[Link]

Common questions

Powered by AI

To start the Appium server using Java code, utilize the AppiumDriverLocalService class. Build the service by providing the node executable location and the appium.js path using AppiumServiceBuilder. Set a log file for the service logs. The service is then started by calling service.start(). Here is a sample code snippet: ``` AppiumDriverLocalService service = AppiumDriverLocalService .buildService(new AppiumServiceBuilder() .usingDriverExecutable(new File("c:/Program Files/nodejs/node.exe")) .withAppiumJS(new File("C:/Program Files (x86)/Appium/node_modules/appium/bin/appium.js")) .withLogFile(new File("c:/appiumlogs/logs.txt"))); service.start(); ``` .

To launch an already deployed app using Appium and Java, set the DesiredCapabilities including BROWSER_NAME as an empty string, device as 'Android', deviceName as 'Galaxy Note3', platformVersion as '5.0', platformName as 'Android'. Provide the package name and launchable activity of the app with capabilities.setCapability('appPackage', 'com.whatsapp') and capabilities.setCapability('appActivity', 'com.whatsapp.Main'). Use these capabilities to initialize the AndroidDriver and navigate as required .

Ensure your Android device is properly recognized by connecting it through a genuine USB cable. Install the necessary USB drivers. If the device isn't detected, follow troubleshooting guidelines to set up ADB USB drivers. Enable 'Developer Options' by tapping the build number in 'About Device' and then enable 'USB Debugging'. Verify recognition by typing 'adb devices' in the command prompt to check if the device ID is displayed .

To deploy an APK file through Appium on a Galaxy Note3, set the following DesiredCapabilities: BROWSER_NAME as an empty string, device as 'Android', deviceName as 'Galaxy Note3', platformVersion as '5.0', platformName as 'Android', and specify the app using capabilities.setCapability('app', app.getAbsolutePath()), where 'app' is a File object of the APK path .

To set up the Android environment for Appium on a Windows machine, you need to configure JAVA_HOME and download Android Studio from the official website. Set the environment variable for ANDROID_HOME with the variable name 'ANDROID_HOME' and the path set to your Android SDK location, typically 'C:\Users\Selenium\AppData\Local\Android\sdk'. Include the paths '%ANDROID_HOME%\tools' and '%ANDROID_HOME%\platform-tools' in the system PATH variable. Finally, install the latest Android SDK and support libraries through the SDK Manager within Android Studio .

To download and install the Appium GUI tool, visit the official Appium website appium.io and download the tool for your platform. Follow standard installation steps for your operating system to set up the graphical interface, which facilitates the creation and management of Appium testing sessions without requiring command-line operations .

Configuring 'developer options' is crucial for enabling USB Debugging, which allows communication between the Android device and development machine for Appium automated testing. It is accessed by tapping the build number in 'About Device' multiple times to unlock 'Developer Options', where USB Debugging can be activated .

Verify if an Android device is ready by connecting it, checking that 'USB Debugging' is enabled in Developer Options, and using the command 'adb devices' in the command prompt. If your device ID appears in the list, it indicates that the device is correctly recognized and ready for automated testing .

When setting up Appium for a web application test, the BROWSER_NAME capability is set to 'Chrome', while for a native app, it remains empty. For web tests, often ChromeDriver is configured, and URL navigation is performed. In contrast, for native apps, you require package and activity name for app interaction. Testing a web app involves opening a URL in a browser, whereas native app testing involves interacting with the installed app's UI .

To integrate Appium in a Java project, the following Maven dependencies are required: ``` <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>LATEST</version> </dependency> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>LATEST</version> </dependency> ``` These dependencies provide support for Selenium and Appium client libraries in Java .

You might also like