Selenium-Java:Browsermob Proxyy- NoClassDefFoundError - selenium

I updated POM.xml with latest selenium-java dependency and Browsermob proxy.
Java Code:
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.quit();
POM.xml looks like,
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-proxy</artifactId>
<version>2.0-beta-8</version>
</dependency>
While I run the automation script, getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/HasInputDevices
The script runs fine , after removing Browsermob proxy dependency. ( But I need Browsermob proxy to capture network data).
Looks like the Browsermob proxy has a dependency selenium-api-2.*, I assume that is outdated and causing this problem.
Any help would be greatly appreciated.

It looks like you're using a very old version of BrowserMob Proxy, which probably isn't compatible with the latest versions of Selenium.You can find the latest version of BMP on its github page.
For example, the current version of BMP is 2.1.2, so you'd want to include this in your pom file:
<dependency>
<groupId>net.lightbody.bmp</groupId>
<!-- note the new artifactId -->
<artifactId>browsermob-core</artifactId>
<version>2.1.2</version>
</dependency>

Related

A very incredible question, Maven becomes naughty,selenium 4.0.0-beta-1

This is my maven dependency
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.0.0-beta-1</version>
</dependency>
But seleniu-chrome-driver in the local warehouse will always appear in two versions 3.14.0 and 4.0.0-beta-1
And when I
ChromeDriver driver = new ChromeDriver();
The imported one is always ChromeDriver() in 3.14.0;
But what I really need is ChromeDriver() in 4.0.0.1 beta;
Because only this version has executeCdpCommand() method
How can I force the use of ChromeDriver() in 4.0.0.1 beta;
why are you using that dependency explicitly , you could use :
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-7</version>
</dependency>
it has driver.executeCdpCommand(commandName, parameters) method
make sure you clean and rebuild your project.

I am trying to setup selenium with maven but am getting this error when declaring driver

I am trying to set up a selenium project with the maven build tool.
I have defined the dependencies but am still getting this error in the script.
Your screenshot suggests that you don't have org.openqa.selenium. As this is part of Selenium Java, you will need to include this dependency in your pom file:
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.11.0</version>
</dependency>
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/3.11.0

Selenium remote driver issue with HtmlUnit driver

[i'm seeing the issue with Selenium remote driver when I'm executing the script with Htmlunit driver.
Note 1:- Same script works without any issue when I'm running with Firefox driver.]
Note 2: My browser had security authentication process for whatever the site i open, Not sure if that have ant role in this.
I have observed the selenium remote driver under maven shows with little different icon in left pane.
I feel its jar file loading issue.
I tried to put the selenium remote driver manually into .m2 repository.
1
Error message:-
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException
at TestPackage.titleNUrlCheckingTest.main(titleNUrlCheckingTest.java:16)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
[enter image description here][2]
You need to use latest version, note the change of artifactId from old versions.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.26</version>
</dependency>
which depends on
selenium-api 3.3.1
Update:
Your pom.xml works with simple test case of HtmlUnitDriver, but there is a potential conflict of versions, you should exclude HtmlUnitDriver 2.24 from selenium-java 3.3.1:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
Also, try to remove all selenium dependencies, and have only htmlunit-driver, all needed dependencies are automatically handled by maven.
Please update your POM XML file with latest version of htmlunit dependency
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.32.1</version>
</dependency>
and remove if you have something like
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
and update project. This should resolve your exception issue.
Reference: https://github.com/SeleniumHQ/selenium/issues/4930

NoClassDefFoundError using with boxable plugin

I am using boxable plugin with pdfbox and I am trying to create a teble. I am getting error:
2015-09-09T10:36:52.453+0200|Severe: java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/edit/PDPageContentStream
at the line of code:
BaseTable table = new BaseTable(yStart,yStartNewPage, bottomMargin, tableWidth, margin, doc, page, true, drawContent);
Here is a part from pom.xml, describing the dependencies that I am using:
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.dhorions</groupId>
<artifactId>boxable</artifactId>
<version>1.2</version>
</dependency>
Is there a bug in current version of dependencies or am I missing something?
Thank you very much for any help.
Remove this:
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
2.0 is an unreleased version and is in development, and it has a different API. Boxable has its dependencies in its own pom.xml, it is currently requesting 1.8.8. (Which is not the latest version, but I don't think this matters for simple PDF creation)

What is the "official" way to use Selenium 2 (Selenium WebDriver) with Maven?

I'm just trying to make the basic Selenium2Example work with Firefox 4 using Maven to get the Selenium jars :
public class Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}
If I go there : http://code.google.com/p/selenium/wiki/UsingWebDriver, it says I should try a dependency like this :
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b3</version>
</dependency>
but the latest jars can be found in no repositories, the last version which works (with all dependencies found) is "2.0a4" (2.0a5 to 2.0a7 and 2.0b1 to 2.0b3 have missing main jars or missing dependencies), and this "2.04" version doesn't have the right classes to make the example work.
If I go there : http://seleniumhq.org/docs/03_webdriver.html#chapter03-reference, it says I should use this dependency :
<dependency>
<groupId>org.seleniumhq.webdriver</groupId>
<artifactId>webdriver-firefox</artifactId>
<version>0.9.7376</version>
</dependency>
It makes the example compile, but this release hasn't been updated since october 2009, and it doesn't run with Firefox 4 (see http://repo1.maven.org/maven2/org/seleniumhq/webdriver/webdriver-firefox/)
If I go there http://seleniumhq.org/download/maven.html, it says I should try something like :
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>...</version>
</dependency>
But the 2.0b3 version doesn't work either (missing dependencies). Here is the error message :
23/05/11 22:09:07 CEST: Build errors for first-webdriver-test; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project first-webdriver-test: Unable to get dependency information for org.apache.httpcomponents:httpcore:jar:4.0.1: Failed to process POM for org.apache.httpcomponents:httpcore:jar:4.0.1: Non-resolvable parent POM org.apache.httpcomponents:httpcomponents-core:4.0.1 for org.apache.httpcomponents:httpcore:4.0.1: Failed to resolve POM for org.apache.httpcomponents:httpcomponents-core:4.0.1 due to Missing:
----------
1) org.apache.httpcomponents:httpcomponents-core:pom:4.0.1
----------
1 required artifact is missing.
for artifact:
org.apache.httpcomponents:httpcomponents-core:pom:4.0.1
from the specified remote repositories:
central (http://repo1.maven.org/maven2, releases=true, snapshots=false)
I don't know the meaning of this error, since I can find the requested pom here : http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-core/4.0.1/httpcomponents-core-4.0.1.pom
So the only way I can make the example work for now, is manually downloading the 2.0b3 jars.
Does anybody succeed in making it work with Maven ?
Since RC2, you just need:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0rc2</version>
<type>pom</type>
</dependency>
For me this is working (with Maven 2.2.1):
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b3</version>
<type>pom</type>
</dependency>
Notice this line: <type>pom</type>
Also, I had to add the dependency on the junit library to get it to pass some surefire exceptions, but you might not need this.
With RC3 you need:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.0rc3</version>
</dependency>
to include all the jar
For me, this works:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.29.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.29.1</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>