Maven Test Automation Project - maven

I have a maven test automation project developed using selenium and testng. This is what I am doing with my framework:
1.I have main class in src/main/java and within the main class I trigger methods to dynamically create and run the testng xml.
2.The tests to be run are determined from the XMLFlag.xls sheet and test data for the tests is set in TestNG.xlsx sheet in src/main/resources.
3.I have successfully created a jar of my entire package.
Since I have put my Test Data sheets(TestNG.xlsx and XMLFlag.xls)under src/main/resources, these Test data sheets get packaged within the jar.
But ideally, I would like to run my test scripts for different sets of test data and see if the scripts are successful.
for example: I would like to run my scripts with ,say, username:abcd and password:1234 for the first time and then run the same set of scripts with username:efgh and password:9876.
But with my Test data sheets packaged within the jar I will not be able to achieve the above scenario since I cannot edit the test data sheets.
So let me say to overcome the above problem:
1.I put my Test data sheets in src/test/resources and not src/main/resources and then create a jar.
But when I do this and try to run the jar,
I get an error message:
.\src\test\resources\XMLFlag.xls (The system cannot find the path specified)
This, I believe, is because the Test data sheets get placed in test-classes folder under target folder and not within the jar.
To put it in simple words:
i. I want the test data sheets to be outside my jar, so that it can be edited and test scripts can be run based on the users requirement.
ii.If the test data sheets are outside my jar and everything else within my framework is dependent on test data information(ie.test scripts, testng.xml) and is packaged within the jar, my jar would not run.
Is there a way to avoid this error and accomplish what I want to do?
Or should I restructure my entire framework??
Kindly help me out.

How about passing the Test Data sheets as program arguments when you're executing your jar?
That is,
java -jar c:/path/to/your/jar c:/path/to/your/testng.xlsx c:/path/to/your/xmlflag.xlsx
and then just in your main method, read the file names and their content such as
File testNgXlsxFile = new File(args[0]);
and pass the information from the files to your framework.
Is that possible?

Related

Directory Structure for Cucumber + Maven + POM project under SRC & TEST folder

I am looking for effective project Structure to manage it with POM, Cucumber(Feature and Step definition Files) under Maven's Src & test folders.
What should be correct way to manage? Where to use Maven's src and test folder.
Please Share. Thanks in Advance.
Project Structure for a Maven project with Cucumber + POM
base package contains Page object initialization class where it can be extended to all the page classes
browser package contains the browser factory class which contains the methods to invoke Chrome, Firefox, IE etc.,
custom Exception package used to throw the custom messages
features package contains the feature files
pages package contains the page objects classes like login, home page with the relevant web elements and methods
resources package contains the driver information, test data information, xml configuration, property file etc.,
runner package contains the runner classes which is created in manual. Otherwise we can refer the same package for dynamic runner class creation in maven parallel plugin dependency.
steps package contains the step definition for each specific pages.
utils package contains the utility classes like common utility, selenium utility, excel utility etc.,
Under target
cucumber - parallel contains the parallel execution report
cucumber-reports contains the normal execution report
generated-test-sources contains the dynamic runner class files which is created during the run time for parallel execution.
feature files are not java code and should be in src\test\resources folder

TestNG run/debug from IDEA cannot load main class files

I have inherited some Selenium TestNG tests which I can run with no problem via 'mvn test' but when I try to run/debug inside IDEA I receive an instant error:
Error: Could not find or load main class Files
In my own projects I have xml test suites and I keep my /main empty. I can run tests easily with either command line and inside IDEA.
However, this project structure is different from one I developed myself. Here I have test classes in /test/java directory but all PageObject classes, helpers and such in /main/java. There is no xml suites (I am not sure how it is even working and if it is possible to run certain test class). See picture below.
The question is: how to make those tests run/debug inside IDEA?
As dumb as it sounds I have been passing a parameter to Firefox binary within '' instead of "" resulting
-Dbinary='C:/Program Files/...'
to be interpreted as
-Dbinary =C:/Program
with remaining string treated as class.

Updating KIE Execution Server container with updated rules file

This is where I am at:
I am using Drools 6.2 and calling drools engine remotely via KIE Execution Server running on jboss.
I used workbench to create my initial drl file and fact objects and then used Build & Deploy option of workbench to create and deploy the jar file. I then created the container using the jar file and got the end point that I am using to access the rule engine from my client application. At this point every thing is working fine and I am able to fire the rules remotely.
My requirement is to modify the rules file (.drl) outside the workbench, let's say in notepad and update the container with this new drl file. Is there an easy way to create the jar file programmatically that i can deploy to the central maven repository? I can then run the KIE scanner to look for the latest version of my jar file and automatically update my container. Or is there another recommended way to update the running container with an updated .drl file?
My client application is not in Java so I am not looking for an integrated solution where I can write java code to create the knowledge base and use kie builder to build the drl file.
Is there an easy way to create the jar file programmatically that i can deploy to the central maven repository?
2 options that I can think of, one "easy" and one not so much:
Option 1
Use Maven and the maven drools plugin (you don't have to write Java code, just create your maven project and run mvn package to get a jar. See here: https://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html/KIEChapter.html#KIEModuleIntroductionBuildingIntroductionSection
Option 2
A JAR file is simply a zip file with a specified structure. That means that you should be able to update your whatever.drl file, put it in the directory structure that the KIE server expects and deploy it.
For instance, create a directory structure like:
META-INF/kmodule.xml
com/site/project/drools/rules/myrule/SomeRule.drl
Zip those files into somefile.jar and deploy it.

ActiveJDBC Instrumentation: Unable to instrument the model classes which are in Jar

I am using activejdbc 1.4.9. I created one jar (using maven) which has two ActiveJDBC Model Classes. I added the jar to the application. Application has three more model classes. When I compile and try to run the application (gradle based), activejdbc is instrumenting only 3 classes which are in application but not instrumenting the classes which are in jar. When I try to write the data into the two models which are in jar, It is throwing exception as
org.javalite.activejdbc.DBException: Failed to retrieve metadata from DB. Are you sure table exists in DB ?
Now I have certain doubts. Please help me to resolve and understand few things.
How instrumentation happens ?
When we create a jar, will it include instrumented classes ?
Why it is throwing this error ?
It is throwing this error in case classes have not been instrumented. This means that before placing your model classes into a jar file, you need to instrument them. Does not matter which build method you use though. This http://javalite.io/instrumentation explains what is instrumentation and how to do it. Instrumentation does not create jars, it merely adds some byte code into your classes. In all scenarios you need:
Write code :)
Compile
Instrument
after this, you can do any of the following:
run app using class files in the file system
package class files into jar file and use that on your classpath
package jar file into a larger app (WAR, EAR, RAR, etc.) and deploy your app
making sense?

where to place the external java jar when deploy birt report?

I use some java code to retrieve data from database, and export the java code as runnable jar, placed the jar in eclipse\plugins\org.eclipse.birt.report.viewer_3.7.1.v20110905\birt\scriptlib, then in the birt report I can use the jar to get the data. In eclipse all goes smoothly, I can see the correct data in preview.
but when I upload the myreport.rptdesign to the server, I don't know where to place the jar then the report can refer to it. In our team, they use grails to deploy birt report, all I need to do is upload the rptdesign file to a specified server directory, when there's no java jar to refer, that's enough. but when I need to refer to a java jar, I do not know how to deploy.
Please help and thanks a lot.
=========================================================
here is answer of my question. Just put the jar in directory lib of grails. It works!
Did you try to put the jar file in the server/lib directory? What kind of application server are you currently using?

Resources