Posts tagged as:

selenium

What are the features provided by ISFW?

What is the use of listeners?

How multiple parents supported in page hierarchy?

What is the purpose of page locator and how to use it?

How can I implement dynamic page flow using page hierarchy design?

What is self-descriptive locator?

How can I create custom component/element?

How can I use existing driver session?

How can I make a test Data driven?

How can I provide desired capabilities when using ISFW?

Is any logging system used in ISFW?

What are the features provided by ISFW?

  • Extended Selenium
    •   Listeners
    • Custom commands
    •     Reporting
  • Extended WebDriver
    •       Provides extended webelemets
    •       Listeners
    •     Reporting
  • Extended WebElement
    •     Self descriptive locator
    •     Inbuilt wait, verify and assert methods
    •     Listener support
    •     Can be extended for Application specific custom component/elements
    •       Lazy loaded webelements
    •        Auto wait for Ajax – Dynamic elements
  • Choice of API for Development (Selenium RC and WD )
  • Descriptive report
  • Easy configurable test run
  • Enabling testing across multiple platforms with or without selenium grid
  • Test Results integration with test management tools
  • Integration with continuous integration/build automation systems.
  • Locale support
  • Flexible data provider for data driven tests
  • Auto retry analyzer for failing tests
  • Descriptive report

What is the use of listeners?

The general idea is that one or more objects (the listeners) register their interest in being notified of command execution on selenium/webdriver/webelement. The listener can perform some actions or track details before/after command execution as well as on failure. You can create listener by implementing appropriate listener interface of by extending adaptor class. To register listener set property “wd.command.listeners” for web driver listener and “we.command.listeners” for web element listener.

A simple but very useful example of listener is “listener for sendkeys”. As you know in webdriver send keys will append the text box, so each time we need to first call clear command and then use send keys command.

Without listener

firstName.clear();
firstName.sendKeys(“fname”);
lastName.clear();
lastName.sendKeys(“lname”);

With listener

firstName.sendKeys(“fname”);
lastName.sendKeys(“lname”);

 

Listener for above requirement can be implemented as below:

public class SendKeysListener extends IsWebElementCommandAdapter {

@Override
public void beforeCommand(IsExtendedWebElement element, CommandTracker commandTracker) {

if (commandTracker.getCommand().equalsIgnoreCase(DriverCommand.SEND_KEYS_TO_ELEMENT)) {
element.clear();
}

}

}

For another example refer comment-2205.

How multiple parents supported in page hierarchy?

Please refer comment-1816

What is the purpose of page locator and how to use it?

Please refer comment-1822 comment-1832

How can I implement dynamic page flow using page hierarchy design?

Consider the following case where page flow is configurable in AUT.

According to flow one page flow is Review Page -> Passenger Page – > Payment Page

Another possible flow is Review Page -> Payment Page.

Dynamic page flow

Blow sample shows you the implementation for such case.

public class ReviewFlightPage extends WebDriverBaseTestPage<ReviewPage>

implements PaymentLocators, PaymentsPageLauncher {

}

public class PassengerPage extendsWebDriverBaseTestPage<ReviewFlightPage>

implementsPaymentLocators, PaymentsPageLauncher {

}

 

public class PaymentPage extendsWebDriverBaseTestPage<PaymentsPageLauncher>

implementsPaymentLocators{

protecte void initParent() {

this.parent= (pageProps.getInt(“review.next.flow”) == 6)

? new ReviewFlightPage()

: new PassengerPage();

 

}

}

 

What is self-descriptive locator?

Locator is used for locating the element on the page. In addition, using self descriptive locator you can provide description of the locator/element as well. The description will be used in different assertion/verification messages.

String LOGOUT_LINK_LOC = “{‘locator’:'css=a.logout’,'desc’='Logout link’}”;

 

How can I create custom component/element?

Custom component can be created by extending Component class.

public class TestComponent extends Component {

public TestComponent(String locator) {

super(locator);

}

….

}

Custom component can be used in page class as below.

@FindBy(locator=”locator”)

TestComponent testComponent;

@FindBy(locator=”locator”)

List<TestComponent> testComponent;

 

How can I use existing driver session?

Following are the steps:

1. Webdriver session can be created through http://localhost:4444/wd/hub/static/resource/hub.html. After starting session you can perform manual steps on the browser!

2. You need to use only appropriate remote driver for this purpose. (e.g. firefoxRemoteDriver)

3. You need to provide session id by setting a property “webdriver.remote.session”. The session id can be found at http://localhost:4444/wd/hub/static/resource/hub.html from where you had created session.

How can I make a test Data driven?

To make any test data driven you can use IsDataProvider annotation on test method. You can provide data in CSV, JSON, MS-Excel file or from database.

@IsDataProvider(dataFile = ” resources/data/searchText.csv “)

@IsDataProvider(dataFile = “resources/data/searchText.json”)

@IsDataProvider(dataFile = “resources/data/testdata.xls”)

@IsDataProvider(dataFile = “resources/data/testdata.xls”, sheetName=”TC2″)

@IsDataProvider(dataFile = “resources/data/testdata.xls“, labelName=”TC2″)

@IsDataProvider(sqlQuery = “select col1, col2 from tbl”)

 

To configure using property

global.testdata=[<param>=value]

 

global.testdata=dataFile = “resources/data/${class}/${method}.csv”

global.testdata=dataFile = “resources/data/testdata.xls”; sheetName=“${class}“;labelName=“${method}”

global.testdata=dataFile = “resources/data/${class}.xls”; sheetName=“${ method }“

 

In above example you can notice ${class} and ${method} parameters are used which you can use as per your requirement.

To set data provider parameters for individual test method you can provide property as below:

<tc_name>.testdata=[<param>=value]

 

TC02.testdata=dataFile = “resources/data/testdata.xls”; sheetName=”TC2“

TC01.testdata= sqlQuery = ” select col1, col2 from tbl “

 

How can I provide desired capabilities when using ISFW?

For all driver set property “driver.extra.capabilities=[<capabilityname>=<value>]”

For specific driver set property “<driver>.extra.capabilities=[<capabilityname>=<value>]”

Example:

driver.extra.capabilities=acceptSslCerts=false;platform=WINDOWS

chrome.extra.capabilities=acceptSslCerts=true;chrome.switches=[--ignore-certificate-errors]

 

Is any logging system used in ISFW?

Yes, Apache logging services is used and logger object is available at test level as well as page level. Configuration is provided through log4j.properties file. For configuring logging as per your requirement please refer log4j documentation.

How can I Use Selenium grid with ISFW?

You need to set appropriate server, port and remote driver.

For example you can set following properties in application property file.

selenium.server=<ip or machine name>

selenium.port=<port used by grid/server normally 4444>

selenium.defaultBrowser=firefoxRemoteDriver

 

The same can be provided either by command line as system property or in testNG configuration file as parameter.

How can I run my test on cloud (Sauce Lab)?

Please refer: running-test-on-cloud-with-infostretch-test-automation-framework.

VN:D [1.9.10_1130]
Rating: 10.0/10 (1 vote cast)

  

{ 0 comments }

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 }

The quality engineering has gained the popularity as same way as software design and development and sometime more than some of the development technologies; as it is required for most of the application /systems. As being most recognized company in Quality engineering, we observed that most of the companies will have quality engineering department of their own even-though the software development is out sourced to other vendors.

Now a days, software test engineering (QA) is not just limited to test case managements with tools like QMetry etc. and test execution manually. But there are many areas like test automation, performance / load testing, security testing, SOA testing and code review with testing etc. being introduced and widely used by each departments at different level. In all of this, the test automation is very much popular as it reduces the regression test duration plus easily integrated with continuous build systems etc. to result in best ROI over the time.

There are many automation tools available which can be used by any manual test engineer for regression tools like Selenium IDE, Sahi etc.. Still once you start the automation, there will be  some more demand  from your QA Manager / Test Lead / Project manager / CTO about test results, debugging, reusability, continuous integration, maintainability, execution from cloud etc. and that will required you to develop the framework using scripting language / programming language.

Amongst big group of automation tools, selenium is the only tool which supports many programming languages ranging from simple  like HTML to complex like Ruby/Java/C# to automate the test bed of your web application. As selenium supports variety of languages for automation, manier  get confused to select the suitable language for automation. Mainly the selection of laungage depends on many different crieterias as well. Therefore  to overcome from this delta situation, I tried to get input from different big players in automation world about the preferred language and based on which crieteria they select that etc. We had run the poll for same for quite a month long time and able to get good information as descried in following sections of this post.

Overall Result:

Language preferred for Selenium Test Automation Project? Write in comment for other languages.

Language preferred for Selenium Test Automation Project? Write in comment for other languages.

We can see that JAVA got around 77% votes from total 194 votes worldwide.  The HTML, PHP and Javascript etc. was not part of selection but few peoples are using this for their test automation.

We have got some language selection criteria based on the feedback during this poll are:

  1. SUT development environment
  2. Open Source Tool
  3. Material/libraries available for language
  4. Performance and Transaction Time
  5. Easy to code, IDE
  6. Language exposure to automation engineer

Etc.

If we have to rate these criteria’s, then the first point will win the race and most of has voted based on this criteria.

Brainstorming: Based on first preference and poll data, can we think that JAVA is most popular in development as well!!

The consolidated feedback and related information is as below.

1. SUT development environment

Many time, we (auto architects) think to use the language as same as the application under test development platform/language. Because it help us to use the same tests as unit tests and helps us for customization etc.

“I prefere Python because I like this language and I used if for wide range of tasks before I start automation with Selenium. Python has everything what I need for any purposes. But Current project based on PHP, so one of requirement was that automation will also based on PHP” – how can you leave your preference.

Helps in unit testing – “ Being able to write Selenium tests in JUnit allows me to do end-to-end testing of our server-side Java application and browser clients. So I can call into a backend Java application(handy for me when doing test setup and cleanup) and control the browser from the tests. I can also easily take automated screenshots of the browser view.”.

Further from other expert, “It really depends on what your goals are. Personally I prefere using the language the app is written in. Of the benefits its nice to be using the same language and tool chain the developers are using to make collaboration and integration points simpler.”

Manish says, “I’m working in a product that uses Selenium RC with C# and codedUI and I’m enjoying it and the reason of choosing c# is the same app written in .Net”

More specific quote “For your tests to be economically maintainable, they need to be in a Turing-complete language (e.g. not HTML-based). That said, assuming either: 1. There’s no dedicated QA team and testing is an integral function of Development or 2. there’s a dedicated QA team that works closely with development, the only responsible choice for your scripts is in the language of the application under test. Otherwise, cooperation with Development for test case issue resolution will be difficult as not all members may be familiar with the script language.”

2. Open source Tool

We all know that why JAVA won the race, because it is open source.

“Eclipse with JAVA and selenium is free, however .NET IDE is not free. There is an open source .net IDE called mono that could be used with selenium;”

Ratankumar adds “ I’d prefer JAVA, as it is also open source and easily available for download.”

3. Material/Libraries available for language

The availability of the documentation / samples / tutorials can matter the selection of the language for your selenium (others as well) automation projects very well because not all test automation engineers / architectures will have strong programming language experience. So this type of supporting material helps them for quick start. Selenium is the very best automation platform which gives us the wide variety of language selection for automation and which make ease for the new people to quick start with the help of this kind of supporting material.

“I favor Perl because I can use the martial from CPAN.org to build a framework. I have lot of modules that I can interface to the selenium api” – Perl selection for automation based on this criteria.

Kshitij describes in same line “ I prefer java/junit with Eclipse, due to easy available solution on web and most other plugins and technology for automation is available in Java.. So its easy to integrate with selenium.”

C# Documents seems ahead of all, “ C# has a ton of documentation and tools that can complement your script development efforts.”

Do you think same “ There’s much less user support for Perl, but having that extensibility opens up many avenues. I’m looking forward to checking out the Webdriver Perl bindings.”

4. Performance and Transaction times

Sometimes we think on this before starting the automation development.

Selenium can perform well with Java. Do you agree with “Selenium is built on JAVA and runs through a JVM. So I suggest using the language that selenium was created in.”

5. Easy to code, IDE

Definitely this is the easiest criteria as well, but test automation sometimes required customization in results presentation, looping based on data etc. So I am not sure that whatever language we will define as “easy to code” will be good selection for test automaton. Still we can find some other supporting interfacing language etc. like HTML is very easy so try to use Java Script extensions with this will definitely help you to keep it easy to code plus some level of customization. Let me describe same thing in users’ words: “I prefer html tests/cases with selenium server + js extentions + Hudson”.

Also, IDE does matter in the selection as it helps us to make our coding with easy due to context sensitive help, auto complete etc. C# IDE Visual Studio, Java IDE Eclipse etc. are good IDEs and is important point in language selection decision making process.

“If you have access to the VisualStudio IDE you cant go wrong with that”. I like this.

6. Language exposure to automation engineer

Sometimes we do not disclose or mention this criteria, but I think it is always get hidden consideration for language selection.

Are you thinking same? “I personally prefer Java because that’s the language I’m most familiar with. However, if the project and its timeline provided the opportunity for my learning curve, I would love to try out some other languages – it for nothing more than to see what differences there are.”

Anand is asking us with explanation, “Depends on which language you are already comfortable in, isn’t it? If you are comfortable in JAVA you don’t learn PHP to write selenium tests. As far as I know, most of the bindings provides the same features. And thanks to people behind Selenium for making this possible !”

In short, all points has their own pros and cons but this poll has created a platform to help someone to ask related queries to other who using same language.

At last, thanks to all for voting and commenting. We will come up with something similar and useful topic again!! 

courtesy:

  1. Selenium Automation User Group
  2. Infostretch Selenium Test Automation Framework
  3. All the linked in users who voted and commented on poll : “Language preferred for Selenium Test Automation Project? Write in comment for other languages.”

Thanks and Regards,

Akhilkumar Patel

Waiting for your suggestions and queries!!

 

 

VN:F [1.9.10_1130]
Rating: 9.0/10 (3 votes cast)

  

{ 0 comments }

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 }

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 }

While there are bunch of posts on the web for this issue,It’s so annoying when you face this issue.I spent about half a day to solve this issue even with all the help around it.So for the benefit of someone else here’s what i did

Problem:If you are using a self signed certificate or the web site that you are testing uses an https protocol,there is no way in Selenium to automate the accepting of the certificate part and the browser will always request the user to accept the certificate.Not very helpful if you want to run a suite of tests without manual intervention

Solution:The solution is specific to Firefox and was tested on Windows 7 and Windows XP with FF 3.6

a)In Windows->Start->Run

b)Try one of the following

i)firefox -P no-remote

ii)firefox -ProfileManager no-remote

More information can be found from Firefox help

c)If all goes well,the ProfileManager should open and there should already be a “default” profile.This is the profile used by FF everytime you open a new firefox window  or when Selenium RC launches a firefox window

d)Create a new profile

e)Give the path of this profile like “C:\seleniumprofile” and not the default folder chosen.There is a risk you might mess with the default profile

f)Once done->Select “Do not ask at the startup” and launch your new profile

g)Go to your test site and manually accept the certificate once.To make sure Selenium RC launches this new profile,bookmark a site like cnn.com and close the browser

h)now when you start the selenium server you need to start it like

java -jarselenium-server.jar -firefoxprofiletemplate C:\seleniumprofile

i)Now when you run your tests and the selenium RC launches the browser,quickly make sure it has launched the new profile by going to the bookmarks and verifying it’s has the bookmark added by you.

Also if you want to use your default profile with your normal FF use,open the profile manager once again ,select the default profile and select “do not ask at startup” and launch the browser.you should be all set.

Good luck!!!!

VN:F [1.9.10_1130]
Rating: 4.0/10 (1 vote cast)

  

{ 2 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 }