I'm just starting out writing out Java tests to automate native Android apps using Appium and JUnit. Getting a NoClassDefFound error even if the required jars are on class path in Eclipse GUI. I've narrowed it down to this line :
driver = new RemoteWebDriver(new URL("appium typical server url here"), capabilities);
The following jars are in the Java build path in Eclipse under Libraries: java-client-1.5.0.jar, selenium-java-2.42.2.jar, selenium-java-2.42.2-srcs.jar, along with JUnit
Here is my complete code:
package com.chinmay.automation;
import java.io.File;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ChessTest {
private WebDriver driver=null;
#Before
public void setUp() throws Exception{
File appDir= new File("/Users/csathe/Desktop/Java");
File app = new File(appDir, "ChessFree.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.3");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("device", "android");
capabilities.setCapability("app-package", "uk.co.aifactory.chessfree");
capabilities.setCapability("app-activity", "ChessFreeActivity");
capabilities.setCapability("app", app.getAbsolutePath());
driver= new RemoteWebDriver(new URL("//appium typical server url here"), capabilities);
}
#Test
public void testFirst(){
// do something
}
#After
public void tearDown(){
// driver.quit();
}
}
If I run this using JUnit with that line commented, it runs fine (does nothing however).
The stacktrace with the line:
java.lang.NoClassDefFoundError: com/google/common/base/Function
at com.chinmay.automation.ChessTest.setUp(ChessTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 25 more
Running this one class outside JUnit leads to the same error.
This error clearly indicates that any jar dependency is missing from the build path.
Please add all the jars available here to the class path :
http://selenium-release.storage.googleapis.com/2.42/selenium-java-2.42.2.zip
OR
Download the Selenium-server-standalone.jar from here and add to the class path:
http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar
You can retry by selecting mentioned JAR files under Order and Export tab. Can be accessed in the way mentioned below:
Right click on the project -> Build Path -> Configure Build Path -> Order and Export -> Select required jars (e.g. Selenium,java etc.) and click on OK.
Lemme know if this works for you!
Related
This question already has answers here:
Module error when running JavaFx media application
(2 answers)
Closed 8 months ago.
So i'm using IntelliJ and I built my application using JavaFX.
But when i'm starting my main:
package fr.agglomistral.programme;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import fr.agglomistral.classedao.BusDAO;
import fr.agglomistral.classemetier.Bus;
import fr.agglomistral.outils.ConnexionMysql;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fr/agglomistral/vues/Login.fxml"));
primaryStage.setTitle("AggloMistral");
primaryStage.setScene(new Scene(root,1680,1020));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
BusDAO busDAO = new BusDAO();
Bus bus = new Bus("MARQUE", "IMMAT", 12, 12);
busDAO.create(bus);
ConnexionMysql.disconnect();
}
}
I get the following errors, and I don't get where those come from...
Everything was working perfectly until I switched branches on github and had to set all the configurations all over again...
This is a picture of my configuration below:
The errors I'm getting:
"C:\Program Files\Java\jdk-17.0.2\bin\java.exe" --module-path C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib --add-modules=javafx.controls "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.1\lib\idea_rt.jar=3220:C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\lilian.carion\Documents\Agglo-Mistral\classes\production\Agglo-Mistral;C:\Users\lilian.carion\Documents\mysql-connector-java-8.0.29\mysql-connector-java-8.0.29.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx-swt.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.web.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.base.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.fxml.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.media.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.swing.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.controls.jar;C:\Users\lilian.carion\Documents\javafx-sdk-18.0.1\lib\javafx.graphics.jar;C:\Users\lilian.carion\Downloads\javafx\javafx-swt.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.web.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.base.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.fxml.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.media.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.swing.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.controls.jar;C:\Users\lilian.carion\Downloads\javafx\javafx.graphics.jar;C:\Users\lilian.carion\Downloads\jsch-0.1.55.jar;C:\Users\lilian.carion\.m2\repository\junit\junit\4.13.1\junit-4.13.1.jar;C:\Users\lilian.carion\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter\5.8.1\junit-jupiter-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.8.1\junit-jupiter-api-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\lilian.carion\.m2\repository\org\junit\platform\junit-platform-commons\1.8.1\junit-platform-commons-1.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.8.1\junit-jupiter-params-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.8.1\junit-jupiter-engine-5.8.1.jar;C:\Users\lilian.carion\.m2\repository\org\junit\platform\junit-platform-engine\1.8.1\junit-platform-engine-1.8.1.jar fr.agglomistral.programme.Main
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x7dff628f) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x7dff628f
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2135)
at fr.agglomistral.programme.Main.start(Main.java:22)
at javafx.graphics#18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics#18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics#18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics#18.0.1/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#18.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#18.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
... 1 more
Exception running application fr.agglomistral.programme.Main
Process finished with exit code 1
I had similar issue. For me solution was to
add following configuration :
--add-modules javafx.controls,javafx.fxml
insted of just
--add-modules javafx.controls
I'm setting up my first program for a class and I'm stuck on why my program won't run trying to debug. What do I need to do to debug this error?
I've tried to add libraries but this didn't seem to work.
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.awt.*;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try{
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
primaryStage.setTitle("My First JavaFX GUI");
Button button= new Button("Submit Answer");
StackPane layout= new StackPane();
layout.getChildren().add(button);
Scene scene1= new Scene(layout, 300, 250);
primaryStage.setScene(scene1);
primaryStage.show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
This is the error my Run Console is giving me:
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x41b2844d) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x41b2844d
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at Main.start(Main.java:20)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application Main
Process finished with exit code 1
I expect this to run, but it won't and I'm really stuck on where to act.
Thanks for taking a look ! Any help is appreciated :D
Add the modules to your modulepath. Most projects just need javafx.controls and javafx.fxml but check to see if you need other packages.
Run > Edit Configuration > VM Options >
--module-path /path/to/javafx-sdk-13/lib --add-modules javafx.controls,javafx.fxml
Like so:
Additionally make sure that your SDK and project language level is properly setup in:
File > Project Structure > Project
Make sure that your OpenFX library is added (either manually or with something like Gradle) in:
File > Project Structure > Libraries
And one last thing, I don't think you meant to import java.awt.*; in your code.
Exception in Application start method:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at edu.citytech.view.EmployeeMain.start(EmployeeMain.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application edu.citytech.view.EmployeeMain
Here's the class with the main method, EmployeeMain.java:
package edu.citytech.view;
import edu.citytech.utitlity.GlobalVariables;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class EmployeeMain extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("EmployeeView.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
// * new *
primaryStage.setResizable(false);
primaryStage.setTitle("Employee List");
primaryStage.getIcons().add(new Image(EmployeeMain.class.getResourceAsStream("People.jpg")));
}
public static void main(String[] args) {
if (args.length > 0) {
GlobalVariables.portNumber = (Integer.parseInt(args[0]));
}
launch(args);
}
}
And what fixes this is adding a space to any of the files and saving it, then restarting the Eclipse IDE, and running it again from the IDE. What breaks it is when I run mvn clean and mvn install, and then running the jar file it created. Everyone in my class is having this problem, and the teacher has no idea how to fix it. It just works for some people and it doesn't for others. However this time, this isn't working no matter what I try. Only works in the IDE until I use maven to create a jar. Then it won't work until I modify and save a file, and then restart the IDE. Everything is named properly and it just works and doesn't work randomly. Is this an IDE problem or a project problem?
What can I do so that I can make a jar file that works when it's run?
I figured out how to get it to work. Really annoying but really simple. I'm going to write it here for anyone who is probably finding this page through a search engine.
Right click on project folder > Maven > Update Project...
Update selected project
Right click the project folder and run in local terminal
mvn install
And DO NOT DO MVN CLEAN
3 issues possible
it sounds like you need the IDE to recompile the code for it to work again in eclipse too? not sure why that would be actually unless its the java version used ...
eclipse usually rebuilds given any change (e.g. your space added to file)
is your eclipse IDE and maven compile are using the same java version?
delete your ./target directory and
add this to maven pom.xml to make sure you're using the right java version (e.g. for java 1.8):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
include the file in the jar build
Also the copy your EmployeeView.fxml should be in src/main/resources and the file wont be making it into your jar file unless you include:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
That code won't work within the jar file at runtime see these answers:
How to reference a resource file correctly for JAR and Debugging?
and update your code to use getREsourceAsStream e.g. here's a method i use:
public void load(String resource, HashSet<String> hashset) {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is_awl = classloader.getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is_awl));
String line;
try {
while ((line = reader.readLine()) != null) {
hashset.add(line.trim());
}
} catch (IOException e) {
System.err.println("LexicalFeatures can't initialise:"
+ resource + " hashset: "+ e.getMessage());
e.printStackTrace();
}
}
I have been trying to write a integration test for a small Spring boot Project that I have written but for some reason seem unable to get integration tests to work. Here is what I am trying to do:
package au.azzmosphere.integration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
#RunWith(SpringJUnit4ClassRunner.class)
#SpringBootTest(classes = {IntegrationTestConfiguration.class})
public class TestIntegration1 {
#Test
public void testDummy() {
}
}
the configuration class has the following:
package au.azzmosphere.integration;
import au.azzmosphere.configuration.RobotAppConfig;
import org.springframework.context.annotation.Configuration;
#Configuration
public class IntegrationTestConfiguration extends RobotAppConfig {
}
The code is consistently getting the following errors when I try to run the Integration Test from IntelliJ
14:54:01.537 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class au.azzmosphere.integration.TestIntegration1].
14:54:01.542 [main] INFO org.springframework.test.context.TestContext - #ContextConfiguration not found for class [class au.azzmosphere.integration.TestIntegration1].
14:54:01.549 [main] INFO org.springframework.test.context.TestContextManager - #TestExecutionListeners is not present for class [class au.azzmosphere.integration.TestIntegration1]: using defaults.
From gradle the following is returned
au.azzmosphere.integration.TestIntegration1 > initializationError FAILED
java.lang.NoClassDefFoundError
Caused by: java.lang.ClassNotFoundException
The full stack trace is
java.lang.NoClassDefFoundError: org/springframework/transaction/TransactionDefinition
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:102)
at org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(TestContextManager.java:171)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:108)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:107)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:79)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.TransactionDefinition
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)
... 23 more
Worked it out, :) The problem was that I did not have any TransactionDefinition defined because I didn't use it. The default SpringBoot annotation attempts to inject it. The answer was to use #TestExecutionListeners({DependencyInjectionTestExecutionListener.class}) which overrides the defaults and gets things going.
I've set up an Android phone emulator that contains the app komoot which I seek to perform testing on using Appium and IntelliJ to write the test. I'm working out of a macbook air. After having: started up my Android emulator, launched the Appium server, and written my test (in java) in IntelliJ, I run my test and it produces the error seen in the attached pictures. I have also copied/pasted my simple testing script and the error log messages that result from running my test "komootTest".
I am confused about the error being thrown. As per line 44 I am instantiating a variable that is an element in komoot (the login button) with the correct id. Why would it throw a null exception in this case? I can provide more details as needed, thank you!
error log image
komootTest.java code image
Here is the code for my test komootTest.java:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import java.net.URL;
public class komootTest
{
AppiumDriver driver;
#Before
public void setUp() throws Exception
{
//set desired capabilities and specify device name
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "BigBrother Emulator");
//capabilities.setCapability("appPackage", "de.komoot.android");
//capabilities.setCapability("appActivity", "com.google.android.gms.auth.api.signin.internal.SignInHubActivity");
//establish a connection with the server
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
#After
public void end() throws Exception
{
//kill connection with server after test has been executed
driver.quit();
}
#Test
public void logInHereButton()
{
//reference UI element by ID and click it
WebElement logInHere = driver.findElement(By.id("de.komoot.android:id/textview_login"));
logInHere.click();
}
}
Here is the error message when I run komootTest.java:
[TestNG] Running:
/Users/coracoleman/Library/Caches/IdeaIC2016.1/temp-testng-customsuite.xml
java.lang.NullPointerException
at komootTest.logInHereButton(komootTest.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:74)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
===============================================
Default Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
Process finished with exit code 0
Problem solved! I rewrote the project by beginning a new project in IntelliJ, instead selecting Maven versus Java. I then imported the dependencies in the pom.xml file as I have included below. I had not fully specified my capabilities and I had not included my dependencies in the pom.xml file. I made sure to include the java-client-4.0.0.jar and selenium standalone server .jar file in my Project Structure/Project Settings/Library.
Here are the contents of 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>com.example</groupId>
<artifactId>AppiumTest2</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Here is the simple code that I was able to successfully run:
package scenarios;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class AndroidSetup
{
WebDriver driver;
#Test
public void setUp() throws Exception
{
//create object of DesiredCapabilities class
DesiredCapabilities capabilities = new DesiredCapabilities();
//set android deviceName desired capability
capabilities.setCapability("deviceName", "BigBrother Emulator");
//set browserName desired capability
capabilities.setCapability("browserName", "Android");
//set android platformVersion desired capability
capabilities.setCapability("platformVersion", "5.1");
//set android platformName desired capability
capabilities.setCapability("platformName", "Android");
//set android appPackage desired capability
capabilities.setCapability("appPackage", "de.komoot.android");
//set android appActivity desired capability
capabilities.setCapability("appActivity", "de.komoot.android.app.InspirationActivity");
//set appium server address and port number in URL string
//this will launch app in emulator
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//click on LogIn button
driver.findElement(By.id("de.komoot.android:id/textview_login")).click();
driver.quit();
}
}
Here is the resulting execution log:
[TestNG] Running:
/Users/coracoleman/Library/Caches/IdeaIC2016.1/temp-testng-customsuite.xml
===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0