I am new to Selenium grid. My hub and the node is running. I tried a test to automate in the node. But I am getting the error "Could not initialize class org.openqa.selenium.os.Kernel32". I could not find the solution anywhere. Please help
My code is :
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.net.MalformedURLException;
public class TestGrid {
WebDriver driver;
String baseURL, nodeURL;
#BeforeTest
public void setup() throws MalformedURLException{
baseURL = "http://newtours.demoaut.com/";
nodeURL = "http://192.168.0.6:5566/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.WIN8);
driver = new RemoteWebDriver(new URL(nodeURL), capability);
}
#Test
public void verifyTitle() {
String actualTitle = driver.getTitle();
String expectedTitle = "Welcome: Mercury Tours";
Assert.assertEquals(actualTitle, expectedTitle);
}
#AfterTest
public void closeSetup(){
driver.quit();
}
}
I had the same problem. And there was another error message appearing frequently.
org.openqa.selenium.WebDriverException: Native library (com/sun/jna/windows-x86-64/jnidispatch.dll) not found in resource path ([file:/C:/Users/admin/work/Selenium-batch-files/Windows/selenium-server-standalone-2.47.1.jar])
To solve the problem, I manually create selenium standalone jar file with jnidispatch.dll in correct path.
The steps below.
1) unzip selenium-server-standalone-2.47.1.jar using 7-zip. Then find out the "jnidispatch.dll" does exist, but no /com/sun/jna/windows-x86-64/ directory.
2) Create a directory .../com/sun/jna/windows-x86-64/ and copy "jnidispatch.dll" in.
3) create jar file.
"C:\Program Files\Java\jdk1.8.0_45\bin\jar.exe" cf yournewselenium.jar *
Note: you need to be in unzipped folder.
4) To run runSeleniumHub.bat and runSeleniumNode.bat, still complain "no menifest attribute". To fix this, change file
From:
call java -jar selenium-server-standalone-2.47.1.jar -role hub
To:
call java -cp yournewselenium.jar org.openqa.grid.selenium.GridLauncher -role hub
And on runSeleniumNode.batch
From:
call java -Dos.name=windows -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exe -jar selenium-server-standalone-2.47.1.jar -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,version=11,platform=WINDOWS" -browser "browserName=chrome,platform=WINDOWS" -browser "browserName=firefox,platform=WINDOWS"
To:
call java -Dos.name=windows -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exe -cp yournewselenium.jar org.openqa.grid.selenium.GridLauncher -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,version=11,platform=WINDOWS" -browser "browserName=chrome,platform=WINDOWS" -browser "browserName=firefox,platform=WINDOWS"
After the above changes, the problem is fixed. The error message not appear any more.
just dont use parameters
os.name, os.arch, os.version
when you run command
java -jar selenium-server-standalone-xxx.jar
(solution was tested on windows 10)
I was facing the same problem. After using proper URL, my problem has gone.
You should try with: http://www.yoursite.com
Also have a look here: https://stackoverflow.com/a/22149459/4921776
Related
I have setup a Gradle project to automate an Android application using Cucumber and Appium with Java. I also wanted to use POM to capture the elements page-wise. The project structure looks like:
I wants to add Extent Report to get testcase execution status. Now when i am running CukesRunner file:
package runners;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {
"json:target/cucumber.json",
"html:target/default-html-reports",
"rerun:target/rerun.txt"
},
features = {"src//test//resources//Features"},
glue = {"stepdefinition"},
dryRun = false,
tags = "#paybackTest"
)
public class CukesRunner {
}
It displays the exit code 0 error with some unknown error:
My appium server is running on 127.0.0.1:4723 and also an Android device connected through USB (i cross-checked it with 'adb devices').
I am trying to run TestSuite using Junit 5. Individual file run fine. But TestSuite is not running when executed from command line. I am using junit-platform-console-standalone-1.6.0.jar to run tests.
My Test classes are:
package demo;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
public class TestDemoClass1 {
#Test
public void test1() throws Exception {
System.out.println("Test 1 from DemoClass 1");
}
#Test
public void test2() throws Exception {
System.out.println("Test2 from DemoClass 1");
}
}
My Suite calss is:
package demo;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
#Suite
#SelectClasses({ TestDemoClass1.class })
public class TestSuite {
}
The command I am usign to run from command lines:
java -jar target/junit-platform-console-standalone-1.6.0.jar -cp .;target/test-classes/ -c demo.TestSuite
This is resolved ":https://github.com/junit-team/junit5/issues/2813.
The issue was not adding set of jars while runnign command needed for console launcher.
Additional info in above GitHub issue link but in summary you need to add following jars to classpath:
junit-platform-console-standalone-1.8.2.jar;
junit-platform-suite-api-1.8.2.jar;
junit-platform-suite-commons-1.8.2.jar;
junit-platform-suite-engine-1.8.2.jar; \
i am trying to run the chrome beta version with selenium Web-driver.
When i run the test case i got the following error on console see image please:
I have added following lines in the node config file:
{
"capabilities": [
{
"platform": "WINDOWS",
"browserName": "chrome",
"webdriver.chrome.driver":"drive:\selenium\chromedriver.exe",
"chromeOptions": "drive:\Program Files (x86)\Google\Chrome Beta\Application\chrome.exe",
}
]
I am using following setup:
Selenium=2.53
chrome Web-driver= 80_0_3987_16
Google chrome= 80.0.3987.66 (Official Build) beta (64-bit)
we have Hub and Node setup and automated test suit executed from GO cicd Server.
any help would be appreciated, thanks
To run either of the google-chrome browser variant among:
Chrome Canary
Chrome from Dev Channel
Raw build of Chromium for Windows x64
You need to to download the latest Chromium binary from either of the official repositories:
The Chromium Projects
chromium.appspot
Chrome Canary - Nightly build for developers
and you can use the following solution:
Code Block:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class A_Chrome_Canary {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
}
}
Console Output:
Google
Browser Snapshot:
This worked for me
chrome_options.binary_location = "C:/Program Files/Google/Chrome Beta/Application/chrome.exe"
I'm trying to set-up a Selenium + Cucumber project in Java (I'm a beginner with Java) in Intellij. This is my class that uses the Cucumber JUnit runner:
package runtest;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions (
features = "C:\\Users\\my-feature.feature",
)
public class RunTest {
}
I'm getting these errors:
Error:(8, 1) java: annotation #org.junit.runner.RunWith is missing default values for elements annotationType,<init>
Error:(8, 2) java: org.junit.runner.RunWith is not an annotation type
I don't know how to resolve this or what is happening. Please help.
I had multiple RunWith classes in my project path. After pruning the project tree, it works as expected.
You don't have to provide the absolute path of the feature file if you opt to place it within your project space. The name of the feature file folder would be enough.
As an example, if you are having the following structure:
Package: Q43966680
Class: Runner
Feature File Folder: q43966680
Snapshot:
As per your usecase within #CucumberOptions you just need to mention:
#RunWith(Cucumber.class)
#Cucumber.Options (features="q43966680")
public class RunTest {
}
I am new to Jenkins.
I have sample selenium code like below in Java project:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SampTest
{
public static void main(String[] args)
{
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println(driver.getTitle());
driver.quit();
}
}
This works perfect.
I configured like below in Jenkins:
Create a new project with name.
In Advanced options, added Workspace as "D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src"
In build section, i used Execute Windows batch command like "javac SampTest.java | java SampTest"
(Basically i dont know what to use here. Can someone help me here).
When i build the project now i see an error message saying below:
Started by user anonymous
Building in workspace D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src
[src] $ cmd /c call C:\Users\user\AppData\Local\Temp\hudson578216989100659838.bat
D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src>javac SampTest.java | java SampTest
java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
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)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" SampTest.java:1: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
SampTest.java:2: error: package org.openqa.selenium.firefox does not exist
import org.openqa.selenium.firefox.FirefoxDriver;
^
SampTest.java:8: error: cannot find symbol
WebDriver driver=new FirefoxDriver();
^
symbol: class WebDriver
location: class SampTest
SampTest.java:8: error: cannot find symbol
WebDriver driver=new FirefoxDriver();
^
symbol: class FirefoxDriver
location: class SampTest
4 errors
D:\UD\ProgrammingSamples\Selenium\SeleniumPractice\src>exit 1
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE