error on code " org.openqa.selenium.remote.DriverCommand.NEW_SESSION" - java

I am getting below error with my java program:-
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.remote.DriverCommand.NEW_SESSION(Lorg/openqa/selenium/Capabilities;)Lorg/openqa/selenium/remote/CommandPayload;
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:211)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:147)
at automation.flyYatra.mainTest(flyYatra.java:42)
at automation.flyYatra.main(flyYatra.java:243)
Tried with adding the latest jar files as can be seen the snapshot below, but could not resolve it. Any help, please?
package automation;
public class flyYatra {
public void mainTest() throws IOException, InterruptedException, WebDriverException, SocketException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Downloads\\Driver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Tried with various versions of jar files, but could not solve

Your various versions of jar files is the problem known as JAR Hell because in the CLASSPATH there are multiple libraries having the same classes and the order of classloading varies depending on the underlying operating system and location of the libraries.
Make sure to have the same version of the Selenium Java libraries, to be more specific the latest one is 3.141.59
So I would recommend going for a dependency management solution like Apache Maven, you should get the things some using this small pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>selenium-java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
Save it somewhere on your disk and execute mvn dependency:copy-dependencies command - it will download a bunch of "good" .jars to "target/dependencies" folder.
You can also use this repository mentioned in Selenium with Java article as a basis for your tests

Related

Seems that methods of maven repository can not be called from end-product

I am setting up a Craftbukkit Server with the editor IntelliJ and the programming language Java. For that I use firebase-admin. I want use it trough maven and everything works. But when I build the .jar and then let it run it returns following error in the console:
java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
at raycroud.mckaff_server_manager.ServerManager.onEnable(ServerManager.java:26) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:254) ~[craftbukkit-1.13.2.jar:git-Bukkit-a4c555b]
I am sitting at this problem for many days and tried many different solutions, but nothing worked.
Here you can see my project structure:
And here my Artifacts Settings under File->Project Structure->Artifacts:
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>company.lol_server_manager</groupId>
<artifactId>server_manager</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.6.0</version>
</dependency>
</dependencies>
</project>
Actual the Craftbukkit plugin gets disabled but I normally I expect that he works and I don't know why he can find methods or other elements from maven libraries.
There could be several reasons.It would help if you provide your run/debug configuration.You could try the following:
Activate [Include in project build].
Let me know if it helps.

Maven failed to execute goal (Could not resolve dependencies)

I haven't worked with Java in many years as I primarily work with PHP (Using Composer for dependency management). I've only just started looking at Maven and Gradle too.
I'm trying to have a play around using Maven and wanted to use Eclipse's JDT UI tools so I could have a go at a test project building a user interface using some of their components, just to try and bring myself up to speed.
I'm using Maven to try and bring in the JDT UI package as a dependency. This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jonathon</groupId>
<artifactId>ui-test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.12.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.ui</artifactId>
<version>3.12.2</version>
</dependency>
</dependencies>
</project>
I'm using IntelliJ IDEA as my IDE and it seems to be complaining in a tooltip about not being able to resolve dependencies. I tried running mvn compile to see if I could get a better error message and I got this:
[ERROR] Failed to execute goal on project ui+test: Could not resolve dependencies for project com.jonathon:ui-test:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.eclipse.jdt:org.eclipse.jdt.ui:jar:3.12.2 -> org.eclipse.platform:org.eclipse.search:jar:3.11.1 -> org.eclipse.platform:org.eclipse.ui:jar:3.108.1 -> org.eclipse.platform:org.eclipse.swt:jar:3.105.2 -> org.eclipse.platform:org.eclipse.swt.gtk.linux.aarch64:jar:[3.105.2,3.105.2]: No versions available for org.eclipse.platform:org.eclipse.swt.gtk.linux.aarch64:jar:[3.105.2,3.105.2] within specified range -> [Help 1]
Am I doing something wrong? I got the artifactId, groupId and version from here.
This library is the problem org.eclipse.platform:org.eclipse.swt.gtk.linux.aarch64:jar it doesn't exist at all.
gtk.linux.aarch64 this part is resolved from your setup or java/system
propably you need to set osgi.platform=gtk.linux.x86_64 in your mvn pom or env .

Robot framework not picking up keyword implementation

I'm trying to set up robot on top of an Eclipse Maven-Selenium-TestNG java project I created, but it doesn't seem to be picking up default keywords (I haven't even tried adding my own yet).
I started by creating a maven project and adding to pom.xml the dependencies for selenium 3.4, testNG 6.8 and robot 3.0.2, then also added robot plugin 1.4.7. Finally, updated the project so maven downloads all the needed stuff.
To test selenium (without robot) I created a textNG class in src>test>java, added a system property pointing to the chromedriver.exe file in my system and added a simple test that just opens the browser and navigates to google. It worked, so now I want to use robot on top of that.
This is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.automation</groupId>
<artifactId>automated_tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.robotframework</groupId>
<artifactId>robotframework</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.4.7</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I created a file in src/test/robotframework/acceptance, with the following contents:
*** Settings ***
Test Set Up Start Selenium Server
Test Tear Down Stop Selenium Server
*** Test Cases ***
Visit google
Open Browser https://www.google.com chrome
Close Browser
However, when I run as maven install, I get:
Setup failed: No keyword with name 'Start Selenium Server' found.
Also teardown failed: No keyword with name 'Stop Selenium Server'
found.
So why is it that robot is not finding the keywords implementation? And how do I add implementations of my own keywords?
The reason robot isn't finding the keywords is that you aren't importing the library that contains the keywords. Start Selenium Server is part of the deprecated SeleniumLibrary. In order to use the keywords you must import them with the Library setting:
*** Settings ***
Library SeleniumLibrary
Test Set Up Start Selenium Server
Test Tear Down Stop Selenium Server
Assuming that the folder where SeleniumLibrary is installed is in your PYTHONPATH, robot will import the library and make the keywords available to you.
I actually found out I was missing a maven dependency:
<dependency>
<groupId>com.github.markusbernhardt</groupId>
<artifactId>robotframework-selenium2library-java</artifactId>
<version>1.4.0.8</version>
</dependency>
Also, I don't need to use Start Selenium Server and Stop Selenium Server because they're deprecated.
After that, I was able to run my test by creating a custom keyword to set browser path (I'm using chromedriver):
I created a .java file within src/main/java/demo and added a method that sets up the property:
package demo;
public class Setup {
public void driverPath() {
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
}
}
Then, I created src/test/robotframework/acceptance/Resource.robot file and imported my library:
*** Settings ***
Library Selenium2Library
Library demo.Setup
Also created a src/test/robotframework/acceptance/__init__.robot file and used the keyword I created (Browser Setup):
*** Settings ***
Test Setup Driver Path
Test Teardown Close All Browsers
Test Timeout 2 minute 30 seconds
In my test, I invoked Resource.robot:
*** Settings ***
Resource Resource.robot
*** Test Cases ***
Visit google
Open Browser https://www.google.com chrome

Maven project giving error

After setting up the project in intellij as a maven project like so ..
I set up my pom.xml file with a basic structure ...
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany.test</groupId>
<artifactId>jreddit-testing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jreddit-testing</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.github.jreddit</groupId>
<artifactId>jreddit</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
when I run sudo mvn clean install it installs everything with no errors.
On running the project I get the Error ..
Error:java: directory not found:
/Users/stingRay/Documents/workspace/jreddit/target/generated-sources/annotations
Not sure if this will solve your issue but the comments have not enough space :)
I would argue the environment variables are simply not properly configured. I recommend not using sudo and maven. It is simply not necessary if everything is configured properly.
The download page of maven contains the instructions what to do: http://maven.apache.org/download.cgi (scrolling down)
In short:
Download the Java Development Kit (I don't use the packet manager from Linux for this, to prevent having root being able to execute Java commands or run servers accidentally). It looks you are working on MacOS? So Download the dmg file from oracle.
Download the Maven archive and extract it (it can also be in a shared dirctory so it is readable for every user on the system)
the important part: setting the environment variables. You must set JAVA_HOME, M2_HOME, optionally MVN_OPTS and the PATH for convenience - so "mvn" runs in your terminal without sudo.
There are tutorials on the web that guide you through this, like this one: http://bitbybitblog.com/environment-variables-mac/
If you work with IntelliJ or the terminal the .bash_profile file be enough. Editing the .plist file is for OSX internal tools only. In IntelliJ it will work once the M2_HOME variable is set (if I remember correctly) and IntelliJ is restarted.
Note you may need to clean up the files already around (to make sure your user can write them without sudo). Meaning:
/Users/stingRay/Documents/workspace/jreddit/target/
/Users/stingRay/.m2/repository (or where your local maven repo is located)
Hope that will work :)

Selenium Maven Setup - One Empty Jar

I'm trying to set up a Java Selenium test using the recommended Maven instructions found here:
http://docs.seleniumhq.org/docs/03_webdriver.jsp
and here:
http://docs.seleniumhq.org/download/maven.jsp
I have maven installed and working.
I've copied the example pom.xml, changing only the project name
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SeleniumTest</groupId>
<artifactId>SeleniumTest</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>com.opera</groupId>
<artifactId>operadriver</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.opera</groupId>
<artifactId>operadriver</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Using
mvn clean install
runs without any errors. The target directory is created, containing SeleniumTest-1.0.jar and the maven-archiver directory. The problem is that my Eclipse project can't resolve the Selenium classes. I've copied the example Java driver class, modifying the imports based on my project layout:
import Selenium.*;
import Selenium.target.*;
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");
// Alternatively the same thing can be done like this
// driver.navigate().to("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());
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}
The classes "WebDriver", "WebElement", "WebDriverWait", and "ExpectedCondition" can't be resolved. Trying to use the imports in the example
import Selenium.By;
import Selenium.WebDriver;
import Selenium.WebElement;
import Selenium.firefox.FirefoxDriver;
import Selenium.support.ui.ExpectedCondition;
import Selenium.support.ui.WebDriverWait;
all fail.
I looked into the jar downloaded by Maven, SeleniumTest-1.0.jar, and it is effectively empty. It only contains the META-INF directory.
I feel like I'm missing something obvious, but I just can't figure it out. I feel like I'm missing something in my pom.xml, but I can't find anything on Selenium's site that helps. Can anyone give me a hand?

Categories

Resources