Sunday, 6 March 2016
Sunday, 21 February 2016
Galen Framework for RWD/Layout/Cross Browser Automation
Sunday, 20 September 2015
Cobertura War Instrumentation and Coverage in a web application
In a day to day work we typically run our tests and presumably check that we are getting the expected results.Our tests may all pass with flying colours, but if we've only tested 50% of the code, how much confidence can we have in it? So a step ahead would be to ensure how much of the application code is exercised by our tests which ensures the quality of the tests that we typically run and thus code coverage comes into picture.
What is Code Coverage?
Code Coverage is a measurement of how many lines/blocks of the application code are executed while the automated/unit tests are running.
Though code coverage is a white box testing methodology(as it requires knowledge of and access to the code itself rather than simply using the interface provided),
we might come across situations where we need to analyse/collect code coverage metrics for our functional test cases.This post briefs the need of code coverage,coverage analysis,instrumentation for functional test cases with an example using Cobertura.
How is Code Coverage achieved?
Code coverage is collected by using a specialized tool to instrument the binaries to add tracing calls and run a full set of automated/unit tests against the instrumented product. A good tool will give you not only the percentage of the code that is executed, but also will allow you to drill into the data and see exactly which lines of code were executed during particular test.
There are many coverage tools in market for Java Code Coverage -Cobertura,Clover,Emma,Jcoverage.In this post we will generate coverage metrics using cobertura -one of
the most widely used java coverage tool as it has edge over other tools.
- Open source Java tool.
- Can be executed from simple ant build script.
- Instruments Java bytecode after it has been compiled.
- Can generate reports in HTML/XML by class name, percent of lines covered, percent of branches covered, etc.
- Shows the percentage of lines and branches covered for each class, each package, and for the overall project.
What is instrumentation?
Instrumentation is all about manipulating the application code by injecting reporting code into strategic positions. In fact, the art of instrumentation falls in either of the two: class instrumentation and source instrumentation. Not surprisingly, the difference is that class instrumentation injects the reporting code directly into compiled .class files while source instrumentation creates an intermediary version of the sources which are then compiled into the final, source-instrumented .class files. Most of the code coverage tools will follow either of these instrumentation techniques.
For this post we are using a sample war file from (https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/)for instrumentation wherein for real time scenario,this should be replaced with your application war file.
Sample Cobertura War Instrumentation and Coverage in a web application
PreRequisite:- Tomcat 7 and above
- JDK 1.7 and above
- Ant 1.8 and above
- Cobertura 1.9 and above
- A sample war file for instrumentation/use your application war file
Pre-coverage steps:
- Extract classes from your war.
- Create an ant script for instrumenting the classes.
- Add required libs/dependencies for instrumentation (Sample attached- Refer build.xml and build.properties).
- Perform Cobertura instrumentation using your build target as below.
- Now we have instrumented classes generated as below ,Replace the generated files in the war (replace with the existing classes) and cobertura.ser file generated.
- Put your updated war in the tomcat webapps.
- Put your cobertura.ser file in the tomcat bin .
- Add cobertura.jar in the tomcat lib .
- Start your tomcat.
- Hit the required test cases (run ur web application flows either manually or through your automation scripts) (for this sample war -we are hitting http://localhost:8080/sample home page -this application has Hello page-hello class alone so we are executing a test to hit the hello page)
- Now put the updated cobertura.ser in the project ant home folder
- Run coverage targets as below.
- Now we have coverage for the test cases that we have run!
Monday, 17 August 2015
Automated Visual Testing with Selenium and Applitools
Why should visual testing be automated:
1. Lot of areas needs to be covered such as browsers, devices, screen resolutions, RWDs etc.
2. Manual visual testing is error prone and time taking.
3. In the process of “Continues Deployment”, it is mandatory that every task should be automated.
- Automated testing of all the visual aspects of your application:
- One simple test validates all the fields on a given screen.No need to write separate test for each UI element on the screen
- Easy integration with existing test automation and ALM frameworks:
- Test automation tools: Selenium, Appium, MS Coded UI, HP QTP (coming soon) and more.ALM tools: HP QC, MS TFS, IBM Rational Quality Manager, Atlassian, Rally and more.Cloud testing environments.
- Seamless testing on multiple platforms, screen-resolutions and form-factors:
- Define expected results or volatile areas for one browser, one screen resolution or one form factor and all tests would automatically be updated in all browsers, all screen resolutions and all form factors. Any change in your application should only be approved once in one specific test and all other tests would automatically be updated for all browsers, all screen resolutions and all form factors
- Visual self-explanatory logs:
- No more reading of complex text-based failure logs.
Visual test timeline points you immediately to any failed steps.
Smart visual test playback shows step by step the user actions and the screen displays during a test.
Now in this article we are going to learn about integrating applitools with selenium.
1. Download the latest version of the Eyes Java Selenium SDK from https://store.applitools.com/download/eyes_selenium_java/ and extract it to a folder of your choice. Add the extracted files to your path.
2. When running tests, make sure to use your personal API key: XFkqR77qRm9GZkvw9STuox8gBrECZt298F1101ur39cioY110
Sample code is as below:
public static void main(String[] args) throws URISyntaxException, InterruptedException {
WebDriver driver = new FirefoxDriver();
Eyes eyes = new Eyes();
// This is your api key, make sure you use it in all your tests.
eyes.setApiKey("XFkqR77qRm9GZkvw9STuox8gBrECZt298F1101ur39cioY110");
try {
// Start visual testing with browser viewport set to 1024x768.
// Make sure to use the returned driver from this point on.
driver = eyes.open(driver, "Applitools", "Test Web Page", new
RectangleSize(1024, 768));
driver.get("http://applitools.com");
// Visual validation point #1
eyes.checkWindow("Main Page");
driver.findElement(By.cssSelector(".features>a")).click();
// Visual validation point #2
eyes.checkWindow("Features page");
// End visual testing. Validate visual correctness.
eyes.close();
} finally {
// Abort test in case of an unexpected error.
eyes.abortIfNotClosed();
driver.quit();
}
}
}
3. after running a test for the first time, it will automatically be saved as a baseline for future test runs. Now run your test again and open Applitools eyes to analyze the changes. For each step either 'Accept New' in case the changes are expected or 'Keep Baseline' in case the changes reflect a bug.
Advantages of this integration:
- Single page validation replaces hundreds of lines of validation code and hours of manual testing.
- Automatic maintenance – approved changes are automatically propagated to other tests and execution environments.
- Cognitive vision – avoiding false positives, by ignoring differences that are invisible to the human eye.
- Automatically test your app in multiple languages.
- Easily tests complex application pages including dynamic content, size and moving elements.
- It takes the pressure off manual QA and increases the coverage, test faster & more accurately.
Wednesday, 12 August 2015
Do Makeup to your Jenkins Server
HTML Publisher
1. Click on the Configure option for your Jenkins job.
2. In the post build portion, look for the Publish HTML Reports option and select the check box. See the screen shot below
Some time at HTML directory, you don't have to specify project name, but have to start one level below. For e.g. if your project name is "ABC" and if HTML files are at "ABC/report-output/html" then you have to specify just \test-output\html\.
3. After saving the configuration, run build once. The published HTML reports are available to view from within Jenkins with convenient links in the dashboard.
Green Balls
Simple Theme Plugin:
This is a plugin for Jenkins that supports custom CSS & JavaScript.
You can customize Jenkins's appearance (ex. his gentle face on the background) as below:
Navigate to Jenkins > Manage Jenkins > Configure System > Theme
Set URL of theme CSS and JS to URLs of your customized CSS and JS
Some example themes are as below:
http://daniilyar.github.io/Jenkins-themes/themes/canon-jenkins/min/styles.css
http://daniilyar.github.io/Jenkins-themes/themes/canon-jenkins/min/script.js
Wall display Plugin:
Email Extension Plugin:
This plugin allows you to configure every aspect of email notifications. You can customize when an email is sent, who should receive it, and what the email says.
Hi All,
Please find the overall Results of this build as below. You can click on http://10.40.60.186:8080/view/MCS/job/LETSCRETSAutomation/HTML_Report/ for more details.
${FILE,path=”test-output/emailable-report.html”}
Bottom of the line in the above script specifies the path. Change it according to your html path. Remember here, if ur html report depends on any resources like images etc, we have configure them accordingly.
https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin
Dash Board Plugin:
This plugin contributes a new view implementation that provides a dashboard / portal-like view for Jenkins.
The configuration is done in 2 parts, selecting the Jenkins jobs to include in the view, and selecting which dashboard portlets to have included in the view. The jobs that you select are used for all the portlets to draw their information from.
Monday, 2 March 2015
XPath Writing Techniques and Strategies
- Each element has one parent except root
- Each element may have zero or one or more child elements referred as child Nodes can have same parent called siblings. Among siblings, the nodes which are to the immediate left are referred as preceding-sibling and other left nodes as preceding. The nodes to the immediate right are referred as following-sibling and other right nodes are referred as following.
- A nodes parent, parent’s parent is referred as Ancestor
- A nodes children, children’s children is referred as Descendant
- Employee3 as following sibling
- Employee1 as Preceding sibling.
- Manager1 is the parent
- Department is the ancestor (Parent of Parent).
- Section is the Child node
- Employee4 and Employee5 are Descendant nodes
- Use id attribute if available
- Use the combination of attributes to make the XPath more specific
- Use the Relative XPath instead of Absolute XPath Statements
- Always avoid using indexes in Xpath.
- Verify the xpath using Selenium IDE commands
- Using … to move to parent of the present node
- Use XPath functions in XPath wherever necessary to better identification
- Identification of objects with same attribute values
- Don't identify the images using src or alt attributes
- Handling dynamic attribute Values
- Handling multiple Xpaths for a single object
- Absolute Xpath will be very long compare to Relative xpath and hence difficult to manage
- In case of Absolute Xpath , there are high chances that Xpath may break even if there are small changes introduced
- Absolute Xpath has the disadvantage of typing the expression to a particular input structure
Monday, 16 February 2015
Generating HTML Alerts Report through ZAP API
When the user automates the security testing, he/she looks for below kind of reporting.
- alerts based on id
- alerts for the baseurl
- html consolidated report
With the help of getAlerts() method of zaproxy class, we can generate the alerts based on id and url. For generating the consolidated report, API doesn't support HTML report generation as it does by ZAP tool. But it generates xml report. As a work around we can generate this xml report and convert that into HTML with the help of XSLT file.
Users can get the XSLT file from the below path:
https://code.google.com/p/zaproxy/source/browse/trunk/src/xml/report.html.xsl
The below code snippet will be handy in converting xml report into HTML report
public void generateHTMLReport() throws ClientApiException, TransformerException, IOException{
TransformerFactory tFactory=TransformerFactory.newInstance();
InputStream is = ZAProxyScanner.class.getResourceAsStream("<XSLT REPORT PATH>");
Source xslDoc=new StreamSource(is);
Source xmlDoc=new StreamSource(new ByteArrayInputStream(clientApi.core.xmlreport("")));
OutputStream htmlFile=new FileOutputStream("<PATH TO GENERATE HTML>");
Transformer trasform=tFactory.newTransformer(xslDoc);
trasform.transform(xmlDoc, new StreamResult(htmlFile));
htmlFile.close();
}
Happy Testing :)



