I have added following jars in my projects build path:
java-client-2.0.0 from http://appium.io/downloads.html >> Appium Client libraries >> Java
selenium-java-2.43.1
selenium-java-2.43.1-srcs
selenium-server-standalone-2.43.1
and here's my code:
public class SampleApp{
WebDriver dr;
#Test
public void testApp() throws MalformedURLException, InterruptedException {
String apkpath = "D:\\apkdump\\sampleapp.apk";
File app = new File (apkpath);
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
capabilities.setCapability("deviceName","TestADB18");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app",app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.test");
capabilities.setCapability("appActivity", "com.sampleapp.Main");
dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
}
I am getting red line below new AppiumDriver which says that Cannot instantiate the type AppiumDriver. Now if remove all selenium jars the error disappears but then I can't resolve errors with webdriver.What is the conflict between jars?
I saw similar question here but that could run the code and was getting Null pointer exception but in my case I cant even run it, it is giving run on saving the code. Secondly the answer has been posted without using AppiumDriver
You don't need to downgrade or anything. There is a design change in the Java Client version 2.0.0 as they mention on their site:
AppiumDriver is now an abstract class, use IOSDriver and AndroidDriver which both extend it.
So, just change your driver line to be:
dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
Hope that helps...
This error can be fixed by downgrading the Appium Client(see step 1 in my question) from latest to java-client-1.5.0. You can keep rest of the jars to latest.
Downgraded version of Appium Client can be downloaded from here http://mvnrepository.com/artifact/io.appium/java-client/1.5.0
WebDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),getDesiredCapabilities("192.21.168.56:5555"));
use this. and import:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
dr=new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
proper URL to be established
for appium version 1.7 use capability
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
while for v1.8.1
its not needed
Related
package AutomationSample;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver", "C:\\Users\\UserName\\Desktop\\chromedriver_win32");
WebDriver driver= new ChromeDriver();
driver.get("https://www.youtube.com/");
the above is my code and I have added all the selenium related jars into the project.
am getting the below error while running the Chrome driver:
Error: Unable to initialize main class AutomationSample.HelloWorld
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
I am using Chrome - Version 91.0.4472.114 (Official Build) (64-bit)
and I am using chrome driver - 32 bit and my OS is windows 10 -64 bit.
Can you please help me to rectify this error?
cause you are missing class and method, one such method is main()
You need to have a method like below :
public static void main(String args[]) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\UserName\\Desktop\\chromedriver_win32");
WebDriver driver= new ChromeDriver();
driver.get("https://www.youtube.com/");
}
and obviously a class in which you will have this method.
you have to pass the driver extension like below :
System.setProperty("webdriver.chrome.driver", "C:\Users\UserName\Desktop\chromedriver_win32.exe");
WebDriver driver= new ChromeDriver();
System.setProperty("webdriver.chrome.driver","C:\\Users\\UserName\\Desktop\\chromedriver_win32");
has to be:
System.setProperty("webdriver.chrome.driver","C:\\Users\\UserName\\Desktop\\chromedriver_win32.exe");
you forgot .exe
I want to user driver.removeapp({bundleID}); command in my appium script BUT IDE NOT suggesting this method even I've imported io.appium.java_client.*;
You need to double check the declaration of your driver variable:
public AppiumDriver driver;
driver = new IOSDriver(appiumURL, capabilities);
driver.removeApp(bundleId);
Exception in thread "main" java.lang.IllegalStateException : The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at practise_locators.DatePicker.main(DatePicker.java:11)
Here is my code:
package practise_locators;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DatePicker {
public static void main(String[] args){
WebDriver driver = new ChromeDriver();
System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
driver.get("https://www.google.com");
}
}
The error says it all :
Exception in thread "main" java.lang.IllegalStateException : The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
The following phrases from the error implies that there is an error in the line containing webdriver.chrome.driver
The error can be either of the following :
Error in the System Class Method setProperty()(including sequence) :
System.setProperty()
This line should be the very first line in your script.
Error in the specified Key :
"WebDriver.Chrome.driver"
Error in the Value field :
"E:\\chromedriver.exe"
You have to pass the absolute path of the WebDriver through either of the following options :
Escaping the back slash (\\) e.g. "C:\\path\\to\\chromedriver.exe"
Single forward slash (/) e.g. "C:/path/to/chromedriver.exe"
Your code seems to be having two issues as follows :
First issue is in specifying the Key which instead of "WebDriver.Chrome.driver" should have been "webdriver.chrome.driver" as follows :
System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
Second issue is in the sequence of mentioning the Key "webDriver.chrome.driver" in your program which should be before WebDriver driver = new ChromeDriver(); as follows :
System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
I have seen many people are using wrong sequence.
the sequence should be.
First set the property and then launch the browser
System.setProperty("webdriver.chrome.driver", "F:/chrome/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://www.google.com");
Download the chromedriver version corresponding to the chrome version in your system from https://chromedriver.chromium.org/downloads . Unzip the file and run the below code in the IDE.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Selintroduction {
public static void main(String[] args) {
//Invoking browser
System.setProperty("webdriver.chrome.driver","C:\\Users\\HP\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
}
}
(Path would depend on your file location in the PC.)
I was facing the same error when my code was like so:
System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32.exe");
It works after adding "chromedriver" before ".exe" like so:
System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32\\chromedriver.exe");
package com.merchantPlatform;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MerchantPlatformTest {
public static void main(String[] args) {
System.getProperty("webdriver.gecko.driver", "C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
// Initialize WebDriver
WebDriver driver = new FirefoxDriver(capabilities);
/* This works fine for versions lesser than Selenium 3. For Selenium 3 and higher, it will throw java.lang.IllegalStateException */
// Maximize Window
driver.manage().window().maximize();
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Navigate to MerchantPlatform URL
driver.get("http://localhost:52939/");
}
}
Error
I am getting the below exception with System.getProperty
Exception in thread "main" 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 com.google.common.base.Preconditions.checkState(Preconditions.java:738)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:137)
at com.merchantPlatform.MerchantPlatformTest.main(MerchantPlatformTest.java:20)
You have to use System.setProperty not the System.getProperty as follows.
System.setProperty("webdriver.gecko.driver",
"C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
I have noticed that you are using wrong syntax, to opening the browser.
Instead of using System.getProperty, You have to use System.setProperty as mentioned below.
System.setProperty("webdriver.gecko.driver", "C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
For more details on this issue, refer this page.
I am running Selenium WebDriver test on a remote PC from my laptop(java client), by using RemoteWebDriver. But RemoteWebDriver haven't provided screenshot API to directly get a screenshot of remote PC. Googled a lot but found seems need use to Json API to get it from remoteWebDriver server directly. Anyone can give me some instruction about how to do that? Thanks.
The RemoteWebDriver must be augmented before you can use the screenshot capability. As you have no doubt already found, attempting to cast without augmenting results in an exception.
WebDriver driver = new RemoteWebDriver( ... );
driver = new Augmenter().augment( driver );
( (TakesScreenshot)driver ).getScreenshotAs( ... );
I was able to get this working...here is what you need to do:
1) Create a new class file in a Util directory or somewhere
package com.util;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.RemoteWebDriver;
public class ScreenShotRemoteWebDriver extends RemoteWebDriver implements TakesScreenshot {
public ScreenShotRemoteWebDriver(URL url, DesiredCapabilities dc) {
super(url, dc);
}
#Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
if ((Boolean) getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT)) {
return target.convertFromBase64Png(execute(DriverCommand.SCREENSHOT).getValue().toString());
}
return null;
}
}
2) Then...where ever you start the RemoteWeDriver, replace with this code:
driver = new ScreenShotRemoteWebDriver(new URL(-PUT YOUR HUB URL HERE-),cap);
Your screenshots will be stored locally.
Hope this helps.
I think this is the best way:
public<T> Object getScreenshotAs(OutputType<T> outputType) {
Augmenter augmenter = new Augmenter();
TakesScreenshot ts = (TakesScreenshot) augmenter.augment(driver);
return ts.getScreenshotAs(outputType);
}
Here's another solution:
https://groups.google.com/d/topic/selenium-users/NLHXlhPrADs/discussion
The RemoteWebDriver does not implement the TakesScreenShot and the methods described here to cast the instance of RemoteWebDriver to TakesScreenShot will cause a ClassCastException. I'll see if I can find a solution as I'm interested in doing the same.
The Augmenter will "enhance the interfaces implemented by this instance of WebDriver iff that instance is a RemoteWebDriver". Depending on how the RemoteWebDriver is configured and how the selenium server is running on the remote host, it may be possible to get a screen shot in using the org.openqa.selenium.remote.Augmenter.
I've configured the RemoteWebDriver to use DesiredCapabilities.htmlUnit() capabilities and this gives an ClassCastError. If the RemoteWebDriver is configured with the capabilities of a driver that implements the TakesScreenshot interface, then a ClassCastException may not occur, though I have yet to test this.
From the TakesScreenshot interface, the known implementing drivers are: AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, InternetExplorerDriver, IPhoneDriver, IPhoneSimulatorDriver, and SafariDriver