Skip to main content

First Appium Test to Launch Amazon App

First Appium Test to Launch Amazon App. This will include following steps:
  • Launch Appium Node server
  • Create your first test script
  • Execute your first test

Launch Appium Node Server

1) I am expecting that your Appium window is already opened on your machine. If you have restarted your system then please start Appium by navigate to Appium directory in your system and start Appium by double clicking Appium.exe file.
Appium_1
  1. Android Icon is for Configuration settings
  2. Settings Icon is for General Settings
  3. Play Icon is for Starting Node server

2) Click on Android icon to open the configuration of the Appium run. There you need to select the check box of ‘No Reset‘. This will ensure that the Appium will not install or uninstall App on every run.
Appium_2

3) Click on General Setting icon and make sure that Server Address and Port is populated.
Appium_4
Note: Do not alter the IP address or port number. Your Appium console start at 127.0.0.1:4723 as shown in below.

4) Now its time to start the Appium server, juct click on the Launch Appium Node Server button on the top right corner ofAppium window and wait for few seconds. Appium server started and running on your system.
Appium_3

Run The First Test

Now you are all set to write your first test script. Create a small test Program for opening a Amazon application on your device using Appium.
1) Copy & paste the below code to your StartApplication class and give it a run.

2) Do no get in to details for now and simply run the test. To start the test just select Run > Run As > Java Application OrRight Click on Eclipse code and Click Run As  > Java Application.
3) After a few Seconds, you will see that with the help of your script, Amazon application will be launched on your device. Once the execution is finished, you will see a long list of messages on the Appium console.We will come back to these messages later.

Code Explanation

Lets now discuss what each line of code means in the above test. I hope you are enjoying your journey of learning Appium.

Import libraries statements

// Llibrary for Appium drivers
import io.appium.java_client.android.AndroidDriver;
// Library to create the path to APK
import java.io.File;
// Library used to verify if URL is malformed
import java.net.MalformedURLException;
// Library used to create URL for the Appium server
import java.net.URL;
// Libraries for configuring Desired Capabilities
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

Path to APK file

Since the Amazon app apk is stored in the computer and is not already installed on the device we need to create a file object which represents the actual apk file on the disk. I placed the folder ‘/Apps/Amazon/‘ which contains the apk file inside the Eclipse project.
// Path to Eclipse project
File classpathRoot = new File(System.getProperty(“user.dir”));
// Path to <project folder>/Apps -> Amazon
File appDir = new File(classpathRoot, “/Apps/Amazon/”);
// Path to <project folder>/Apps -> Amazon/Amozon apk file
File app = new File(appDir, “in.amazon.mShop.android.shopping.apk”);

Desired Capabilities

To be able to test the app on an actual device Desired Capabilities need to be set. Desired Capabilities are a set of keys and values sent to the Appium server to tell the server what kind of automation session we’re interested in starting up. There are also capabilities used to modify the behavior of the server during automation.
// To create an object of Desired Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
// Name of mobile web browser to automate. It should be an empty string, as we are automation an app
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
// Name of the OS: Android, iOS or FirefoxOS
capabilities.setCapability(“platformName”, “Android”);
// Mobile OS version –  My device is running Android 4.4.2
capabilities.setCapability(CapabilityType.VERSION, “4.4.2”);
// Device name:  – I am using Micromax A311
capabilities.setCapability(“deviceName”, “Micromax A311″);
// An absolute local path to the APK file
capabilities.setCapability(“app”, app.getAbsolutePath());
// Java package of the tested Android app
capabilities.setCapability(“appPackage”, “in.amazon.mShop.android.shopping”);
// An activity name for the Android activity you want to run from your package.
capabilities.setCapability(“appActivity”, “com.amazon.mShop.home.HomeActivity”);
// Constructor to initialize driver object with new Url and Capabilities
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);

Comments

Popular posts from this blog

JMeter Exceeded Maximum Number of Redirects Error Solution

While running performance test, JMeter allows maximum 5 redirects by default. However, if your system demands more than 5 redirects, it may result in JMeter exceeded maximum number of redirects error. In this post, we have listed down steps to overcome this error. Actual error in JMeter: Response code: “Non HTTP response code: java.io.IOException” Response message: “Non HTTP response message: Exceeded maximum number of redirects: 5” This error is noticed because  JMeter  allows maximum 5 redirects by default and your system may be using more than 5 redirects. You need to increase this count to more than 5 in jmeter.properties file. Follow below steps to achieve this. Navigate to /bin directory of your JMeter installation. Locate jmeter.properties file and open it in any editor. Search for “httpsampler.max_redirects” property in opened file. Uncomment the above property by removing # before it. Change to value to more than 5 Eg. 20. Save the file and restart JMet...

SSO with SAML login scenario in JMeter

SAML(Security Assertion Markup Language) is increasingly being used to perform single sign-on(SSO) operations. As WikiPedia puts it, SAML is an XML-based open standard data format for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. With the rise in use of SAML in web applications, we may need to handle this in JMeter. This step-by-step tutorial shows SAML JMeter scenario to perform login operation. First request from JMeter is a GET request to fetch Login page. We need to fetch two values ‘SAMLRequest’ and ‘RelayState’ from the Login page response data. We can do this by using  Regular Expression Extractor . These two values need to be sent in POST request to service provider. Refer below image to see how to do this. We will get an HTML login page as a response to the request sent in 1st step. We need to fetch values of some hidden elements to pass it in the next request. We...

VBScript Code - Function to convert CSV file into excel and viceversa in QTP using VBScript

We at times are required to convert excel files into csv to read as flat files and sometime require to convert a csv file into excel file to use excel features on the data.   Below function shows how to convert an csv file into excel file and vice versa. We can also convert to other formats based on constants Here constant value 23 is used to create a csv file and constant -4143 to save a file as xls file. Once the destination file is created, we can delete the source file as shown below.  In case of any issue in understanding the code, please add in comment section Call func_ConversionCSVExcel("E:\Test.csv", "E:\Test_converted.xls", "csvtoexcel") Public Function func_ConversionCSVExcel(strSrcFile, strDestFile, Conversion) on error resume next Set objExcel = CreateObject("Excel.application") set objExcelBook = objExcel.Workbooks.Open(strSrcFile) objExcel.application.visible=false objExcel.application.displayalerts=...