I'm new to eclipse. I'm trying to start Appium test on Android devices. My preferenses:
Appium 1.8.2
jre1.8.0_191
jdk1.8.0_191
eclipse 4.9.0
TestNG
AndroidStudio 3.2.1
AndroidDeveloperTools
So after installing, configuration Appiumserver, Android SDK, Android Device Manager - next step is to start testing in Eclipse IDE I've got problem with defining URL and don't know what to do.
jar files:
java-client-6.1.0.jar
gson-2.8.5.jar
client-combined-3.9.0-sources.jar
client-combined-3.9.0.jar
seleium-3.9.0-nodeps-sources.jar
seleium-3.9.0-nodeps.jar
seleium-html-runner-3.9.0.jar
seleium-server-standalone-3.9.0.jar
TestNG
JRE System Library
that's all
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class FirstScript {
private URL serverUrl;
public static AndroidDriver driver;
public String APPIUM_PORT = "4723";
#BeforeClass
public void setUp() throws MalformedURLException{
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Samsung S7");
caps.setCapability("udid", "******************"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("appPackage", "com.***.***");
caps.setCapability("appActivity", "com.***.***.MainActivity");
caps.setCapability("noReset", "true");
try {
serverUrl = new URL("http://127.0.0.1:4723/wd/hub");
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver = new AndroidDriver (serverUrl,caps);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
#Test
public void testExample() {***}
#AfterClass
public void tearDown() {driver.closeApp();}
}
Running debug for this code with error
Server is working
The solution to your issue is that you use latest stable version of Selenium i.e. 3.141.5
If you're having Java project then, before adding new latest version of jar's make sure to first remove all selenium related old jar's and then add newly downloaded version of the jar's to build path.
In case of Maven project, update the selenium dependency version to latest and run following on terminal,
$ mvn clean install
I suggest you to use maven project and the dependencies: java-client, selenium-java and testng.
If you don't want to use maven project, you need to import above libraries in eclipse. For that From your Eclipse workspace, right click your project on the left pane -> Properties -> Java Build Path -> Add Jars -> add your jars there.
Change your code as follow:
public class FirstScript {
public static AppiumDriver<MobileElement> driver;
#BeforeClass
public void setUp() throws MalformedURLException{
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Samsung S7");
caps.setCapability("udid", "******************"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("appPackage", "com.***.***");
caps.setCapability("appActivity", "com.***.***.MainActivity");
caps.setCapability("noReset", "true");
driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"),caps);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
}
Related
I'm trying to run a simple appium test case , but when executing the test this exception is throwed Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/ConnectionPool
for this line of code
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), caps);
the code I used is
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "blustack");
caps.setCapability("udid", "emulator-5554"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "7.1.2");
caps.setCapability("appPackage", "com.sourcey.materialloginexample");
caps.setCapability("appActivity", "com.sourcey.materialloginexample/com.sourcey.materiallogindemo.LoginActivity");
caps.setCapability("noReset", "true");
//Instantiate Appium Driver
try {
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
I found a same issue here but the proposed solution doesn't work.
Make sure your are importing all the required jars files.
If you are using Maven project import following dependency
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.13.0</version>
</dependency>
If you are using java project, check Adding jars for appium
Unable to build Selenium Script in Jenkins.
Generating error related to Browser driver.
Working Code in Eclipse with Maven
package test;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.net.MalformedURLException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
public class NewTest {
private WebDriver driver;
#Test
public void testEasy() throws InterruptedException {
System.out.println("Testing");
driver.get("http://www.google.com/");
Thread.sleep(5000);
String title = driver.getTitle();
}
#SuppressWarnings("deprecation")
#BeforeTest
public void beforeTest() throws MalformedURLException {
System.out.println("#BeforeTest");
//System.setProperty("webdriver.gecko.driver", "F:\\Selenium\\Selenium Library\\drivers\\geckodriver.exe");
//Now you can Initialize marionette driver to launch firefox
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
/*FirefoxOptions options = new FirefoxOptions()
.addPreference("browser.startup.page", 1)
.addPreference("browser.startup.homepage", "http://demo.guru99.com/test/guru99home/");
driver = new FirefoxDriver(options);
*/
driver = new FirefoxDriver();
}
#AfterTest
public void afterTest() {
System.out.println("##AfterTest");
driver.quit();
}
}
After trying to run POM.xml build in Jenkins. It's result failed because of Unable to execute gecko driver.
enter image description here
Failed
test.NewTest.beforeTest (from TestSuite)
Failing for the past 26 builds (Since Unstable#11 )
Took 1.2 sec.
add description
Error Message
The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
Stacktrace
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
at test.NewTest.beforeTest(NewTest.java:39)
Standard Output
#BeforeTest
Standard Error
Apr 20, 2018 2:12:36 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
Any one have idea about how to resolved this issue please provide me solution for that
public class Mobiletest {
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException,
InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Redmi 1s");
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("platformName", "Android");
// capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage",
"com.zipgo.customer");
capabilities.setCapability("appActivity",
"SplashActivity");
capabilities.setCapability(
MobileCapabilityType.NEW_COMMAND_TIMEOUT,
"100");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
It shows below error as in Appium:
Multiple markers at this line
- AndroidDriver cannot be resolved to a type
- driver cannot be resolved to a variable
I have added gson jar and java client jar files also
You are probably adding wrong dependencies into your project.
In my case, these are the ones I'm using in my Appium lib:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'junit:junit:4.12'
compile 'io.appium:java-client:4.1.2'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'org.apache.httpcomponents:httpclient:4.5.1'
compile 'commons-lang:commons-lang:2.6'
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.http-client:google-http-client:1.21.0'
compile 'com.testdroid:testdroid-api:2.9'
compile 'com.google.http-client:google-http-client-jackson2:1.21.0'
}
And then, when creating the AndroidDriver, I'm importing:
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
Try to my example:
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "8d1737f5");
// Need your unique device name, search in google, only for real device
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0.1");
capabilities.setCapability(MobileCapabilityType.APP, "D://YourAPK.apk");
capabilities.setCapability("appPackage","com.sannacode.android.interviewtest");
capabilities.setCapability("appActivity", "com.sannacode.android.interviewtest.MainActivity");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
add Apache Commons Lang 3.8.1 for (Java 7+)
and Apache Commons Lang 2.6 (Requires Java 1.2 or later)
my java version is 8 and after adding Apache Commons Lang 3.8.1 solve my problem.
Genymotion with VirtualBox download from genymotion site and install properly
Add Genymotion pluging on eclipse and set Genymotion directory
Add virtual device Nexus9 os version 5.1.0 API 22
Add Selenium and Appium java client jar files under project
Use Genymotion Android Tool and Custom Android SDK tool as Genymotion ADB tool connection setting
Configure Appium Setting and run Appium
Run below source code on eclipse
import java.io.IOException;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;
public class Firstappium {
static String deviceName = "Nexus9-5.1.0API22";
static WebDriver driver;
static String url ="http://127.0.0.1:4720/wd/hub";
public static void main(String[] args) {
DefaultExecuteResultHandler resultHandler;
DesiredCapabilities capabilities = new DesiredCapabilities();
DefaultExecutor executor = new DefaultExecutor();
resultHandler = new DefaultExecuteResultHandler();
capabilities.setCapability("deviceName","Nexus9-5.1.0API22");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app","G:/appium/apk/cz.hipercalc.apk");
driver = new AndroidDriver(new URL(url),capabilities);
System.out.println("Appium Driver is launched successfully");
}
}
Every time Appium can't find to the Genymotion emulator within session time. Please check attached screen shot
Friends,
Trying to run appium script on ios actual device,gets below error
Eclipse error:
[TestNG] Running:
/private/var/folders/05/79kfthm94qjd3bngd2l5pv7r0mx69v/T/testng-eclipse--1690789728/testng-customsuite.xml
FAILED CONFIGURATION: #BeforeClass setUpBeforeClass
org.openqa.selenium.SessionNotCreatedException: A new session could
not be created. (Original error: Command failed: /bin/sh -c xcrun
--sdk iphonesimulator --show-sdk-version) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15.00 seconds
Build info: version: '2.51.0', revision: '1af067d', time:
'2016-02-05 19:15:17'
System info: host: 'NCA047065', ip: '10.65.210.61', os.name: 'Mac
OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version:
'1.7.0_79'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
And .java code:
import org.junit.BeforeClass;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class iOSApptest {
public static RemoteWebDriver driver;
#BeforeClass
public static void setUpBeforeClass() throws Exception
{
File appDir = new File ("//Users//gangaiahl//Appium//jars");
File app = new File (appDir, "Car.ipa");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "firefox");
capabilities.setCapability("device", "iPhone 6");
capabilities.setCapability("u_did", "840384833537f40d011032eaaf20a53705a451ce");
capabilities.setCapability("bundle_id", "au.dev.com.onewaytraffic.carsguide");
capabilities.setCapability("deviceName", "Cars_iPhone_6");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "9.2");
capabilities.setCapability("app",app.getAbsolutePath());
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test()
{
System.out.println("Test started");
//System.out.println(" Start to identify a test");
//System.out.println("Test Completed");
}
}
It seems wrong capability
capabilities.setCapability("u_did",
"840384833537f40d011032eaaf20a53705a451ce");
Try use "udid" key instead of "u_did"
See documentation
You can try since that could have to do with the libxml library according to a quick google search.
$ brew uninstall libxml2
$ brew prune
$ brew install libxml2
You should also try and update your Xcode command line tools. Since its failing when trying to use the xcrun command.
Xcode 11
Try installing command-line tools from https://developer.apple.com/download/more/
This solved my error