Thursday, July 23, 2015

How to handle empty element in XML (Java StAX Parser)

I am not a Software Developer rather a QA person.
I face this problem, while I was writing Selenium Automation Framework in Java. So I am sharing solution i used in it.

Some XML may contains empty elements. i.e. Creation of XML is not under user ownership and You can not prevent XML to have empty elements.

Strange thing is there is no inbuilt function in XMLEvent  API to check empty elements.
Here is tick that you can use:

Example of XML file:
<teststepID tid="S1TC1">
<step>
<action>VisitURL</action>
<locator-id></locator-id>
<locator-class></locator-class>
<locator-xpath></locator-xpath>
<data>http://www.nextag.com/</data>
</step>
<step>
<action>Type</action>
<locator-id>searchTop-s2</locator-id>
<locator-class></locator-class>
<locator-xpath></locator-xpath>
<data>shoes</data>
</step>
</teststepID >

Code to handle:
if (event.isStartElement()) {
        //Check for each element
if (event.asStartElement().getName().getLocalPart().equals(action)) {
                 //After reading element, check for immediate next element. 
         event = eventReader3.nextEvent();
                    //Immediate element should be Endelement  due to empty tag in XML.
            if(event.isEndElement()){    
            }
            else {
                           //Else store the value or use according to your requirement. 
                  td.setStep_action(event.asCharacters().getData());
                  }
                //Continue loop of XML event reader
continue;
}
}



Thursday, June 11, 2015

Selenium Simple Framework like Hybrid for Automation Testing

I am working as a QA Lead in a MNC in Noida, India.

I have create a Automation framework based on Selenium web-driver.
This is Hybrid Framework, and source code of this is available on Github:    https://github.com/ashvinisharma/HybridFramework

For any queries related to this framework, you can contact me on following: 
E-mail id = ashvsharma82@gmail.com

I have added comments in my code so that it will be easy for you to understand the logic.

Key Features of this Framework:
-Written very generic code, you can customize/tweak it according to your requirement. 
-Support Windows/Mac/Linux platform.
-No coding knowledge required for executors.
-This framework is suitable for any e-commerce site.
-Report Generates in HTML format.
-Verify values in DB

Tools:
-Use of Java tools, Junit and Log4J.

Flow diagram of this framework: