Hello there are tests written on Java + cucumber
The structure is as follows:
https://i.imgur.com/moLVY6L.png
The main question is how to run this tests not from the IDE, say from the console or even wrap it all in jar file
The problems encountered are that you need the main class to create a jar,
It seems as there is a certain java cucumber.api.cli.Main - but how to use it I do not understand. Either way, there's probably a way to run this just from the command line. Please tell us how to do it?
You can download Maven with following terminal script :
$brew install maven
After brew installation, you need to go to the project directory which includes pom.xml file in terminal :
$cd /path/of/your/project
And finally you can run following command to run your tests :
$mvn clean test
You can try the below on command prompt.
java -cp "E:\Workspace\CucumberProj\Jars*;E:\Workspace\CucumberProj\bin" cucumber.api.cli.Main --glue stepDefination E:\Workspace\CucumberProj\Feature\Login_Test.feature
Related
I have a Java Code where I am able to run it on Intellij using custom configuration. The configuration has following attributes :-
module : java 8 (Oracle OpenJDK 1.8.0_321)
classpath : -cp XYZ.main()
main : com.ABC.XYZ.ManageTraffic
CLI arguements : server XYZ.yml
But when I try to run the jar that was build using gradle from terminal , it gives me Error , could not find or load main class com.ABC.XYZ.ManageTraffic
So far I have tried the following things looking at other solutions at Stackoverflow , still getting the same error
java -jar ques.jar
java -jar ques.jar com.ABC.XYZ.ManageTraffic
java -cp /build/libs/ques.jar com.ABC.XYZ.ManageTraffic
Just to cross check , I unzipped the creataed jar and found that com.ABC.XYZ.ManageTraffic class file is available there , still getting error. What could be the issue?
Run it from the IDE, and while it is running, try to get the command used by the IDE from the process list.
not sure what OS you are using but something like this should work on linux/mac:
ps -ef | grep java
After you have the command you can try to understand why its not working for you, or just use that command
Just want to add how I managed to run it. I created a new shaded jar file of the same application. refreshed its dependencies and now it works. I am yet to find out how creating a shaded jar instead of normal jar helped. Right now the only reason I could figure out is there may be version clashes with some dependencies but I wonder how it could throw could not found main class error.
Anyways , then I ran the file with the following command from terminal:
java -jar ./build/libs/ques-shaded.jar server XYZ.yml
I have intellij java project which I run from IDE.
When I run simple java command to run project I get error -
Can any one tell me what is issue here?
Thanks
Nilesh
Please add the .java extension while running the javac command. Something like below:
javac ..... filename.java
Trying to do some automated test. I have used below commands to execute the junit file (RunnerTest.java) in command line, getting an error as "could not find class"
Command line commands:
C:\Users\username\workspace\MavenCucumberPrototype\src\test\java\com\cucumber\MavenCucumberPrototype>javac -cp "C:/cjars/*" MavenCucumberPrototype/*.java
C:\Users\username\workspace\MavenCucumberPrototype>java -classpath C:/cjars/junit-4.12.jar org.junit.runner.JUnitCore src.test.java.com.cucumber.MavenCucumberPro
totype.RunnerTest
Maven Project structure
MavenCucumberPrototype
-/src/main/java
-com.cucumber.MavenCucumberPrototype
-/src/test/java
-com.cucumber.MavenCucumberPrototype
-postconn.java
-RunnerTest.java
-Steps.java
-/src/test/resource
-myfeature.feature
When I run Maven projects from a command line, I usually do
mvn clean install
or whatever lifecycle phase I want to execute. In your case, it might be sufficient to do
mvn test
The only imprtant thing to notice is that you must execute the command in the same directory as the pom.xml resides.
The error you recieve is nost likely due to a classpath that doesn't contain what you expected.
I've been developing a test suite for a provided "solution.jar" file in Eclipse for an assignment. I have a test suite which I can run in eclipse no problem, but the assignment requires that I run it from the command line, but I've no idea how to do this.
I've tried:
java -cp .;/usr/share/java/junit.jar org.junit.runner.JUnitCore AllTests
but it just said Error: could not load main class org.junit.runner.JUnitCore
Could someone help me out?
you can use maven build and then from command prompt fire this command
mvn test
It will run test case associated with your project.
I wrote a little script to compile the test version of a .jar and put it out on my test server.
cd /home/myusername/workspace/td-daily-budget
mvn -P test clean compile package
scp /home/myusername/workspace/td-daily-budget/target/td-daily-budget-1.0.jar myusername#666.666.666.666:/home/myusername/bin/td-daily-budget.jar
When I run it I get a jar file whose config.properties contains things like
db.connect.string=${db.connect.string}
but when I run mvn -P test clean compile package all by itself in the terminal window I get a jar file put together with the test profile, e.g. config.properties contains db.connect.string=[what I expect it to be for the dev profile]. Why does the same command ignore the profile when run inside a script?
Thanks in advance!
[edit/addendum]
Tried changing the script line to
/bin/bash mvn -P env-test clean package
(it's bash, not Windows, so there's no call command, but using bash to call another script seems to make sense to me) but just got
*Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
*
I think calling it as an external process mucks up Maven's understanding of where it's supposed to be executing.
[2nd edit/addendum]
Removed the redundant compile from the command.
It now appears that this is actually an intermittent problem. The filtering almost always fails when mvn -P [pretty much ANY profile] clean package runs from inside the bash script, but if I run it standalone from the command line repeatedly it will work eight or nine times and then fail several times in a row. I cannot find any pattern to this at all.
As soon as I discovered this I thought I knew the culprit: The m2e plugin for Eclipse was "helping" me in the background every time it saw files changing. So I excitedly shutdown Eclipse thinking the problem would vanish instantly, ran mvn -P env-test clean compile package several times in a row--it worked the first few times and then failed. /headdesk
[edit/addendum]
Removed the space between the -P and the profile name. Still no luck.
I think you need to run the mvn in your batch with "call" command, so sth like:
call mvn -P test clean compile package
The reason is, that mvn is a batch file itself and thus needs to be invoked with "call".
Please give it a try!
Bluddy
Are you allowed to have a profile with the same name as a phase? Try renaming your "test" profile to "env-test" and use:
mvn -P env-test clean package
EDIT:
If you believe it has to do with calling it from a script, try adding a bash declaration at the top:
#!/bin/bash
cd /home/myusername/workspace/td-daily-budget
mvn -P env-test clean package
scp /home/myusername/workspace/td-daily-budget/target/td-daily-budget-1.0.jar myusername#666.666.666.666:/home/myusername/bin/td-daily-budget.jar
Credit Bluddymarri for suggesting the batch script equivalent.