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
Related
I am working on Appium-Java maven driven framework and getting below error for Android Capabilities
reference to setCapability is ambiguous
[ERROR] both method
setCapability(java.lang.String,java.lang.String) in
org.openqa.selenium.MutableCapabilities and method
setCapability(java.lang.String,org.openqa.selenium.Platform) in
org.openqa.selenium.MutableCapabilities match
Versions:
Selenium Version:<selenium.java.version>3.11.0</selenium.java.version> [Also tried with 3.141.59, 3.12.0, 3.7.1]
And Appium version:
<appium.java-client.version>6.1.0</appium.java-client.version>
Code Snippet:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", JsonPath.read(jsonFile, "$." + "platformName"));
Typecasting Output from JsonPath.read , to String resolved the issue.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", (String) JsonPath.read(jsonFile, "$." + "platformName"));
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);
}
}
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.
Platform compatibility :
Mac OS X 10.10 or higher, 10.11.1 recommended **[Using 10.10.5]**
XCode >= 6.0, 7.1.1 recommended **[Using 7]**
Apple Developer Tools (iPhone simulator SDK, command line tools)
Appium Server **[Using v1.5.3]**
Node.js **[Using V4.5.0]**
Don't actually know which is the perfect combination of all the SDK/requirements for configuring the Appium in MAC system.
And getting an error in Appium logcat:
Unable to load node configuration file to register with grid.
My code is
#BeforeTest
public void preSetup() throws MalformedURLException{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
File f=new File("/Users/nandini/Documents/AppiumWorkSpace/One20Automation/app/One20.app");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.0");
desiredCapabilities.setCapability("udid", "E1791000-5BC8-4741-A1AC-416FDEEB3048");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM, "MAC");
desiredCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
desiredCapabilities.setCapability(MobileCapabilityType.APP, f.getAbsolutePath());
driver=new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Note: Actually app is getting installed but not lunching the app and further work.Also by code simulator is appearing in screen, but after sometimes automatically closing it.
Please suggest.