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
Related
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; \
This question already has answers here:
java.lang.NoClassDefFoundError: com/google/common/base/Function
(1 answer)
How to solve java.lang.NoClassDefFoundError? Selenium
(1 answer)
Closed 3 years ago.
I am getting an error "Exception in thread "main" java.lang.NoClassDefFoundError", when running a small selenium.
Added external jar file is client-combined-3.141.59.jar
If adding some more jar files like selenium-server-standalone-3.141.59, okio-1.14.1.jar errors are increasing.
package seleniumBasic;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class selenium {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
}
Probably you did not add the library correctly to your build path. From where did you get that jar and how did you add it to your project?
Anyway, I would suggest to use gradle to add these libraries. Just add the gradle nature to your project and use following example build.gradle file:
plugins {
id 'java-library'
}
dependencies {
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
}
repositories {
jcenter()
}
I'm using Ubuntu Mate 16.04 and I'm trying to run a simple hello world program using tornadofx. The file is called hello.kt and I'm attempting to compile and run it using just the terminal.
It seems to compile just fine by running
kotlinc -cp tornadofx.jar hello.kt -include-runtime -d hello.jar
But when I try to run it by entering
java -jar hello.jar
I get a NoClassDefFoundError error:
Exception in thread "main" java.lang.NoClassDefFoundError: tornadofx/View
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at HelloKt.main(hello.kt:15)
Caused by: java.lang.ClassNotFoundException: tornadofx.View
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Here's the file:
import javafx.scene.control.Label
import javafx.scene.layout.HBox
import tornadofx.App
import tornadofx.View
class HelloWorld : View() {
override val root = HBox(Label("Hello world!"))
}
class HelloWorldApp : App() {
override val primaryView = HelloWorld::class
}
fun main(args: Array<String>) {
val window = HelloWorldApp()
}
Any help would be greatly appreciated. Thanks.
You need to install Oracle JDK, which comes with JavaFX, or install the JavaFX OpenJDK bundles in Ubuntu. I would recommend the Oracle JDK.
Additionally, JavaFX Applications has to be launched, you can't simply instantiate the App class. See below.
The syntax in your example code is very outdated - did you find this in the guide or somewhere else? This is the current syntax for your code example, including the correct launch command.
class HelloWorld : View() {
override val root = hbox(label("Hello world!"))
}
class HelloWorldApp : App(HelloWorld::class)
fun main(args: Array<String>) {
launch<HelloWorldApp>(args)
}
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
I try to run "gradle test", and get error
My test is
class HelperTest extends ro.gd.Test {
Plugin o;
void setUp() {
o = new Plugin();
}
void testGetIdeaDeps() {
def r = o.ideaDeps
asrHaveVal r
}
}
when i run gradle test, it raise:
junit.framework.AssertionFailedError: Exception in constructor: testGetIdeaDeps (java.lang.NoClassDefFoundError: Could not initialize class groovy.lang.GroovySystem
at org.codehaus.groovy.reflection.ClassInfo.isValidWeakMetaClass(ClassInfo.java:221)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassForClass(ClassInfo.java:191)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:236)
at ro.gd.idea.HelperTest.$getStaticMetaClass(HelperTest.groovy)
at ro.Test.<init>(Test.groovy)
at ro.gd.Test.<init>(Test.groovy)
at ro.gd.idea.HelperTest.<init>(HelperTest.groovy)
...
Here is my full code
I fix this question. the reason is "groovy.lang.GroovyRuntimeException: Conflicting module versions", for detail, following is my build.gradle
compile 'org.codehaus.groovy:groovy-all:+'
compile gradleApi()
I guess gradleApi() will auto "compile localGroovy()", and this groovy version is 2.3.6, but latest version is 2.4.3
I find this error message in one test report
the solution is to specify groovy version like following
compile 'org.codehaus.groovy:groovy-all:2.3.6'
and you check your groovy version with 'gradle dependencies|grep groovy'