How to integrate Galen reports in Jenkins - selenium

I've started to use Galen framework to test the layout of my website pages and I also have my other test, written in Selenium, integrated into Jenkins.
I'm using Java+JUnit+Maven and I would like to know if anyone has managed to integrate the Galen reporting into Jenkins and how.
Because for the moment I am using something like:
assertThat(layoutReport.errors(), is(0));
which tells me if there were errors in the tests but not where.
Thanks!
P.S. If someone with reputation could make the tag galen-framework so that we can group these type of questions, it would be great :D

In your case you could use Galen for generating HTML reports as it normally does when you run tests with it. Though you will have to manage the creation of GalenTestInfo objects.
Here is how the HTML report generation works. Imagine you have somewhere obtainAllTests method defined which returns a list of all executed tests.
List<GalenTestInfo> tests = obtainAllTests();
new HtmlReportBuilder().build(tests, "target/galen-html-reports");
Somewhere in your code you could create a GalenTestInfo and add it to some collection:
GalenTestInfo testInfo = GalenTestInfo.fromString("Here goes the name of your test");
Once you have done the layout checking and obtained LayoutReport object you could add this report to the report of the test. Here is how you can do it:
LayoutReport layoutReport = Galen.checkLayout(driver,
specPath, includedTags, null,
new Properties(), null);
testInfo.getReport().layout(layoutReport, "A title for your layout check");
You can find more insights in this project https://github.com/galenframework/galen-sample-java-tests. It has a basic setup for Galen tests in Java + TestNG + Maven. The reports in it are collected in a singleton GalenReportsContainer. There is also a reporter implemented in GalenReportingListener which takes all those tests from GalenReportsContainer and generates HTML reports.

You can see a full example for Java (TestNG and JUnit) and JavaScript here:
https://github.com/hypery2k/galen_samples.
I use the HTML Plugin together with Jenkins, see example here

Related

Grails compile .gsp to .html from gradle/command line

Is there any way that I can compile a gsp view into an html given a provided model from a groovy script without having to run all the Grails application?
The use case is that due to client demands we have to use Javascript/jQuery to create the front-end of the application. We've already had the architecture definition, but we're having issues creating integration front-end tests since our front-end composes of .gsp, javascript and css, all componentized.
For instance: Button may have a .gsp a .js and a .css associated to it.
Ideal solution to create front-end component integration tests: Have the .gsp compiled into html before the tests run so we can run the assertions in the *.test.js files. Since we don't need database, services or other instances to compile the .gsp, no need for the application to be running, avoiding the time to boot up the app.
Thanks in advance!
Next code should help you.
File gspFile = new File(BuildSettings.BASE_DIR, "grails-app/view/path/to/view/${viewName}.gsp")
This code will find gsp, you can find it by absoluteUrl
if(gspFile.exists()) {
def model = model((Class)scaffoldValue)
def viewGenerator = new GStringTemplateEngine()
Template t = viewGenerator.createTemplate(gspFile)
def contents = new FastStringWriter()
t.make(model.asMap()).writeTo(groovy.lang.Writer)
}
Writer you should find by yourself, think that it can be a stream to the file.
Didn't test it, but it should work :)

I want to run each .feature file as single TestNG test using Karate?

I want to run each .feature file as single TestNG test using Karate, how can I do it?
We are using karate to automate REST API's. We have custom listener which will record status of each TestNG test and other information to postgress DB.
One more way running by tags:
#CucumberOptions(tags = { "#getVersion" })
public class GetVersionTest extends KarateRunner {
}
Feature File:
#getVersion
Feature: Testing Rest API with Karate and Java
Scenario:
Given url 'https://......'
When method get
Then status 200
And match response contains '{version= x.xx.x}'
Did you try using the Karate TestNG support ? The documentation has details on how to use: https://github.com/intuit/karate#running-with-testng
As the developer of Karate I actually strongly recommend that teams don't use TestNG. My suggestion is that you use the new 'hooks' feature to call your custom Java code from Karate directly and you won't depend on TestNG or even JUnit.
If you still need a custom way of running, the TestNG support is actually a single class: KarateRunner.java. I really don't know if it runs each feature as a TestNG test or not since I am not a TestNG expert. But you should be able to create your own version of this Java code that does what you want and maybe contribute it back to the project.

How to write Java code using ther Jubula client API

I am new to the testing environment and have been searching for tutorials on Jubula client API.
Fortunately I have managed to find one, but still I am unable to launch my project. Till now I have installed the JUnit plugin in Jubula and configured the AUT on the standalone. Am I supposed to straight away make the JUnit unit test class or something else has to be done?
There is an FAQ on the Jubula Testing Portal about this:
http://testing.bredex.de/faqs/jubula-api-setup.html
You need to connect to the AUT first and map the objects from the app accordingly for usage and launch the test application.
Assign the variables or objects from the Swing or HTML and perform the required testing according to need.
For example:
public static final ComponentIdentifier btnFileExit = MakeR.createCI(Object from Jubula); //$NON-NLS-1$
Now, perform the required actions on the application and webpage, respectively.

Integration between Rally and Robot framework?

Does anybody know of an integration between Rally ALM and robotframework?
I'm looking for something that would log test results in robotframework back to Rally test cases.
With the pyral rally module for Python, seems like it could be fairly straightforward.
As far as I can tell there is nothing out there to do this-- but its pretty easy to do, only needing about 50 lines of python code for a simple integration that logs robot framework to Rally test case results.
In my case, I have it log results for any test who's name starts with a Rally test case id: (e.g. "TCXXXX My Test Name").
The trick is to user the RobotFramework listener API (See: Elapsed time and result of a test in variables) and pyral, the Rally python API. Key for my needs was to define an "end_test" listener:
def end_test(self, name, attrs):
match = re.search('^(TC\d+)\s*(.*)', name)
tcId = match.group(1)
testName = match.group(2)
if tcId:
tcr = self.__logTestCaseResultToRally(tcId, testName, attrs)
self.__cleanTestCaseState()
In robotframework, I include this listener file, which also has some additional methods to add attachments and other information like notes to a test result (these can be directly called as libraries in your robotframework file):
def addAttachment(self, attachment):
if os.path.isfile(attachment) and os.access(attachment, os.R_OK):
self.attachments.append(attachment)
This method simply saves the attachment path in the listener object so that when end_test() is called, it has access to the file names to attach to the rally test case. __cleanTestCaseState() zeros these out so they are cleared before the next test cast starts.
Actually, I've never used Rally!
But in my opinion, With robot framework, I like using Testlink for testcase management system & jenkin for CI control system :)
You can search in the internet for installation.
Hope it useful :)

PhantomJS, but not headless?

Is there a way to get a realtime view of what PhantomJS (or similar) is rendering?
I would like to develop my automation script while interacting with (or at least seeing a screencap of) the page it's targeted to.
No, there is no such thing. SlimerJS has the same API as PhantomJS, but runs the Gecko engine. You can see directly what is going on and run it headlessly with xvfb-run.
You will not be able to interact with it. You may want to use a screengrabber to record a video of the interaction when the tests are long and you don't want to run the test suite again if you didn't catch the problem in the test case.
The obvious way to debug PhantomJS scripts is to render many screenshots using page.render() and logging some objects to the console with
console.log(JSON.stringify(yourObj, undefined, 4));
with nice formatting.
Solution we use is an automatic screenshoting in case of exceptions, phantomJs will render the current page into a file that you can exam later .
That's for test execution phase.
When you writing the tests, just keep additional window open ("normal browser") with the application you trying to test and design the test according to it.
When the design is done, execute the test with phantomJS.
My Suggestion is to use logging alongside.
http://casperjs.org/
CasperJS is an open source navigation scripting & testing utility written in Javascript for the PhantomJS WebKit headless browser and SlimerJS (Gecko). It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar for doing common tasks such as:
defining & ordering browsing navigation steps
filling & submitting forms
clicking & following links
capturing screenshots of a page (or part of it)
testing remote DOM
logging events
downloading resources, including binary ones
writing functional test suites, saving results as JUnit XML
scraping Web contents
The solution to this problem is using the remote debugger:
--remote-debugger-port=9000
Using slimerjs for testing scripts with a browser is not advisable since it is based on gecko, which means the script might work on slimerjs and not on phantomjs or viceversa.
take a look at this guide for more info...
https://drupalize.me/blog/201410/using-remote-debugger-casperjs-and-phantomjs