Selenium Netbeans Project to runnable jar - maven

I'm developing tests using junit, maven and Selenium inside Netbeans IDE. I don't have any main class inside the src folder. I can run the tests easily from the IDE, but I'm trying to pack all of them into one jar file (so I can later use with linux cron and schedule daily tests). I've searched around the web but so far my search hasn't been successful. Can anyone point me in some enlightment path please?

Add a class in your project that contains the main function and accepts test class names as parameter.
class RunTest
{
public static void main(String args[])
{
// Run the tests contained in the classes named in the args.
org.junit.runner.JUnitCore.main(args);
}
}
Now create the jar using maven including all the dependancies in pom.xml. you will be able to run tests through jar by passing test class names
for more information read this

Related

JUnit class is not displayed in JMeter

I have created a Java project with 1 class containing 2 simple tests, exported as jar and added the jar in my JMeter JUnit folder, now after restarting the JMeter i don't see my class in JMeter even after selecting Annotation 4 option.
This is my class:
package print;
import org.junit.Test;
public class PrintClass {
#Test public void test() {
System.out.println("Hello World..!");
}
}
Consider the following checklist:
Your JUnit test class should have either empty constructor or constructor taking a single string as an argument. Other options are not supported
You should place your .jar file(s) under "lib/junit" folder of your JMeter installation
If there are any dependencies you need to put them somewhere in JMeter classpath as well
JMeter restart will be required to pick the .jars up
In case of any problems first of all check jmeter.log file (normally it lives under "bin" folder of your JMeter installation and contains enough troubleshooting information)
See How to Use JUnit With JMeter article for more details.
Even I faced same kind of issue then I added the dependency jars to the lib file.
Make sure you copy these files at this location -> apache-jmeter-5.1.1\lib
1.Selenium webdriver jar file (selenium-server-standalone)
2. Junit4 Jar file (junit4)
Make sure you add Jar file from eclipse or any IDE to this location -> apache-jmeter-5.1.1\lib\junit
1. Jar file which contains the automation selenium code (Using Junit)
Restart Jmeter and continue which the normal process of adding thread group and adding Junit sampler etc...
This resolved my issue and I was able to run my scripts on Jmeter.
In eclipse make sure that you create a JUnit class, not just the class and add junit annotations to this, even i was facing the same issue, it got resolved when i was created a JUnit class and then uploaded my project in JMeter
Did you put the jar in :
/lib/junit
Check you jar by running below command to see if it is ok:
jar -tvf <your jar>
And its dependencies as described in:
JUnit test classes not showing up in JMeter
See this for more details:
http://jmeter.apache.org/usermanual/junitsampler_tutorial.html

I want to run many SOAPUI project xmls using Gradle script, in Linux

I want to run the SOAPUI project xmls using Gradle script. The GRADLE script should read the project xmls from soapuiInputs.properties file and run automatically all. Please guide me step by step how to create Gradle script to run the SOAPUI projects in Linux server.
Note: We use SOAPUI version 5.1.2.
Probably the simple way is to call the SOAPUI testrunner directly from gradle as Exec task, like you can do from cli.
In gradle you can define the follow tasks (Note that I try it on windows but to do the same on linux as you ask simply you've to change the paths):
// define exec path
class SoapUITask extends Exec {
String soapUIExecutable = 'C:/some_path/SoapUI-5.2.1/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// execute SOAPUI
task executeSOAPUI(type: SoapUITask){
// simply pass the project path as argument,
// note that the extra " are needed
soapUIArgs = '"C:/location/of/project.xml"'
}
To run this task use gradle executeSOAPUI.
This task simply runs a SOAPUI project, however testrunner supports more parameters which you can pass to soapUIArgs string in executeSOAPUI task, take a look here.
Instead of this if you want to deal with more complex testing there is a gradle plugin to launch SOAPUI project, take a look on it here
Hope this helps,

How to work with JMeter and Junit

I am very new to JMeter
I am trying to use Junit Request sampler in JMeter.In my project we have a class called PayloadProcessorTest.java. from these class methods i am calling some other class methods.It has lot of dependencies
How can i create jar file for PayloadProcessorTest.java with dependencies
I saw many examples for JMeter with Junit Request sampler. But, those all examples are independent classes
Can any one please help me
There are several ways of creating a .jar file:
Using Maven
Using Ant
Using Eclipse
.jar files are basically ZIP archives so you can just compile your PayloadProcessorTest.java and put resulting PayloadProcessorTest.class into /lib/junit/test.jar file keeping package structure. After restart JMeter will pick up the class. Don't forget to add any 3rd-party jars used in PayloadProcessorTest (if any) to JMeter classpath. For more information check out How to Use JUnit With JMeter guide.
If you want to get the dependencies with Maven you can run
mvn install dependency:copy-dependencies, which will create a folder inside your target folder called 'dependency' filled with the dependencies. To speed this up you can add the command as External Tool in Eclipse using Run > External Tools > External Tools Configurations.
Or if you want to use Eclipse you can choose File > Export > Java > Runnable JAR file and select the option 'Copy required libraries into a sub folder next to the generated JAR'. However to do this you will need to add a main class, and run it once as a Java Application before trying to export. The Main class can be empty or not.
package test;
public class Main {
public static void main(String[] args) {
}
}
Really, it depends what packaging capabilities you have.
You need to compile your classes in one or more jars, and then put them in the %JMETER_HOME%/lib/ext folder.
Or use maven to do it all for you.

pax-exam: are the tests running inside of a bundle?

I have a Maven project that builds a very simple OSGi bundle. No activator; it's only job is to deliver some shared code to an OSGi project. I want to test that I have got the dependencies all set up and embedded correctly.
So, I've added pax-exam to the situation.
I'll paste a unit test shell at the end of this. Is my #Test method in fact running inside of a bundle that is in turn depending on the bundle built in my project?
#RunWith(PaxExam.class)
#ExamReactorStrategy(PerClass.class)
public class CommonBundleTest {
#Configuration
public Option[] config() {
return options(
// this is the current project's result artifact
mavenBundle("com.basistech.osgi", "rosette-common-java-lib"),
junitBundles()
);
}
#Test
public void atest() {
}
}
Are the tests running inside of a bundle: yes
Pax Exam creates a TinyBundle for the Unit test itself. But it doesn't add extra dependencies on any bundle declared in the config method.
If you want to make sure those packages are imported you can alter the way the TinyBundle is build.
#ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
// makes sure the generated Test-Bundle contains this import!
probe.setHeader(Constants.IMPORT_PACKAGE, "*,your.extra.package");
return probe;
}
The so-called probe bundle created by Pax Exam on the fly contains all classes from the src/test/java folder containing your test class. The probe bundle manifest has a Dynamic-ImportPackage: * header, so it is not normally required to add explicit imports by means of a probe builder.
Any bundles required by your tests must be provisioned by a configuration option in the #COnfiguration method.
If you want your test to fail immediately when a bundle does not resolve, you can set a config property:
pax.exam.osgi.unresolved.fail = true

calling jar from another jar

i am making a java swing Gui which i will convert to a jar file. also i have 3 other jar files which i am calling through my gui. But when i convert my gui and other three jar files into one, an error is shown the the 3 jar files are not found/file not found exception.
i am usin classLoader to get path of my 3 jars inside my final jar
my code:
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Testing");
ClassLoader cl=this.getClass().getClassLoader();
String k=cl.getResource("jar_1.jar");
Runtime.getRuntime.exec("java -jar "+k );
similary other 3 jar files..
so what i think is that when i convert my gui and all the other three jars into one jar then the path of the 3 jars is not correct.
Thats not how you call jars.
If they are loaded correctly you have complete control of them within your main class / jar file. and you can just import them as you would with any other import.
When they are imported you can call the methods you like (if you just want to run it - just call main() )
You should be using the class path
Class-Path: jar1-name jar2-name directory-name/jar3-name

Resources