Monday 29 December 2014

A better way of handling hidden elements in Selenium



We have already discussed how to interact with the hidden elements in the webpage in this blog.

There could still be challenges in identifying and performing specific actions on the hidden elements, especially when using Selenium WebDriver as the test automation tool, which can interact only with elements that are in visible state on the webpage.

Here are the couple of other solutions to interact with hidden webelements in a better way.

1. When we need to perform, just a click operation on the any webelement irrespective of the element having the unique html id assigned or not. We can use the below method.


a.        In case of ID exist for the element, we can use .getElementById javascript method to perform the click operation

String Script = "javascript:document.getElementById('testobject').click();";
((JavascriptExecutor) webdriver).executeScript(Script);

b.       In case there is no id or name assigned to the webelement, still we can interact as given below.

Identify the element by any of the standard webdrive By class.

WebDriver element = webdriver.findElement(By.xpath(“<locator>”));

Now the argument[0] will always represent the webelement holding by “element” object in the above statement.

JavascriptExecutor Executor = (JavascriptExecutor)webdriver);
Executor.executeScript(“arguments[0].click();”, element);

In fact we can even perform complex actions using javascript support like scrolling the current webpage view. Actually Selenium 2 or webdriver implicitly scrolls the page to the respective element to be clicked or to perform the action on it.

We can still perform the scroll actions explicitly using the below statement whenever necessary.

Executor.executeScript("arguments[0].scrollIntoView(true);", element);


2.
 We can even perform the action on the specified elements by making it to visible during run time of the automation script.



Having the firebug addon in firefox as the tool to identify and debug the object locator effectively we can even change the any attribute value of the html element temporarily on any webpage.





Generally in web application, elements visibility is controlled majorly using the CSS (which are attached to webpages) attributes like style=”display: none;” as shown above.

We can change the style attribute or even add new attributes which can cause a temporary change in the application look and feel which helps to execute selenium automation scripts uninterruptedly.

Below, we have changed the style property as style=”visibility : visible; which has made the drop down or combo box as visible for selenium WebDriver interactions.




This can be performed during runtime of the automation test script using the below command. Again to remind you, we can use the javascript to change the attribute values dynamically.

Executor.executeScript(“arguments[0].setAttribute(‘style’, ‘visibility: visible;’);”, element);

With the above methods we can handle the hidden elements in an effective manner.




ByAutomationMentorwww.automationmentor.in
We provide hands-on training on automation tools and frameworks

Saturday 8 November 2014

Web-service Testing - Overview



W3C defines a web service as a system/software designed to support the interoperable machine-to-machine interactions over internet.

A Web service enables the communication between subsystems by using a combination of open protocols and standards, mainly XML, SOAP and WSDL (Web service Definition Language). It uses XML to tag data, SOAP to transfer a message and finally WSDL to describe the availability of services.

Let's take a look at three main components of a Web service.
  • Simple Object Access Protocol (SOAP) is a protocol for sending and receiving messages between applications without causing any trouble in interoperability.
  • Web Services Description Language (WSDL) is a document that describes a Web service and also tells how to access and use its methods. A simple WSDL file is
    • A description of a Web service
    • The methods a Web service uses and the parameters that it takes
    • A way to locate Web services
  • Extensible Mark-up Language (XML) is an eXtensible Mark-up Language that enables us to identify and organize the data or information in a more accurate and flexible way. It is called extensible because it does not have a specific or fixed format. Using XML we can define any element and call it whatever we like.


Now what is expected from a Web Service testing?
  • Whether the services meet business requirement
  • Validate the data transfer standards as per the business needs
  • To validate whether the  methods provided by the web service work as intended
  • Validate the accessibility and compatibility of the services
  • Verify the data against the data source
  • Data types, optional content and size for each tag
  • Define the test scenarios and test cases with more data transfers considering the every business requirement
It’s difficult to cover all the possible end to end business scenarios with all the possible data combinations but which can be handled using an automated tool to simplify the web service testing. There are quite a number of tools available in the market to test the web services like SoapUI, TestMaker, WebInject out of which SoapUI is the most popular in the market currently.





Capabilities and features of SoapUI:

SoapUI is an open source web service testing application for service-oriented architectures (SOA). Its functionality covers web service inspection, invoking, development, simulation and mocking, functional testing, load and compliance testing.

It has two versions of software, a commercial version, SoapUI Pro, which mainly focuses on features designed to enhance productivity, was also developed by eviware software. In 2011, SmartBear Software acquired eviware.

We can test both SOAP and REST APIs using this tool.  Its most distinguishing factor when compared to other testing tools is that it can be used for multiple forms of testing like both functional and non-functional. Load, Functional and Security testing are few testing types that can be successfully accomplished via SoapUI.

  • SoapUI can be used to create efficient and comprehensive tests that are completely portable across multiple platforms. As it is built on Java.
  • Data driven tests can be created with the help of external data sources like Excel, XML, CSV, Flat files etc.
  • It can generate various types of report in which ever format we require like PDF, Word, HTML.
  • We can even perform load test either web application pages or API’s to capture the response time, the network etc. as if any load testing tool does.
  • Service mocking / MockServices, helps to mimic the web service behavior even before it is developed. This is a really versatile feature helps to minimizing the time that it takes to implement, test and correct it.


Some of the best practices in thoroughly testing the web services
  • Write test cases even if the services aren’t ready
  • Ensure all the messages and elements are covered
  • Testing the corner and boundary conditions
  • Apply assertions to the test results
  • Applying data driven automated testing can derive much benefit
  • Maintain the test data for both input and expected output as well
  • Using the random generator available with tool to generate meaningful data dynamically


Maximum productivity can be leveraged with some of the practises like
  • Linking service tests to rest QA environment
  • Bring testing into the automated build process via integration of deployment tools like ant or maven
  • Let end users interact with services via a forms based UI
  • Add libraries of pre-packaged tests and logic



By
AutomationMentor
www.automationmentor.in

We provide hands-on training on automation tools and frameworks

Wednesday 8 October 2014

Mobile Application Testing and Automation - Overview



Mobile application testing is a process of testing applications for the functionality, usability and consistency. Mobile application can be pre-installed or provided by the mobile software distribution platform itself.

In simple language, application functionality tested that works on mobile platform is nothing but “Mobile Application Testing”.

There are different types of mobile applications:

Native apps – Client side applications
  • Created to work on mobiles and tablets
  • Developed using SDKs
  • Installation is required
  • Mostly no need of internet

Mobile web apps
  • Server side application
  • Websites accessed on mobile using browsers like chrome, safari, firefox etc
  • Developed using the web technologies like html, php, css, asp.net etc
  • Need mobile internet / Wi-Fi to access the applications

Hybrid apps
  • It’s the combination of native and web applications
  • Majorly developed using HTML5 and CSS
  • Can run on mobile and be used offline as well 
Testing the applications on mobile devices are more challenging than testing on desktop due to variety & range of devices and different & versions of operating systems like iOS 5,6 etc / Android 2.3,3.1, 4.2, 4.3(jelly bean), 4.4(Kit Kat) etc.

Different types of tests performed on mobile applications:
  • Usability: To make sure user experience of mobile app is easy, simple and satisfactory
  • Functionality: Testing the intended functionality of the application, just like any other application
  • Interface testing: Testing every menu options, buttons, setting and importantly the Navigational & functional flow of the app
  • Compatibility: testing on different devices , browsers and versions of OS etc 
Apart from the above, we do have various other testing types like Installation testing, Performance, API, Security which can be performed with some manual intervention.

When it comes to automation for the mobile application, there are few tools which can interact directly with the objects on mobile interface. Also, there are few commercial tools that work on image based object recognition like EggPlant, Renorex, SeeTest etc.

We have few open source libraries & tools like Robotium, Sikuli and Selendroid which can also provide faster and reliable automation results for mobile testing.



When it comes to automation of mobile app testing on android platform, we have Selendroid which has great support to interact with the emulators and various devices with different android versions.

Selendroid is based on Android instrumentation framework which helps automation on the android platform for both mobile webview and native apps.

Features of Selendroid:
  • Mobile WebDriver supports native and hybrid apps
  • AUT need not be modified to automate it
  • All the browser automation atoms are supported
  • Advanced user interaction and gestures like tap, doubletab, flick etc are supported.
  • Multiple simulators and devices can be interacted
  • Emulator can be started automatically before execution of the test
  • Built in inspector for object identification
  • Full Support to JSON wire protocol

Coming to iOS platform, there are open source and commercial tools but Appium has extensive and increasing support of automation on iOS.

Appium is a cross-platform test automation tool for native, hybrid and mobile web apps, tested on simulators (iOS, FirefoxOS), emulators (Android), and real devices (iOS, Android, FirefoxOS). There are few challenges in mobile test automation with respect to platform technology and the execution of the scripts once automation is done.

Mobile automation success depends on the tool’s ability to work across various platforms and technology. The following challenges influence mobile automation success:
  • Multiple platforms and browsers
  • Differences in rendering
  • Mobile devices with varied application run times
  • Some network related to issues when using different types of networks (GSM/GPRS/Wi-Fi/Wi-Max).
  • When using the physical devices some of the hardware challenges like processing speed and memory limitations. 

When it comes to Test execution across different devices and browsers there will be huge effort to deploy and run automation tests. For example we have a test case that needs to be executed on three different platforms, such as Android, iOS and Blackberry. The test case is expected to be executed on 10 different devices and in 10 different combinations, which leads to 100 iterations of execution which is challenging and time-consuming to design such a test execution on mobile. Collaborating with cloud mobile environment providers like BrowserStack, SauseLabs & DeviceAnywhere is a good idea to quickly test compatibility on multiple environments.



By
AutomationMentor
www.automationmentor.in

We provide hands-on training on automation tools and frameworks

Saturday 20 September 2014

Mobile Web Testing & Automation – Introduction



Nowadays, compatibility testing is very important and in demand as it gives the confidence that our application is usable across multiple platforms.

One of the most used platforms in the world is Mobile. So the question is whether your application is usable across different Mobile platforms?

For that matter there are many mobile devices and platforms like android and iOS in which we can test the compatibility of our application.

There are n number of Mobile devices available with x resolutions having y operating systems. So practically, it’s not feasible to have all the n*x*y number of devices to do a compatibility test on.

There are again two different ways we look at the mobile compatibility

Using Mobile WebDriver

As our objective is to test the web application on mobile, we can either do it on the mobile emulators or on the actual devices.

That’s the reason Mobile simulators have come into the picture so if I have to test my application on that many devices, I can do it by simulating the required features.

We have android webdriver which helps us test the application and run the tests to ensure our website working as expected when viewed from android browser.

It supports all the core webdrive apis and many user interactions like taps, flicks, scroll etc. To interact with the web page android driver uses the native touch and key events.

Step 1:
                     Download the android SDK here
Download the Latest ADT bundle from the below Location
System Settings :
Set the ANDROID_HOME
Ex:  C:\Android\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk
Set Path variable for the Android
Ex: % ANDROID_HOME%\platform-tools; %ANDROID_HOME%\tools;

          Step 2:
                        Create an Android virtual device AVD. Follow the instructions given here.

          Step 3:
Download the android webdriver apk file (here) and install on the virtual device using the command below in command prompt

            Command: adb install android-server-2.38.0.apk


           


Step 4:
           
            To get the emulators or devices connected

Command: adb devices

List of devices attached
emulator-5554   device

Start the webdriver app install using the command below

Command:
adb -s emulator-5554 shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity

Forward the tcp port to send the selenium commands to emulator

Command: adb –s emulator-5554 forward tcp:8080 tcp:8080


Step 5:
           
                     Use the eclipse and create a Java project
                       
                     Create a java class with the below code

import junit.framework.TestCase;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;

public class OneTest extends TestCase {

  public void testGoogle() throws Exception {
    WebDriver driver = new AndroidDriver();
   
    // And now use this to visit Google
    driver.get("http://www.google.com");
   
    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));
   
    // Enter something to search for
    element.sendKeys("Selenium Mobile Testing");
   
    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();
   
    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();
  }
}

Run the program as simple Junit test, now the application is opened on the mobile browser and executed

Using Selendroid WebView

Selendroid is an automation framework which drives of UI of android native, hybrid and mobile web application tests. It uses JSON Wire Protocol to run webdriver test scripts on emulators or devices. No modification or need source code is required to automate application.

           Step 1:
                        Download the android SDK here
           Step 2:
                        Create an Android virtual device AVD. Follow the instructions given here.



           Step 3:
                        Download the Selendroid standalone server jar here
           Step 4:
            Start the emulator using AVD manager and to get the emulators or devices connected

Command: adb devices

List of devices attached
emulator-5554   device

Start the Selendroid server using the below command

Command: java -jar selendroid-standalone-0.11.0-with-dependencies.jar

The default port the selendroid server runs in 4444. If we want to change the port use the command

Command: java -jar selendroid-standalone-0.11.0-with-dependencies.jar – port:5555




Step 5:
Use the eclipse and create a Java project and create a java class with the below code and configure the build path


                       

Sample code:
package com.java;

import io.selendroid.SelendroidCapabilities;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class OneTest {
  private WebDriver driver = null;

  @Test
  public void shouldSearchWithEbay() throws InterruptedException {
             
            DesiredCapabilities capa=DesiredCapabilities.android();
            capa.setCapability(SelendroidCapabilities.EMULATOR, true);
           
            driver = new RemoteWebDriver(capa);
           
    // And now use this to visit ebay
    driver.get("http://m.ebay.com");

    // Find the text input element by its id
    WebElement element = driver.findElement(By.id("kw"));

    // Enter something to search for
    element.sendKeys("Nexus 5");

// Now submit the form. WebDriver will find the form for us from the element
    element.submit();
   
    Thread.sleep(5000);

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();
  }
 
}

Result:



Object Identification:

In order to inspect and identify the elements in the webview we can use the below url to spy on the objects.

Note: Make sure the selendroid server and emulator or device is up and running on the specified port. Refer here for more information.

We can even test the native android apps using selenium. Here we need have the application kit or .apk file of the application which we need to test

By
Automation Mentor
www.automationmentor.in

We provide hands-on training on automation tools and frameworks