Posts tagged as:

automation

We know Selenium IDE is one which is used by many manual testers and does not require knowledge of any programming language. But a manual tester can become an automation engineer using fitnesse. The developer need to create a framework using selenium rc/webdriver with any programming language like java, C# etc and integrate with fitnesse. There is no need to have knowledge of junit and testing framework.

I will show how this can be done step by steps

  1. Download fitnesse from http://fitnesse.org/FrontPage.FitNesseDevelopment.DownLoad

Unzip downloaded folder to any drive like C:\fitnesse

  1. Download selenium from http://seleniumhq.org/download/

Keep selenium-server-standalone-2.21.0.jar in C:\fitnesse

  1. Start fitnesse server clicking run.bat or from command prompt type java -jar fitnesse.jar
  2. Now open your browser and go to http://localhost. You will see the FitNesse home page.
  3. Click on Edit menu at left pane. Remove introduction note from home page and create project. We need to set path as shown below once our project is created.

!path selenium-server-standalone-2.21.0.jar

!path fitnesse.jar

!path lib/fitlibrary.jar

!path D:\Workplace\Fitenium\bin

Also configure SetUp and TearDown as if required.

 

  1. Make sure that you have created project Fitenium using eclipse in D drive in Workspace. Below I have created sample java class which utilizes java fixture wrappers around selenium call.

package com.sample.automation.framework;

import org.openqa.selenium.By;

import org.openqa.selenium.WebElement;

import com.sample.automation.browser.Browser;

import fitlibrary.SequenceFixture;

/*

* This class extends SequenceFixture so that we can create and use java style fixture in fitnesse*/

 

public class FitSeleniumFramework extends SequenceFixture

{

private static WebDriver driver;

public void initializeBrowser() {

driver = new FirefoxDriver();

}

public WebDriver getWebDriver() {

return driver;

}

public void stopBrowser() {

if(driver != null) {

driver.quit();

}

}

/*

* This is a fixture which we use to open home page url

*/

public void navigateToHomePage(String url) {

initializeBrowser();

try {

getWebDriver().navigate().to(url);

}catch (Exception e) {

System.out.println(“ERROR OPENING THE ” + url);

e.printStackTrace();

stopBrowser();

}

}

/*

* This fixture is used to check if particular element present on web page

*/

public boolean isElementPresent(String element) {

WebElement webElement = getWebDriver().findElement(By.xpath(element));

if(webElement != null)

return true;

else

return false;

}

  1. We have now two fixtures from above code

navigateToHomePage(String url)

isElementPresent(String element)

 

  1. Edit Project and create test suite namely HomePageSuite. Use Properties menu from left pane to change properties of page.

 

  1. Edit suite created in fitnesse and create test case namely “HomePageElements”. Write fixture in test case like

|navigateToHomePage|http://kayak.com|

|check|isElementPresent|//input[@id="origin"]|true|

|check|isElementPresent|//input[@id="destination"]|true|

|check|isElementPresent|//button[@id="fdimgbutton"]|true|

 

  1. Run test case clicking Test button from left pane.

Once tester got familiar with fixture, effectively he can start productively automating test cases without any programming experience. There is no need for the whole team to  know java and selenium or any other programming language. By just understanding wiki markup and xpath or css, non-technical person can write test cases using fitnesse.

VN:D [1.9.10_1130]
Rating: 8.7/10 (3 votes cast)

  

{ 1 comment }

I hope you found the first 3 parts of the blogs on Mobile Web Application Test Automation informative and helpful.
While Part 1 provides an introduction to mobile web automation, Part 2 talks about the testing methodology and how browser simulations will work and Part 3 focuses on browser simulation tools. Continuing the sequence, in Part 4, I will provide an overview of mobile web automation implementation using selenium webdriver, especially for android web browser.

Preface:

Webdriver enables you to run your tests against the browser running on a mobile device or a device emulator rather than having to use just the  desktop web browser trying to make them to behave like mobile web browser. You can run the tests against android as well as iPhone web browsers using webdriver.

Setup:

For setup, I followed the instruction provided in AndroidDriver wiki and get it worked.

How to automate:

I tried it with ISFW by setting properties for server, port and providing browser string as “androidRemoteDriver”.

selenium.server=localhost
selenium.port=4444
selenium.defaultBrowser=androidRemoteDriver

 

The easiest way over here is to record using selenium IDE and export to ISFW format. If the web application has User-Agent awareness and generates User-Agent specific content, for example google search page or gmail, then one can simulate Firefox for mobile User-Agent as described in Part 3 during recording phase.

Sample Code:

public
class AndroidDemo extends BaseTestCase {
    @Test(description = “Google search”)
    public
void tc01() {
        IsSelenium selenium = getSTB().getSelenium();
        WaitService waitService = new WaitService();

        selenium.open(“/”);

        waitService.waitForPageToLoad();

        selenium.type(“q”, “infostretch test automation framework”);

        selenium.submit(“q”);

        getSTB().assertElementPresent(

                “link=InfoStretch Selenium Test Automation Framework”,

                “link InfoStretch Test Automation Framework”);

    }

}

 

Execution:

Before run automation, you need to execute following commands from command line to create/ start avd and install/start selenium server in avd manually as described in AndroidDriver wiki.

  1. android create avd -n my_android -t 12 -c 100M
  2. emulator -avd <avdName> -no-audio -no-boot-anim
  3. adb -e install -r <dir>/android-server*.apk
  4. adb shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity
  5. adb forward tcp:4444 tcp:8080

Here command #1 to create AVD (Android Virtual Device) requires only one time execution. Command #3 needs to be executed once or after you wipe data. Command #4 will start selenium RC in AVD from command line so you don’t need to search and start the applications in a device/emulator. Before executing command #4,  you need to wait for emulator boot status complete. Finally, run batch file to run test and that’s it…

This task can be automated using ant script including the wait for boot complete and server ready. I have also integrated it with Hudson using Android plug-in. You can find details on integration with Hudson here.

Conclusions:

  • You can test your web application with a mobile emulator or with a real device.
  • Lesser efforts are required in setting up this environment compared to desktop browser simulation approach. You can utilize the simulation approach for getting information about web elements during automation development phase or to record test using IDE.
  • It is cost effective if you run against emulator but slower compared to real device.
  • Makes it as simple as web automation for desktop browser.
  • ISFW provides strength to webdriver by fulfilling automation’s common aspects (data-driven, reporting, integration with test management tools, etc)
  • Here are some Pros & Cons of using webdriver.

Screenshots:

  1. Execution
  2. Result/Report
  3. Attached Screenshot in report

 

VN:F [1.9.10_1130]
Rating: 9.2/10 (6 votes cast)

  

{ 2 comments }

Last week, I evaluated InfoStretch framework (ISFW) and Sauce on Demand (SOD) integration. My main concern was to test not only the integration, but also to verify parallel execution of test that is supported by ISFW and SOD. I found that it worked without any additional efforts along with all benefits of the framework including parallel execution and auto screenshots.  In this blog, I will provide details on integration and how to configure your test to run on SOD.

Preface:

Testing web applications often requires running tests against multiple browsers and in multiple environments. Using ISFW, one can run tests on a local or a remote physical machine. For that, you need to set server, port and browser in the properties file. You can configure to execute test in parallel with different options. Furthermore, you can configure your test to run in parallel on distributed servers in different environment as well. If you are using distributed servers, then the only requirement is that selenium server must be running on a remote machine. We have implemented this for some of our clients. ISFW supports overriding server, port and browser properties from configuration file by providing appropriate parameters at suite/test/package/class level. Thus, you can configure multiple server-browser combinations.

Sauce on demand Integration

To run test on cloud with ISFW, all you need to change is the server, port and browser info provided by sauce labs. You can run your test in one or more environments without having your own infrastructure. The most powerful feature of ISFW is that it provides parallel-ready test harness to connect tests to Sauce Labs’ service. As ISFW can run tests in parallel in multiple threads you can achieve parallelism with SOD as well. To use multiple environments/browsers you just need to override browser parameter in the configuration file.

One common issue is related to json string for browser, faced when you want to set browser from xml configuration file. Normally, value of the browser parameter in the configuration file is a string like *firefox, *iehta, etc. But, for SOD you need to provide json string which contains double quotes (“). So, it will not work as parameter value.To overcome this limitation you can provide any property, defined in properties file, as browser parameter value. It’s really helpful that ISFW supports browser parameter value as property!..

Benefits:

  • By using Sauce Labs’ service you don’t required to setup different environments.
  • With ISFW, no additional efforts are required to run your test using Sauce Labs’ service
  • Get all benefits of the IS framework, including parallel execution and auto screenshots.

Those who are interested getting details of the code and configuration used for evaluation, see Code: test-cases used for evaluation, Configuration 1 and Configuration 2. You might also be interested in reading an  informative blog on Selenium UI test automation with zero infrastructure cost authored by Akhil.

 

Code: test-cases used for evaluation.

package com.sample.automation.tests;
import
/**
* Demo on how to write quick tests.

* These test not uses {@link TestPage} implementation provided by FW.
* @author chirag
*/

public class Demo extends BaseTestCase {
@Test(description = “Sample test”)
public
void TCtest() throws Exception {
final
IsSelenium selenium = getSTB().getSelenium();
WaitService waitService =
new WaitService();
selenium.open(
“/”);

selenium.type(
“q”, “infostretch automation framework”);

selenium.click(
“btnG”);

selenium.click(
“link=glob:*Automation Framework”);
// selenium.waitForPageToLoad(“5000″);
waitService.waitForPageToLoad();

getSTB
().assertEquals(
“InfoStretch Test Automation Framework”,

selenium.getText(
“css=h1.entry-title”), “Heading”);

}

/**
* Data driven test that aspect csv data file. The file path must be set
* using property
<code>test.TCDataDriven.datafile</code>

*
@param query
*
@param linkloctoverify
*
@throws Exception
*/

@Test(description = “Sample data driven test from above one”, dataProvider = “csvDataProvider”, dataProviderClass = DataProviderUtil.class)

public void TCDataDriven(String query, String linkloctoverify) throws Exception {
final
IsSelenium selenium = getSTB().getSelenium();
selenium.open(
“/”);

selenium.type(
“q”, query);

selenium.click(
“btnG”);

getSTB
().verifyElementPresent(linkloctoverify,
“Search result”);

}

@Test(description = “using property from property file”)
public
void propTest() {

final IsSelenium selenium = getSTB().getSelenium();selenium.open(“/”);
selenium.type(props.getPropertyValue(“search.txt.loc”, “q”),”infostretch automation framework”);
selenium.click(
props.getPropertyValue(“search.submit.loc”, “btnG”));

selenium.click(
“link=glob:*Automation Framework”);

}

}

Data File

TCDataDriven is data driven test and the searchText.csv data file provided with following entries. So TCDataDriven will execute in separate threads for each data set, results in 3 tests running parallel.

Qmetry,css=a[href*=www.qmetry.com]Infostretch,css=a[href*=www.infostretch.com]

infostretch selenium,css=a[href*=blog.infostretch.com]

Configuration

Configuration 1:

Here are the settings to run test in windows environment with Firefox. With this configuration data driven test will get executed in parallel.

Properties:

selenium.server=ondemand.saucelabs.com
selenium.port=80
selenium.defaultBrowser=
{“username”: “cjayswal”,\
“access-key”
: “????????-????-????-????-????????????”,\
“os”
: “Windows 2003″,\
“browser”
: “firefox”,\
“browser-version”
: “3.6″,\
“name”
: “This is an example test”}

Configuration file:

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>
<suite name=“Sample Test Automation” verbose=“0″ data-provider-thread-count=“10″>
<
test name=“Sample Test”>
<
packages>
<
package name=“com.sample.automation.tests”/>
</
packages>
</
test>

</
suite>

Configuration 2:

 

Configuration to run test in IE8, FF on Windows and FF on Linux. Attribute parallel=“tests” will execute each xml test in separate thread which in turn executes data driven test in parallel (check the time stamp in attached report).

Configuration file:

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>
<suite name=“Sample Test Automation” verbose=“0″ parallel=“tests” data-provider-thread-count=“10″ >
<
test name=“Test on Win2003 FireFox3.6″ >
<
parameter name=“browser” value=“sauce.json.firefox” />
<packages>
<
package name=“com.sample.automation.tests”/>
</
packages>
</
test>
<test name=“Test on Win2003 IE8″>
<
parameter name=“browser” value=“sauce.json.iehta”/>

<
packages>
<
package name=“com.sample.automation.tests”/>
</
packages>
</
test>

<test name=“Test on Linux FireFox3.6″>
<
parameter name=“browser” value=“sauce.json.firefoxOnLinux”/>
<
packages>
<
package name=“com.sample.automation.tests”/>
</
packages>
</
test>

</suite>

Properties:

selenium.server=ondemand.saucelabs.comselenium.port=80
sauce.json.firefoxOnLinux=
{“username”: “cjayswal”,\
“access-key”
: “????????-????-????-????-????????????”,\
os
: Linux“,\
“browser”
: firefox“,\
“browser-version”
: “3.6″,\
“name”
: “Parallel run evaluation with InfoStretch fw“}

sauce.json.firefox={“username”: “cjayswal”,\
“access-key”
: “????????-????-????-????-????????????”,\
os
: “Windows 2003″,\
“browser”
: firefox“,\
“browser-version”
: “3.6″,\
“name”
: “Parallel runevaluationwithInfoStretchfw“}

sauce.json.iehta={“username”: “cjayswal”,\
“access-key”
: “????????-????-????-????-????????????”,\
os
: “Windows 2003″,\
“browser”
: iehta“,\
“browser-version”
: “8″,\
“name”
: “Parallelrun evaluation withInfoStretchfw“}

Screenshots:

Report: overview
Report: Test on Win2003 FireFox3.6

package com.sample.automation.tests;

import

/**

* Demo on how to write quick tests.

* These test not uses {@link TestPage} implementation provided by FW.

* You can also utilize IDE plug-in for InfoStrech framework.

*

* @author chirag

*/

publicclass Demo extends BaseTestCase {

@Test(description = “Sample test”)

publicvoid TCtest() throws Exception {

final IsSelenium selenium = getSTB().getSelenium();

WaitService waitService = new WaitService();

selenium.open(“/”);

selenium.type(“q”, “infostretch automation framework”);

selenium.click(“btnG”);

selenium.click(“link=glob:*Automation Framework”);

// selenium.waitForPageToLoad(“5000″);

waitService.waitForPageToLoad();

getSTB().assertEquals(“InfoStretch Test Automation Framework”,

selenium.getText(“css=h1.entry-title”), “Heading”);

}

/***

* Data driven test that aspect csv data file. The file path must be set

* using property <code>test.TCDataDriven.datafile</code>

*

* @param query

* @param linkloctoverify

* @throws Exception

*/

@Test(description = “Sample data driven test from above one”, dataProvider = “csvDataProvider”, dataProviderClass = DataProviderUtil.class)

publicvoid TCDataDriven(String query, String linkloctoverify) throws Exception {

final IsSelenium selenium = getSTB().getSelenium();

selenium.open(“/”);

selenium.type(“q”, query);

selenium.click(“btnG”);

getSTB().verifyElementPresent(linkloctoverify, “Search result”);

}

@Test(description = “using property from property file”)

publicvoid propTest() {

final IsSelenium selenium = getSTB().getSelenium();

selenium.open(“/”);

selenium.type(props.getPropertyValue(“search.txt.loc”, “q”),

“infostretch automation framework”);

selenium.click(props.getPropertyValue(“search.submit.loc”, “btnG”));

selenium.click(“link=glob:*Automation Framework”);

}

}

VN:F [1.9.10_1130]
Rating: 9.7/10 (7 votes cast)

  

{ 2 comments }

For non technical testers Selenium IDE is the ideal environment for creating Selenium tests. Selenium IDE provides code formatter for different language and/or testing frameworks.

Choosing the right framework or scripting technique helps in maintaining lower costs. The approach of scripting used during test automation has effect on cost due to development and maintenance efforts.

Various scripting techniques are generally used when developing test automation scripts are:

  • Linear : Procedural code, possibly generated by tools like Selenium IDE
  • Structured: Uses control structures – for instance ‘if-else’, ‘switch’, ‘for’, ‘while’ conditions or flow control statements
  • Data-driven: Data is persisted outside of tests in a database, csv files, or other mechanism
  • Modularity-driven: Creation of small, independent scripts that represent modules, sections, and functions of the application-under-test
  • Hybrid: Two or more of the techniques above are used

Adding Functional programming capability to IDE

If you are using selenium IDE for developing your tests, then using InfoStretch Selenium IDE plug-in you can record scripts that turn out to be Structured, Data-driven, and Modularity-driven or Hybrid. Plug-in provides code formatter to export recoded steps in IDE to “InfoStretch Test Automation Framework (ISFW)” format. In addition to code formatter for ISFW, following functional programming capability added to IDE:

  • Defining reusable steps as modules
    • supports parameters
    • can return value
  • Call defined modules in tests
  • Conditional Flow control
  • Looping
  • Nested looping and conditional flow

Through InfoStretch plug-in you can apply different approaches while recording using selenium IDE, for instance

  • Scripts generated by Selenium IDE using record facility be the linear
  • By use of control structures commands – typically ‘if’, ‘else’, ‘elseif’, ‘while‘ conditions/ statements provided by InfoStretch plug-in will make scripts Structured
  • Creation of small, independent modules of the application-under-test using ‘defineModule‘ command provided by InfoStretch plug-in be useful in developing Modularity-driven test
  • Call command provided by InfoStretch plug-in be useful call defined modules in test
  • Define module with parameters and use of data-provider will make script Data-driven

Thus three steps for non technical users are:

  1. Record using Selenium IDE
  2. Edit as per requirements
  3. Export test case as “ISFW” format from IDE.

You can get more detail about plug-in usage in next blog “Using InfoStretch Selenium IDE Plug-in”

VN:F [1.9.10_1130]
Rating: 9.8/10 (11 votes cast)

  

{ 2 comments }

Nowadays CSS selectors become popular and took place of xpath selectors. While locating elements the ideal candidate is to reference elements on the page by their unique id or name. If that is not possible, incase not available or auto generated, then XPath or CSS are the strategies available to you. Here you can get answer on Why CSS Locators are the way to go vs XPath.

One useful tool I found is FirePath which is a Firebug extension that adds a development tool to edit, inspect and generate XPath 1.0 expressions, CSS 3 selectors and JQuery selectors (Sizzle selector engine). The problem with fire path generates xpath specific to element but for css or Sizzle it is not always specific to selected element.

Selenium IDE 1.0.11
released on 30/May/2011 has inbuilt CSS locator builder! Selenium IDE will now create locators using CSS when recording. Also, same as getXpathCount, new command getCssCount added to count the number of nodes that match the specified css selector. So now using css selector you can get number of nodes that match the specified selector.

Sizzle, used by selenium as CSS selector engine, provides Positional and Form Selector Additions makes locator simpler and more readable, for instance:

  • :nth(index_0_base)

    Simplified position selector (li:nth(5) finds the 6th li element)

  • :input

    Finds all input elements including textarea, select and button.

  • :text
  • :checkbox
  • :file
  • :password
  • :submit
  • :image
  • :reset
  • :button

     

    that finds the input element with the specified input type.
    Here :button also finds button elements in addition to input elements having type button.

You can find more details for additional selectors in Sizzle documentation.

I had documented some examples for defining complex CSS and X-Path selector.

Strategy

X Path

Sizzle(CSS)

Comments

Element 

//div 

div 

locate first div element

By id

//div[@id='eleid'] 

div#eleid 

Locate div with id eleid

By class

//div[@class='eleclass']

//div[contains(@class,'eleclass')]

div.eleclass 

locate div with class name eleclass if more than one class exist then xpath 2 will be used

By attribute

//div[@title='Move mouse here']

  1. div[title=Move mouse here]
  2. div[title^=Move]
  3. div[title$=here]
  4. div[title*=mouse]

you can use match operators for class and id as well, for example div[id^=menu-item]

Child 

//div[@id='eleid']/*

//div/h1 

div#eleid >*

div#eleid >h1

 

Descendant

//div[@id='eleid']//h1

div h1 

Will work for //div/*/…../h1

By index

//li[6]

li:nth(5)

6th li element

By content

//a[contains(.,'Issue 1164')]

a:contains(Issue 1164)

Case Sensitive

By Child

  1. //li[a[contains(.,'Issue 1244')]]
  2. //*[./a[contains(.,'Issue 1244')]]
  3. //ul[.//a[contains(.,'Issue 1244')]]
  1. li{a:contains(Issue 1244)}
  2. ul{a:contains(Issue 1244)}

<ul><li> Improved alert on changing the format <a href=”">Issue 1244</a></li>

<li>next sibling</li>…</ul>

<h3>Listing 2</h3>

<ul><li> Improved alert on changing the format <a href=”">Issue 1244</a></li>

<li>next sibling</li>…</ul> 

Next Sibling 

  1. //li[preceding-sibling::li[contains(.,'Issue 1244')]]
  2. //ul[preceding-sibling::ul[.//a[contains(.,'Issue 1244')]]]
  1. css=li:contains(Issue 1244) + li
  2. css=ul{a:contains(Issue 1244)} ~ ul

 

If you have not read Why CSS Locators are the way to go vs XPath blog posts, you must absolutely read it now.

Limitations of CSS locators

CSS is used for styling the document/elements and not originally for locating elements, so there are certain limitations too.

  • There are some cases where you cannot locate element using CSS locator. For instance

    //*[@value>3]

  • Lack of arithmetic and logical operator/function support as compare to xpath
  • Text comparison is case sensitive and there is no way to perform case insensitive comparison.
  • When referring to parent you must be careful, For instance

In Xpath :

  • //*[./a[contains(.,'Issue 1244')]]
  • //li[./a[contains(.,'Issue 1244')]]

Both 1 and 2 are will locate element li, having first child a[contains(.,'Issue 1244')]

Whereas in CSS

  • li{a:contains(Issue 1244)}
  • *{a:contains(Issue 1244)}

Both 3 and 4 locates different elements. 3 is same as 1(assuming there is no other parent li element of li) but 4 locates first element that having child a:contains(Issue 1244) that is document root. There is no way to locate parent precisely.

  • For IE, Complex CSS might become as slow as XPath.

Conclusions:

  • Element Location strategy should be selected with following preference

    id, name, link, dom/css/xpath

  • Locators recorded by IDE are not always efficient but you can modify it manually for the best efficient one.
  • Avoid locating parent using CSS or be more careful.

 

VN:F [1.9.10_1130]
Rating: 9.2/10 (20 votes cast)

  

{ 4 comments }

InfoStretch test automation framework provides test page concept in a best efficient way by which you can manipulate page navigation same as on actual web application under test. Once page get created page objects/functionalities can be used in any test case, makes code more reusable. The framework takes care of not only launching that page but the entire page hierarchy to reach that specific page. Furthermore it also checks that is page already active in browser? If so then it will continue from there, results in reduced execution time.

Following are two of the test cases that demonstrates

  • Reusability of code
  • Reduced execution time
  • Less maintenance

As the class the derived from framework’s base class, test case developer only need to concentrate on writing the tests and not spend time on adjusting the underlying framework.

      @Priority(value = 1)
      @Test(enabled = true, groups = {"BulkUpload", "Supplier", "Report"},
      description = "TC4277: Verify that 'Upload Status Report' link is visible to buyer on 'Supplier Upload Status' page.")
      public void TC4277() {
            String jobid = context.getAttribute("upload.jobid.TC4277").toString();
            UploadStatusPage statusPage = new UploadStatusPage(getSTB());
            statusPage.launchPage(jobid);
            getSTB().assertElementPresent(UploadStatusPage.UPLOAD_STATUS_REPORT_LINK_LOC,
                        "'View Report' link");
            getSTB().verifyIsVisible(UploadStatusPage.UPLOAD_STATUS_REPORT_LINK_DIV_LOC,
                        "View Report link");
      }

Commands executed in selenium. You can see commands executed for the entire page hierarchy to reach that specific page.

getNewBrowserSession *iehta https://www.domainname.com/ OK,6636575977794f15be1fd6bbdabc5642
setTimeout 100000 OK
setContext TC4277 OK
isTextPresent 10560452 OK,false
isElementPresent //td[@class='pageTitle'] OK,false
isElementPresent link=Suppliers OK,false
isElementPresent link=Home OK,false
isElementPresent link=Suppliers OK,false
isTextPresent Login OK,true
isElementPresent xpath=(//input[@name='j_username'])[1] OK,false
open /aems/login.do OK
waitForPageToLoad 100000 OK
isTextPresent Home OK,false
isTextPresent Login OK,true
isElementPresent xpath=(//input[@name='j_username'])[1] OK,true
isTextPresent Home OK,false
waitForCondition selenium.isElementPresent(“xpath=(//input[@name='j_username'])[1]“) 100000 OK
type xpath=(//input[@name='j_username'])[1] xxx OK
type xpath=(//input[@name='j_password'])[1] yyy OK
click xpath=(//input[@type='submit'])[1] OK
waitForPageToLoad 100000 OK
click link=Suppliers OK
waitForPageToLoad 100000 OK
isElementPresent link=Upload History OK,true
click link=Upload History OK
waitForPageToLoad 100000 OK
isElementPresent //table/tbody/tr[td/a[contains(text(),'10560452')]][1]/td/a[contains(text(),'View')] OK,true
click //table/tbody/tr[td/a[contains(text(),'10560452')]][1]/td/a[contains(text(),'View')] OK
waitForPageToLoad 100000 OK
isElementPresent link=View Report OK,true
isVisible //div[@id='statusReportLink'] OK,true

Framework concept is based on page services so your page and related actions will be reusable from any test case. Thus test case becomes highly maintainable and utilize reusable test asset with proper modularity and semantic structure.

In case of sequential execution it will take advantage of sharing browser sessions between multiple test cases. No special coding or design required to run test in parallel, you just need to set parallel attribute’s appropriate value in configuration file (eg. false, Test, methods, classes) and framework will take care for providing thread safe browser sessions with maximum level of sharing browser session between multiple test cases. This will result in reducing time by parallel processing as well as by some level of sharing browser session(depends on configuration). You also can configure to run parallel in different browser (eg. iexplorer, firefox) with or without selenium grid.

Here is another test case, which get executed after above one. It will found the page loaded and get continued for test steps. Thus results in less execution time.

       @Priority(value = 2)
       @Test(enabled = true, groups = {"BulkUpload", "Supplier", "Report"},
       description = "Verify that application generates in-progress status bar during report execution.")
       public void TC4278() {
              String jobid = context.getAttribute("upload.jobid.TC4278").toString();
              UploadStatusPage statusPage = new UploadStatusPage(getSTB());
              statusPage.launchPage(jobid);
              getSTB().assertElementPresent(UploadStatusPage.UPLOAD_STATUS_REPORT_LINK_LOC,
                           "'View Report' link");
              getSTB().verifyIsVisible(UploadStatusPage.UPLOAD_STATUS_REPORT_LINK_DIV_LOC,
                           "'View Report' link");
              statusPage.clickUploadSatatusReportLink();
              getSTB().verifyIsVisible (UploadStatusPage.INPROGRESS_STATUS_BAR_DIV_LOC,
                           "In-progress status bar");
       }
Selenium-Command Parameter-1 Parameter-2 Res.RC
setContext TC4278 OK
isTextPresent 10560452 OK,true
isElementPresent //td[@class='pageTitle'] OK,true
getText //td[@class='pageTitle'] OK,Supplier Upload Status
isTextPresent 10560452 OK,true
isElementPresent link=View Report OK,true
isVisible //div[@id='statusReportLink'] OK,true
click link=View Report OK
isVisible //div[@id='statusReportProgress'] OK,false

When functionality changes only the specific test page file needs to be updated: if there is any change in page/ui of web application under test you need to update just in particular page rather than each and every test case, thus result in less maintenance.

Following page class illustrate how the navigation took place by derived page object. Whenever page’s launchPage method called framework will check for existence of page in browser if it is not loaded then it will call openPage method to open page from parent/launcher page (UploadHistoryPage in our case) Framework will call openPage method only if page is not loaded and parent is loaded. If parent is not loaded framework will call parent’s launch method.

public class UploadStatusPage extends BaseTestPage<UploadHistoryPage> {

      @Override
      protected void openPage(PageLocator locator) {
            parent.viewPostUploadResults(locator.getLocator());
      }

      //method below check is supplier upload status page open and for given job?
      @Override
      public boolean isPageActive() { 

            return pageLocator != null
                  && pageLocator.getLocator() != null
                  && selenium.isElementPresent("//td[@class='pageTitle']")
                        && selenium.getText("//td[@class='pageTitle']").trim().equalsIgnoreCase(
                                    "Supplier Upload Status")
                        && selenium.isTextPresent(pageLocator.getLocator());
      }
      //overloaded method for simplicity
      public void launchPage(String fileNameOrJobID) {
            launchPage(new DefaultPageLocator(fileNameOrJobID));
      }

      @Override
      protected void initParent() {
            parent = new UploadHistoryPage(stb);
      }

//all page specific functionality goes here

}

Generated Report displays:

  • description of test case
  • browser name
  • duration
  • selenium command log
  • assertion/verification/information message Screens-shots for failure (also can configure for pass assertion/verification)

FAQ

Can I run each test without sharing browser session?

Yes, set property selenium.singletone=0

It will start new selenium session for each test. Still you can save execution time by configure to run methods in parallel

How to run test in parallel?

To run test in parallel you need to set parallel attribute appropriate value in configuration file. You can found configuration details in TestNG documentation.

Can I capture screenshot for passed assertion/verification?

Yes, set selenium.success.screenshots=1. It will automatically cupture screenshot and create link for pass messages.

VN:F [1.9.10_1130]
Rating: 10.0/10 (6 votes cast)

  

{ 12 comments }

The inspiration for this post is Patrick Welsh’s original post as well as code about the Self-Verifying pages in Selenium RC. While the actual pattern is very well explained in Patrick’s post-I thought I might share some experience as well as changes that I did.I have been using the self-verifying page pattern since about 2 months now and it’s been working pretty well for me and the team.To give a brief primer-If you are using Selenium RC,you might be writing the testcase something like

login.setusername(“xxx”);

login.setpassword(“yyy”);

login.submit();

assertTrue(landingPage.isLoaded())

The above is correct but it makes the test code clunky as well it relies on the test case writer to verify for some pages vs others.Not exactly a scientific solution.This is where Patrick’s pattern comes to help,which abstracts out the expected Page logic to the Page instead of the test.So the above code will look like

login.setusername(“xxx”);

login.setpassword(“yyy”);

landingPage=login.submit();

The constructor for landingPage object takes care of waiting for the landingPage to load.So it’s all good upto here.It also helped me in mapping my Page classes to the application pages more effectively.

But it still has some drawbacks.

For e.g-If there is a scenario where entering incorrect password will just reload the login page.Now if you are in Java world-you will need to write two very similar methods which do the same action but return a different class depending on the intended behavior.Depending on your workflow this can get quite cumbersome and difficult in a environment where the folks who write the Page classes are different than the one who write Test Classes.

public LandingPage submit(){

//click button

}

public LoginPage submit(){

//click button

}

Another issue I have with this pattern is that you only set one verification level.For e.g I verify that the landing page has loaded by making sure that some locator is present for an element.There might be a case where this verification is not sufficient.I would want to verify presence of more than one locators.I am sure this can be achieved with some more code hacking.

VN:F [1.9.10_1130]
Rating: 5.5/10 (2 votes cast)

  

{ 0 comments }

InfoStretch Test Automation Framework

[click to continue…]

VN:F [1.9.10_1130]
Rating: 9.7/10 (28 votes cast)

  

{ 27 comments }

I was highly excited to read the introduction of the Meux tool from Jamo Solutions. For a while now, I have been working on mobile QA, both manual and automation. Automation was always carried out using simulation tools such as Fiddler and Bayden UA Pick. But for certain testing the actual device became indispensible and that’s when manual QA had to kick in. I always hoped for a tool that would run my automation scripts directly on the phone.I was highly excited to read the introduction of the Meux tool by Jamo Solutions. It promised to do exactly what I was desperately looking for and that made it my new best friend.

Meux tool by Jamo Solutions available at http://www.jamosolutions.com/documents/downloadproduct.php is an add-in to QTP that records and plays back automation scripts on a mobile application just as it would on a regular desktop application. A pre requisite of having the Meux agent installed on the device and the QTP Add In installed on QTP machine is required. Both of these are available as a part of the installation package. The Meux Device Manager acts as the bridge between the add in and the agent. The installation and set up would require some extra technical expertise with port numbers being used by the agent clashing with the the port numbers already in use on the machine.

After the initial hiccups of setting up, I was highly thrilled to try out the application and see how useful it can be in my mobile automation tasks. Currently it supports only Windows Mobile, Blackberry RIM OS and Android OS with the limitations on the versions of the same. Recording on mobile application is almost as simple as on a desktop application. However the details and the excellence of the same can be debated upon. Meux tool does not support any customization of the Mobile OS which is very common on all the Windows Mobile Devices by HTC. As a workaround many function calls have been provided. But I am pretty concerned with the re usability of scripts across same OS on different devices or different version of the OS. With my concentration mainly on browser testing, I wasn’t highly impressed with the same.

The tool does not support many of the native functions on the mobile browser which are found on the regular browser. The browser and page objects have very limited number of native inbuilt functioanilities and much is left to the discretion of the coder. For instance, the GetChildObjects method found on a regular browser is absent on the mobile browsers inbuilt functionalities. This pretty much defeats the purpose of descriptive programming. To verify the presence of certain web object, you would have to get an array collection of all the objects on the page and then parse through each of them to find what you are looking for. This is not the most effective way of working on a highly dynamic page with high number of objects. Also, the object spy does not work on the mobile browser.

The analysis of the tool can be summarized through the following SWOT analysis of the same.

Strengths :
• Works as a bridge in between QTP Automation Tool and Mobile Device
• Records and Plays back automation scripts on mobile devices

Weaknesses:
• Does not support many important native functionalities of the web browser
• Does not support any customizations on the OS
• Object Spy does not work

Opportunities:
• Can re run same script across multiple devices with the same OS
• Can replace manual QA

Threats:
• Supports limited versions of the OS
• No agent for iPhones as yet
• Can behave highly unexpected at times

Having tried this, for the time being I would still continue using our current options viz. DeviceAnywhere and Perfecto Mobile from Nexperience. Perfecto Mobile provides automation scripting across various devices and platforms with a high level of re usability. But having said that, I am going to keep a keen eye on the development progress of Meux with heavy interest considering its excellent potential.

Another thing that I would like point out here is the excellent support from the Meux team especially by Jacques Wouters. In spite of being on different sides of the Atlantic and having a disastrous time difference, the support team made sure they were available when we needed it.

VN:D [1.9.10_1130]
Rating: 8.7/10 (15 votes cast)

  

{ 1 comment }

How to automate Localization Testing?

Description: Automated testing of web/windows application where application supports localized content.
Silk Test International automation tools supports localization testing i.e. testing the application with localization content. Also testing the localization content with no change in the automation scripts. Localization testing is absolutely essential if the application supports or localized to many countries and languages.

What is Localization testing and how can we automate it?
The following solution will show how to write the initial scripts and making use of the same test scripts to test the localization content of the application without doing any changes to the existing automation framework and scripts.

Solution:
Simply using the window id while declaring the objects from the windows application would work best. But not for all the objects from the application under test, window id is not available and end up writing the different test scripts for different localized content.

Other way of handling it out is, declare the object with the next available and reliable property which is Caption. Generating a unique key for each of the objects available in the application and used in the automation framework. And using the key to identify the objects from the application under test. And the unique keys are used to refer to the original properties of the objects from the application under test.

How it works?
Storing the objects property from the application under test in different excel sheets and differentiate the excel sheet name with the country name or the language name. Saving the object property corresponding to the unique keys would help to retrieve the particular object from the particular excel sheet based on the localized language the test script needs. So reading the particular object property from the excel sheet based on the requirement of the test case with the help of unique key would solve the purpose of the localization automation testing without writing the new test scripts.

Merits of this implementation:
1. Any automation tool which supports Internationalization/localization can make use of this approach.
2. Existing and available test script can be used for testing different localization content of the application under test.
3. Requires no change to the existing test scripts for testing the localized content of the application under test.
4. Efficient as declaring the objects with caption which is the reliable property from the application under test.
5. Duplication effort of scripting different test cases can be avoided.
6. Maintenance of the scripts with ease and delivering fix at one place for any change in the behavior of the application under test.
7. Adding a new localized value to the existing framework is easy and no change is required to the framework and can be done from adding a new excel sheet for a new country or language.

Demerits of writing new test scripts for different localized languages:
1. Writing different test scripts for different localized content is duplicating the automation effort.
2. Maintenance of the scripts is tedious, and every single fix needs to be delivered to different test scripts to make them work for a one small change in the behavior of the application under test.
3. Fix has to be delivered to the test scripts for change in the property name of localized objects.
4. Adding a new country or language needs new scripting of test case.

How can we implement this in Borland’s Silk Test Automation Tool?
Silk Test and Silk Test International Tools are products of Borland Corporation for Functional and Regression Automation Testing. Starting from Silk Test 2005 R1, localization testing is supported till the latest version of Silk Test 2009 R2.

We can make use of the above discussed method to implement the localization automation testing. Capturing or recording the objects from the application under test using the ‘Caption’ property. And generate a unique key for the object by the combination of numbers and characters. Open an Excel Sheet, store the captured caption of the object corresponding to the unique key created and save the excel sheet with the localized language or country name.

Open the application under test with different localized language in a browser and copy the caption of the same object for which the unique key is generated above and store the caption to a new excel sheet corresponding to the same key. And save the excel sheet with the new localized language or the country name.

Based on the country or the language requirement of the test case, reading the excel sheet for that country or language and fetch the object with the localized unique key.

Example of Gmail Login Page:

Object Type Localized Key English Caption German Caption French Caption
Text Box Text_UN_LoginPage UN_English UN_German UN_French
Text Box Text_PW_LoginPage PW_English PW_German PW_French
Submit Button SBT_LoginPage SBT_English SBT_German SBT_French
Label Login Successful SFul_English SFul_German SFul_French

Automating the test case for the above mentioned three different countries and languages, the caption for the objects on the pages are different but the localization key generated is same and can be able to pick up the relevant caption from the different excel sheet from the system.

EX: How to use it in Silk Test International,
Browser(“PageName).ObjectName(“Lacalized Key”).Event()

If the localized key is parameterized as a part of the test script development, then have a function that connects to the excel sheet and fetch the corresponding object property for the language and do the event such as click, select, set text or retrieve text based on the type of the object.

VN:F [1.9.10_1130]
Rating: 8.5/10 (6 votes cast)

  

{ 2 comments }