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
Related
I am trying to launch chrome on my Android mobile which has chrome version: 76.0.3809.89
When I run my Java program, I get below error:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Unable to automate Chrome version because it is too old for this version of Chromedriver.
Chrome version on the device: Chrome/76.0.3809.89
Visit 'https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md' to troubleshoot the problem.
Failed to start Chromedriver session: A new session could not be created. Details: session not created: Chrome version must be between 71 and 75
**(Driver info: chromedriver=2.46.628402** (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17763 x86_64)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'abc', ip: '10.0.1.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'
Driver info: driver.version: AndroidDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Unable to automate Chrome version because it is too old for this version of Chromedriver.
**Chrome version on the device: Chrome/76.0.3809.89**
Visit 'https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md' to troubleshoot the problem.
I have below questions:
From where it is picking chromedriver=2.46.628402 as it mentions in the log ?
How to fix this error?
My code:
package browserTest;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class ChromeTest {
public static void main(String args[]) {
//Set the Desired Capabilities
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "My Android Mobile");
cap.setCapability("udid", "521010f9ee4fb499");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "7.0");
cap.setCapability("browserName", "Chrome");
cap.setCapability("noReset", true);
//Instantiate Appium Driver
AppiumDriver<MobileElement> driver = null;
try {
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}catch (MalformedURLException e) {
e.getMessage();
}
//Open URL in Chrome browser
driver.get("http://www.google.com");
}
}
i'm using Windows and AppiumServer with nodejs
you can download at https://chromedriver.storage.googleapis.com/index.html
matching chrome driver version
and change chrome driver at
C:\Users\{username}\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win
with this command chromedriver.exe -version
you can check version like this
C:\Users\{username}\AppData\Roaming\npm\node_modules\appium\node_modules\appiu
m-chromedriver\chromedriver\win>chromedriver.exe -version
ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1)
C:\Users\{username}\AppData\Roaming\npm\node_modules\appium\node_modules\appiu
m-chromedriver\chromedriver\win>chromedriver.exe -version
ChromeDriver 76.0.3809.12 (220b19a666554bdcac56dff9ffd44c300842c933-refs/branch-
heads/3809#{#83})
You need the correct chromedriver which can handle Chrome 76 on your device.
You can try to set in manually with appium see here:
npm install appium --chromedriver_version="76.0.3809.68"
Another option that should work would be to use the WebDriverManager.
It automatically downloads the correct driver and sets the capabilities accordingly.
Just add it to your project.
For example if you have a gradle project add following line to your build.gradle:
compile group: 'io.github.bonigarcia', name: 'webdrivermanager',
version: '3.6.2'
Then you need to set the chromedriver in your driver capabilities:
WebDriverManager.chromedriver().setup();
cap.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getBinaryPath());
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);
}
}
i have written simple script, which launches an chrome app on Android N(7.0),but not able to run, getting error
Details Environment
Appium version (or git revision) that exhibits the issue: 1.4.16.1
Last Appium version that did not exhibit the issue (if applicable): N/A
Desktop OS/version used to run Appium: window 7/32 bit
Node.js version (unless using Appium.app|exe): node-v8.9.4-x86
Mobile platform/version under test: chrome browser /64.0.3282.123
Real device or emulator/simulator:Android 7.0.0:MotoG(4)/Build/NPJS25.93-14-10
Appium CLI or Appium.app|exe: Appium Desktop exe
Error logs
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s ZY2239HZB2 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk""\nadb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.unlock without first uninstalling.]\r\n)","killed":false,"code":1,"signal":null,"cmd":"C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s ZY2239HZB2 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk""","origValue":"Command failed: C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s ZY2239HZB2 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk""\nadb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.unlock without first uninstalling.]\r\n"},"sessionId":null}
code:
import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
//import org.testng.annotations.Test;
public class StartChrome
{
public static void main(String[] args) throws MalformedURLException{
DesiredCapabilities cd=DesiredCapabilities.android();
cd.setCapability(MobileCapabilityType.BROWSER_NAME,BrowserType.CHROME);
cd.setCapability(MobileCapabilityType.PLATFORM,Platform.ANDROID);
// we need to define platform name
cd.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
// Set the device name as well (you can give any name)
cd.setCapability(MobileCapabilityType.DEVICE_NAME,"my phone");
// set the android version as well
cd.setCapability(MobileCapabilityType.VERSION,"7.0");
// Create object of URL class and specify the appium server address
URL url= new URL("http://127.0.0.1:4723/wd/hub");
// Create object of AndroidDriver class and pass the url and capability that we created
WebDriver driver = new AndroidDriver(url, cd);
// Open url
driver.get("http://www.facebook.com");
// print the title
System.out.println("Title "+driver.getTitle());
// enter username
driver.findElement(By.name("email")).sendKeys("sni****#gmail.com");
// enter password
driver.findElement(By.name("pass")).sendKeys("*****8");
// click on submit button
driver.findElement(By.id("u_0_5")).click();
// close the browser
driver.quit();
Please update your Appium version as it's very old and you're seeing a known issue with Android 7.0 that was resolved in 1.6.0 (released October 2016).
If that's not possible, run the following commands before running your script:
adb -s device_serial uninstall io.appium.settings
adb -s device_serial uninstall io.appium.unlock
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