About WebDriver - WebDriver is a web automation framework that allows to execute test scripts on desktop and mobile browsers.
If you are considering to test mobile apps, then the correct solution is Appium.
About Appium - Appium is an open source automation tool which can automate web, native and hybrid mobile apps on iOS, Android and FirefoxOS platforms.
It uses the WebDriver JSON wire protocol to drives the Android UI Automator framework.
Appium's Benefits-
1. It can automate web, hybrid and native mobile apps.
2. It allows us to write test cases in any programming language (like java, c#, ruby etc) using Selenium WebDriver.
3. The other benefits of Appium is that it is cross- platform test automation tool for mobile apps which means the same test cases would work on multiple platforms.
Getting started with Appium drives on Real Android Device--
Pre-requisites--
1. Appium for Windows (download)
2. Android SDK (download)
3. JDK (download)
4. Eclipse (download)
5. TestNG (download)
6. Appium client library (download)
3. JDK (download)
4. Eclipse (download)
5. TestNG (download)
6. Appium client library (download)
7. Selenium Server jar (download)
8. WebDriver client library (download)
9. Apk info- Users need to install the same app. in android mobile to get the package and activity info of the apps.(download)
Apk Info |
Step 1- Setting up the Android SDK on Windows
a. Open System properties window by pressing window-key +Pause or right click on My Computer and click properties.
b. Click on 'Advanced system settings'
c. Click on 'Environment Variables'
d. Set ANDROID_HOME as shown in above figure.
e. In the 'System variables' find 'Path' and then double click on it.
f. In the 'variable value' text box, add the new path 'C:\Users\dell\android-sdks\platform-tools'.Just be sure that there is a semi-colon separating this new entry from the preexisting values.
g. Now click ok button of all boxes.
Now start android server using "adb start-server" from command prompt.
Step 2- Connect your Android device with the PC and make sure device Developer options is 'ON' and also USB debugging mode is checked as shown in below picture.
Developer options |
Step 3- Upzip downloaded AppiumForWindows.zip, the folder contains Appium.exe, run it by double clicking, it will look like-
Appium v1.4.16
No need to change the IP address and port number.
Now, click on Launch button then Appium Server will start at 127.0.0.1:4723 as shown in below picture.
Step 4- Here i am taking a example of Android native app Calculator.
Now, click on Launch button then Appium Server will start at 127.0.0.1:4723 as shown in below picture.
Appium Server Started
Step 4- Here i am taking a example of Android native app Calculator.
Calculator |
Step 5- Writing test scripts for Calculator using java, WebDriver and TestNG unit framework.
package com;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;
public class CalculatorTest {
AppiumDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.4");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"TA64301YDK");
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.android.calculator2"); // This is package name of your app (you can get it from apk info app
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create AndroidDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCal(){
//locate the Text on the calculator by using By.name()
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
//locate the edit box of the calculator by using By.className()
WebElement results=driver.findElement(By.className("android.widget.EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
}
@AfterClass
public void teardown(){
//close the app
driver.closeApp();
}
}
package com;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;
public class CalculatorTest {
AppiumDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.4");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"TA64301YDK");
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.android.calculator2"); // This is package name of your app (you can get it from apk info app
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create AndroidDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCal(){
//locate the Text on the calculator by using By.name()
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
//locate the edit box of the calculator by using By.className()
WebElement results=driver.findElement(By.className("android.widget.EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
}
@AfterClass
public void teardown(){
//close the app
driver.closeApp();
}
}
Great to see you started blogging. Hoping to see more posts in future.
ReplyDeleteAjoy
Testing Circus Magazine
Thx Ajoy..:)
ReplyDeleteDefinitely you will see more posts in future.
I am getting error A session is either terminated or not started (Original error: Could not find adb; do you have android SDK installed?) I have already installed Android sdk
ReplyDeletedid u follow the first step??
DeleteHwy hi buddy,
ReplyDeleteits really worth and it really helped me a lot.
Am able to lunch the app and automate using emulator but not in real device, I have Samsung S3, android version 4.1.2.
After running the command adb devices from cmd my device is not detected.
And how can I launch an inspecter so that I can record.
Thanks,
Mahesh M
follow step 2 and again hit the adb devices from cmd and about inspect the elements you can use UIAutomatorviewer.
DeleteThanks Manoj, yeah am using UIAutomatorviewer to inspect elements as am not able to launch inspector, but now how to i use swipe ?
ReplyDeleteCan you please provide video
ReplyDeleteI will think about it but for a time being u can follow above steps. if you have any doubts then do let me know.
DeleteHi Manoj,
ReplyDeleteI tried with the below code to flick from top to bottom but it dint work, can you help me out to flick from top to bottom, bottom to top, right to left and left to right :
WebElement el = driver.findElement(By.xpath("//TextView[@text='Caste']"));
TouchActions flick = new TouchActions(driver).flick( el, -50, 0, 0 );
flick.perform();
no need to pass webelement for flicking.
Deletetry below code to flick from top to bottom...
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap flickObject = new HashMap();
flickObject.put("endX",0);
flickObject.put("endY", 0);
flickObject.put("touchCount", 1);
js.executeScript("mobile: flick", flickObject);
Hey thanks Manoj, it worked for me.
DeleteIf i want flick from right to left?
Manoj say if i want to automate for ios apps, then should I have mac notebook, cant I implement using windows machine if I have iphone device ?
DeleteManoj??...btw he's very much right on the same.
DeleteHi manoj its gr8 work by you..its very usefull post for me...
ReplyDeleteThanks a lot..
@Manoj : In one of our android app , i found that under Activity , there are multiple entries , in the case how i will pass these multiple information in the below code
ReplyDeletecapabilities.setCapability("app-activity", "com.android.calculator2.Calculator");
will i use comma or any other wayout
2 another doubt is , when we test web application using firebug we can track the id , name or xapth from firebug but in case of mobile app how i will get that information .
please help
@Neil-- 1. No need to set multiple app-activity in capabilities.app-activity is all about to open desire page.
DeleteFor ex-- In Facebook application there are lot of pages, every pages has its own app-activity.If you are going to automate the Facebook app then you only need to open the login page of the same application.(you will get the app-activity of login page as 'com.facebook.katana.LoginActivity')
2. You can use UIAutomatorviewer for finding the elements.
Great work buddy..!!
ReplyDeleteThxx Tamil..:)
DeleteHi, I m getting error as:
ReplyDeletejava.lang.NoClassDefFoundError: com/google/common/base/Function
at CalculatorTest.setUp(CalculatorTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 25 more
Hi Sarvesh, It seems u missed some jar file.As per my understanding add commons-collections.jar or google-collections.jar to remove the same error.
DeleteHi manoj,
ReplyDeleteThe emulator is not opening for me. And does the program have a main method? I used it as
public static void main(String args[])
{
androidExample andexample=new androidExample();
try
{
androidExample.setup();
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
After this, i started the Appium server and then ran this program, I am getting the error as, could not find any connected device and finally the error is device did not become ready? Can u please help me with the problem?
Hi Viji,
DeleteThe above blog is for real device but if you want to run it on emulator then you need to add one more capability ie 'app'.
Hi Viji,
DeleteIn that case, what you can do is, use AVD in eclipse and start the emulator. After that start the Appium server and then run your tests. It will find the emulator and run your tests. As Appium internally used ADB to find which is the connected device or emulator
hi manoj,
ReplyDeleteIt was really a good post and I was able to execute native application.The steps are very simple and slf explanatory . Now I wanted to start with hybrid application .
Can you pls let me know what is the set up required . I have gone through the appium website but I am not getting how to use 'Get' and 'Post' command which they have mentioned to view the web view section ..
It would be a grt a help if you could give a sample code to start with or any relative reference so that I start .
Thanks alot...
Hi Vishal,
DeleteI never tried with hybrid app if i find any good blog related to it then definitely i will let u know.
Do let me know
Deletethanks :)
I have successfully configured the android webdriver into the emulator and launched the justdail.com(mobile version) into the emulator. My doubt is after this, how to get the web elements id to test this application and how to proceed further ??? Plz reply me..
ReplyDeleteYou can use UIAutomatorviewer for finding the elements
DeleteThanks for good tutorial ...
ReplyDeleteHi Manoj,
ReplyDeleteThis was really very helpful..I could successfully run the application.Thanks for your post. How can i run the same code on IPHONE ? Please reply.
sorry Vinil, I dont have any idea about IPHONE.
DeleteHI Manoj, Really Great work and helpfull; Thanks
ReplyDeleteHi Manoj,
ReplyDeletei am running your script on my device: Nexus5, version 4.4.2.
Code which i used in before class is:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.4");
capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
capabilities.setCapability("app-package", "com.android.calculator2");
capabilities.setCapability("app-wait-activity", "com.android.calculator2");
capabilities.setCapability("app-activity","com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
But it gets failed, Error which i found under console :
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: A valid device type is required in the capabilities list) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 187 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'Admin-PC', ip: '192.168.1.14', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_41'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at CalculatorTest.setUp(CalculatorTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.run(TestNG.java:1036)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Hi Manoj,
ReplyDeleteThanks for your gracious contribution in this regard.
I tried to follow all the steps as you specified above but getting the following error
Error on eclipse console:
[TestNG] Running:
C:\Users\shweta.kawale\AppData\Local\Temp\testng-eclipse-1071858844\testng-customsuite.xml
FAILED CONFIGURATION: @BeforeMethod setUp
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 602.26 seconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'PNEITSH51025LT', ip: '14.97.212.121', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Desired Capabilities I set are:
File appDir = new File("C:\\APPIUM");
File app = new File(appDir, "com.android.calculator2_1.0.0.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.2.1");
capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
capabilities.setCapability("app-package", "com.android.calculator2"); // This is package name of your app (you can get it from apk info app)
capabilities.setCapability("app-activity", "com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create RemoteWebDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
capabilities.setCapability("app", app.getAbsolutePath());
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Error Log:
Where as my device get detected by manual command prompt adb command, Appium server is unable to find device connected.
Please guide me how should I get rid of this error.
Hi Manoj,
ReplyDeleteIts really a good stuff..
I have followed all steps and I have copy pasted same script in to eclipse
Code:
package com;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class testclass {
WebDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.3");
capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
capabilities.setCapability("app-package", "com.sec.android.app.popupcalculator"); // This is package name of your app (you can get it from apk info app)
capabilities.setCapability("app-activity", "com.sec.android.app.popupcalculator.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create RemoteWebDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCal(){
//locate the Text on the calculator by using By.name()
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
//locate the edit box of the calculator by using By.tagName()
WebElement results=driver.findElement(By.tagName("EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
}
@AfterClass
public void teardown(){
//close the app
driver.quit();
}
}
And I’m getting error message with appium, Can u please help me to fix this.
I have a strong feeling that there is something wrong with the lines of code
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.3");
capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
Hi Manoj,
ReplyDeleteThis was one of the good stuff u have posted. I have followed the same steps which was mentioned by you. Getting some error Kindly help me to clear the issue
FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: A valid device type is required in the capabilities list) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 149 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'che-19061L', ip: '10.181.202.49', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at com.CalculatorTest.setUp(CalculatorTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
I have updated the code as per the latest appium version, give it try again.
DeleteHi,
ReplyDeleteI get this error, Any suggestions?
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: A valid device type is required in the capabilities list) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 213 milliseconds
Build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38'
System info: host: 'evyatar-PC', ip: '192.168.1.78', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at com.eviltester.webdriver.CalculatorTest.setUp(CalculatorTest.java:29)
Appium developers made some changes in 1.0 version so i have updated the code, use this updated code.
DeleteGreat work man !!
ReplyDeleteI am trying on windows machine to execute Android calculator on emulator. But I am getting below error. Please help me dude.
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: too many files specified; only takes APK file and verifier file
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 8.10 seconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'Admin-PC', ip: '192.168.10.75', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Hi Manoj,
ReplyDeleteGreat post.
I am new to mobile testing. I have task to do the app testing on iphone and ipod using selenium webdriver(java).
Could you please share the same demo as android for iOS.
Hi Syam...you can take a look http://assertselenium.com/2013/01/17/appium-for-automating-native-ios-apps/ url for iOS automation using Appium.
DeleteHi Manoj Hans,
ReplyDeletethanks for the nice post :)
I tried to run on sample webdriver test with an android emulator
- my emulator is started
- cmd -> adb devices (I see the device)
-> when I run the code I will get an error output on appium nodejs console like this
"Could not find devices, restarting adb server..."
"ERROR: executing C:\...\adb.exe"
when I try to open adb.exe manually it works,
I set all system variables
I have no idea why I can not find my emulator
thanks in advance,
Best Michael
Hi Manoj,
ReplyDeleteI am new to Mobile testing . I am trying to automate android test , When i launch appium i get an error as could not find devices ,restarting ads server, but when i execute adb device i get the list of device, can you help me in this.
Hi,
ReplyDeleteI am facing device not connected error on Appium console as well as on Eclipse.
I can see the devices and emulator attached on the console. I have tried with emulator as well as real devices.
At first i tried with Google Nexus 5 real devices than i with emulator (One device were connected at a time).
Please find the attached screen shot for more details.
Regards
Ritesh
hi manoj,
ReplyDeleteCan u tell is there any other way to find element in mobile app except UI Automator
and also i want to know about how to automate IOS app from Window system
Hi Manoj,
ReplyDeleteI started my appium server using command 'appium &' and it started successfully and the http interface is : 0.0.0.0.4723
so i was used :
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
But when i run my code it gives error :
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Parameter 'appPackage' is required for launching application) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 8.22 seconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'Admin-PC', ip: '192.168.1.13', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_55'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at ExecuteTest.initialize(ExecuteTest.java:30)
at ExecuteTest.main(ExecuteTest.java:16)
Sonia, i have updated the code as per the latest appium version, take a look again
DeleteThanks for sharing this...its really helpful to start with Appium.
ReplyDeleteHi good blog on Android Mobile, Android OS is developing day by day good to see new features, thanks for the post.
ReplyDeleteHi, Can you share the steps for Appium to automate Native Android Apps on Mac platform.
ReplyDeleteHi Manoj,
ReplyDeleteThanks for sharing this. I am beginner in mobile automation on android devices(native app.), I am using selenium for automation. I am not able to swipe/scroll the application page up or down. Please provide me the solution.
Thanks in advance
Tushar Gupta
can you please help me by posting scrolling sample code for mobile web apps(chrome) for android platform
ReplyDelete> info: [37m--> [39m [37mPOST [39m [37m/wd/hub/session/7e344bc0-01d1-4ace-971a-b7ddf8878fd3/element [39m [90m{"using":"tag name","value":"EditText"} [39m
ReplyDelete> info: [debug] Invalid locator strategy: tag name
> info: [debug] Responding to client with error: {"status":9,"value":{"message":"Invalid locator strategy: tag name","origValue":"Invalid locator strategy: tag name"},"sessionId":"7e344bc0-01d1-4ace-971a-b7ddf8878fd3"}
> info: [37m<-- POST /wd/hub/session/7e344bc0-01d1-4ace-971a-b7ddf8878fd3/element [39m [31m500 [39m [90m 1.906 ms - 169 [39m [90m [39m
> info: [37m--> [39m [37mDELETE [39m [37m/wd/hub/session/7e344bc0-01d1-4ace-971a-b7ddf8878fd3 [39m [90m{} [39m
bug resolved in the script !!
DeleteHi manoj,
ReplyDeleteI am trying to automate a hybrid app using Appium. But i am not able to get the element id/class/xpath etc.
How u r finding an element??
DeleteHi,
ReplyDeleteAppium: Mobile Android Automation
to check Login validation message:
Senario: Enter wront username or pw and click on submit button, it should throw validation message as "Username or Password invalid. Try again, or"
Validation Message is - "Username or Password invalid. Try again, or"
To assert , I inserted below statement
WebElement errormessage = (driver.findElement(By.id("edu.wgu.students.mywgu:id/id_login_error_message")));
System.out.println(errormessage.getText());
Assert.assertEquals(driver.findElement(By.id("edu.wgu.students.mywgu:id/id_login_error_message")), errormessage);
After running i am getting the error as
"java.lang.AssertionError: expected [Username or Password invalid. Try again, or] but found [[[RemoteWebDriver: on WINDOWS (4c239c3f-c299-462b-ac7d-1958855203d1)] -> id: edu.wgu.students.mywgu:id/id_login_error_message]]"
Note: If I dont add Assert statement then my scripts will pass
try this--
DeleteAssert.assertEquals(driver.findElement(By.id("edu.wgu.students.mywgu:id/id_login_error_message")).getText(), errormessage);
As i found in your script, you forgot to add getText() function.
Hi Manoj,
ReplyDeleteI am getting following error. please help me out
java.lang.IllegalArgumentException: No enum constant org.openqa.selenium.Platform.Android
at java.lang.Enum.valueOf(Unknown Source)
at org.openqa.selenium.Platform.valueOf(Platform.java:1)
at org.openqa.selenium.remote.DesiredCapabilities.setCapability(DesiredCapabilities.java:168)
at mobileTestPackage1.CalculatorTest.setUp(CalculatorTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
SKIPPED CONFIGURATION: @AfterClass teardown
SKIPPED: testCal
code has been updated, have a look again!
DeleteHi Everyone...Code has been updated as per the latest Appium release. Those facing problem while execution, please have a look again.
ReplyDeleteHi Manoj,
ReplyDeleteI am getting the below error continuously. I am trying to execute the tests on mac. Can you please help me out..
FAILED CONFIGURATION: @BeforeClass setUp
java.lang.NoClassDefFoundError: com/google/common/base/Function
at testproj.sampleTest.setUp(sampleTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 25 more
Hi Akshatha...add the following jar google-collections.jar to remove the same error.
DeleteHi Manoj...grrt work.. i have tried automating native apps and it also works for me. The issue i am facing is with HYBRID apps. For some reasons the UIAutoamtor is not able to identify elements of a native app. Its only identifying the outer frame on which the entire app sits. Can you help me on this, i have a steep deadline to meet.
ReplyDeleteHi Manoj, It is helpful for everyone, Can i have your email id or contact number to reach you out.
ReplyDeleteThanks
Shyam
HI Manoj,
ReplyDeleteI am trying to automate an app with Appium 1.4.0 on Mac iOS 8.3 on a iOS Simulator.
My testcase works fine on Emulator but the same fails on iOS.
On iOS, my app crashes and relaunches 3-4 times and then fails.
Can you help me resolve it asap so that I can make a good progress on it.
Thanks,
Pradeep.K
which type of mobile application you are testing against iOS??
DeleteTrying with NewsHunt app.
DeleteIt seems to be hybrid app, to automate hybrid app you need iOS developer license. After getting license, you need to create iOS provisioning profile then you would be able to automate it.
Delete