I have the following error:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:134)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:155)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
at automationFramework.SecondTest.main(SecondTest.java:20)
my code:
package automationFramework;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import junit.runner.Version;
public class SecondTest {
public static void main(String[] args) throws Exception {
System.out.println("JUnit version is: " + Version.id());
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
FirefoxDriver driver = new FirefoxDriver();
//System.setProperty("webdriver.gecko.driver", "C:\\\\Program Files\\Firefox Developer Edition\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "E:\\\\Projects\\WebDriver\\geckodriver.exe");
driver.get("http://www.google.com");
}
}
This looks like a problem with Guava libraries. If you use maven to manage your dependencies, set a Guava version manually like this:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
Also, remove the \\ part from your system property. It should only be \\
Related
I am trying to run a mini appium project, I have the emulator and an appium server running and here's my code, it says that .getBinaryPath() is undefined for type WebDriverManager "caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getBinaryPath());"
package appiumBasics;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.github.bonigarcia.wdm.WebDriverManager;
#Test
public class RubWebApplicationAndroidEmulator {
public void OpenWebApplication() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "HaidyEmulator");
WebDriverManager.chromedriver().setup();
caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getBinaryPath());
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
}
}
That is because if you actually go to the repository and open the problematic class, you find there is no such method defined for WebDriverManager:
https://github.com/bonigarcia/webdrivermanager/blob/master/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java
Presumably this was changed at some point. Possibly you need WebDriverManager#getDownloadedDriverPath():
#Test
public class RubWebApplicationAndroidEmulator {
public void OpenWebApplication() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "HaidyEmulator");
WebDriverManager.chromedriver().setup();
caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getDownloadedDriverPath());
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
}
}
I am learning appium and trying to perform a basic google search operation in appium java. The code I have written is:
package com.MavenTest;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class StartChrome {
#Test
public void test1() throws MalformedURLException, InterruptedException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My Phone");
caps.setCapability("udid", "790dc03c"); // Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "5.1.1");
caps.setCapability("browserName", "Chrome");
caps.setCapability("noReset", true);
// Create object of AndroidDriver class and pass the url and capability that we
// System.setProperty("webdriver.chrome.driver",
// "D:\\workspace\\AppiumTest\\driver\\chromedriver.exe");
AppiumDriver<MobileElement> driver = null;
try {
driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
// Open URL in Chrome Browser
driver.get("http://www.google.com");
System.out.println("Title " + driver.getTitle());
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Search")));
driver.findElementByName("q").sendKeys("google");
Thread.sleep(2000);
driver.findElementByName("Gogle Search").click();
driver.quit();
}
}
error I am getting when trying to sendkeys is:
java.lang.ClassCastException:
org.openqa.selenium.remote.RemoteWebElement cannot be cast to
io.appium.java_client.MobileElement
MobileElement is derived from RemoteWebElement.
If you write code like this:
driver.findElementByName("q").sendKeys("google");
You are trying to cast a RemoteWebElement to one of its subclasses MobileElement.
java.lang.ClassCastException Issue comes if you directly access the method like below:
driver.findElementByName("q").sendKeys("google");
WorkAround: You have to cast to the MobileElement like below:
MobileElement find = (MobileElement) driver.findElementByName("q").sendKeys("google");
I faced the same issue, upgrading Appium Client library fixes it.
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.4</version>
</dependency>
Following previous related issues posted and given resolution, I tired everything but still getting same error for FireFox, Chrome & Internet Explorer.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Search {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
System.getProperty("webdriver.gecko.driver",
"C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0-
win64\\geckodriver.exe");
driver.get("http://www.wikipedia.org");
WebElement link;
link = driver.findElement(By.linkText("English"));
link.click();
Thread.sleep(5000);
WebElement searchbox;
searchbox = driver.findElement(By.id("searchInput"));
searchbox.sendKeys("Software");
searchbox.submit();
Thread.sleep(5000);
driver.quit();
Shouldn't that be System.setProperty() instead of .getProperty()?
System.setProperty("webdriver.gecko.driver, "C:\\Users\\...\\geckodriver.exe");
Use that gecko driver system property before driver intialization
So first line gecko property and next line driver=new so and so..
Use .setProperty and declare it after providing the path to webdriver
System.setProperty("webdriver.gecko.driver",
"C:\\Users\\nitin\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
I am new to extent reporting. I am using Selenium Webdriver and want to use Extent reports with it.
But my code is not able to create ExtentReport object.
package com.code.draft;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class TestReport {
ExtentReports reports;
ExtentTest logger;
WebDriver driver;
public void start(){
reports = new ExtentReports("C:\\User\\Test\\Report\\Report.html"); //Exception at this line reports object = null
driver = new FirefoxDriver();
driver.get("http://www.google.com");
logger = reports.startTest("Verify Title");
logger.log(LogStatus.INFO, "Starting Browser");
reports.endTest(logger);
}
public static void main(String[] args) {
TestReport report = new TestReport();
report.start();
}
}
The above code is giving exception as :
Exception in thread "main" java.lang.NoSuchFieldError: VERSION_2_3_23
at com.relevantcodes.extentreports.HTMLReporter.start(HTMLReporter.java:76)
at com.relevantcodes.extentreports.Report.attach(Report.java:314)
at com.relevantcodes.extentreports.ExtentReports.<init>(ExtentReports.java:85)
at com.relevantcodes.extentreports.ExtentReports.<init>(ExtentReports.java:419)
at com.code.draft.TestReport.start(TestReport.java:19)
at com.code.draft.TestReport.main(TestReport.java:29)
Using the below configuration :
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
if anyone have idea. Please help.
I tested your code. It shows no exception at my end. But to get your HTML report you need to flush using reports.flush() just before reports.endTest(logger);.
I am new to selenium testing. I want to run selenium test cases on multiple browsers against internet explorer, Firefox, opera and chrome. What approach i have to follow. Can you people please suggest me which is the best process.
Does selenium web driver supports multiple browsers or not???
We had written login script. It runs successful for Firefox, chrome and internet explorer individually. But i want to run it for those multiple browsers sequentially.
web driver supports multiple browsers of course, there is also support for mobile
ChromeDriver
IEDiver
FirefoxDriver
OperaDriver
AndroidDriver
Here is an exemple to run the same tests in multiple browsers.
package ma.glasnost.test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
.........
DesiredCapabilities[] browserList = {DesiredCapabilities.chrome(),DesiredCapabilities.firefox(),DesiredCapabilities.internetExplorer(), DesiredCapabilities.opera()};
for (DesiredCapabilities browser : browserList)
{
try {
System.out.println("Testing in Browser: "+browser.getBrowserName());
driver = new RemoteWebDriver(new URL("http://127.0.0.1:8080/..."), browser);
Hope that helps.
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Sample {
private WebDriver _driver;
#Test
public void IEconfiguration() throws Exception {
System.setProperty("webdriver.ie.driver",
"D:/Softwares/Selenium softwares/drivers/IEDriverServer.exe");
_driver = new InternetExplorerDriver();
login();
}
#Test
public void FFconfiguration() throws Exception {
_driver = new FirefoxDriver();
login();
}
#Test
public void CRconfiguration() throws Exception {
System.setProperty("webdriver.chrome.driver",
"D:/Softwares/Selenium softwares/drivers/chromedriver.exe");
_driver = new ChromeDriver();
//_driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
login();
}
public void login() throws Exception {
_driver.get("http://www.google.com");
}
}
Before that we have to install the chrome and internet explorer drivers .exe files and run those.
You could use the WebDriver Extensions framework's JUnitRunner
Here is an example test googling for "Hello World"
#RunWith(WebDriverRunner.class)
#Firefox
#Chrome
#InternetExplorer
public class WebDriverExtensionsExampleTest {
// Model
#FindBy(name = "q")
WebElement queryInput;
#FindBy(name = "btnG")
WebElement searchButton;
#FindBy(id = "search")
WebElement searchResult;
#Test
public void searchGoogleForHelloWorldTest() {
open("http://www.google.com");
assertCurrentUrlContains("google");
type("Hello World", queryInput);
click(searchButton);
waitFor(3, SECONDS);
assertTextContains("Hello World", searchResult);
}
}
just make sure to add the WebDriver Extensions framework amongst your maven pom.xml dependencies
<dependency>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions</artifactId>
<version>1.2.1</version>
</dependency>
The drivers can be downloaded using the provided maven plugin. Simply add
<plugin>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<goals>
<goal>install-drivers</goal>
</goals>
</execution>
</executions>
<configuration>
<drivers>
<driver>
<name>internetexplorerdriver</name>
<version>2.44</version>
</driver>
<driver>
<name>chromedriver</name>
<version>2.12</version>
</driver>
</drivers>
</configuration>
</plugin>
to your pom.xml. Or if you prefer downloading them manually just annotate the test class with the
#DriverPaths(chrome="path/to/chromedriver", internetExplorer ="path/to/internetexplorerdriver")
annotation pointing at the drivers.
Note that the above example uses static methods from the WebDriver Extensions Bot class to make the test more readable. However you are not tied to using them. The above test rewritten in pure Selenium WebDriver would look like this
#Test
public void searchGoogleForHelloWorldTest() throws InterruptedException {
WebDriver driver = WebDriverExtensionsContext.getDriver();
driver.get("http://www.google.com");
assert driver.getCurrentUrl().contains("google");
queryInput.sendKeys("Hello World");
searchButton.click();
SECONDS.sleep(3);
assert searchResult.getText().contains("Hello World");
}