Sunday, September 22, 2013

Welding all the pieces together - Robot framework does it with ease.

Its been a forced transition from Programming language platform to a keyword driven platform as far as the automation scripting is concerned for my new project. Initially I was really worried about from  delivery perspective as well as from technical standpoint. It didn't last for more than a day and slowly I found the rhythm and now enjoying the comfort for the keyword driven framework from the first time.

As long as I started writing the scripts I thought of sharing some good examples to others who would like to enjoy this easiness as well.

Keep an eye on this space for useful tips for robotframework.

Initially I will be concentrating on the web testing using the selenium and web service testing using the http libraries. Also expect example for database testing as well.  



https://code.google.com/p/robotframework/

Friday, February 1, 2013

Jemmy the superagent for Java App automation

Do you have a java application candiate, for testing? Bored of the repetitive manual UI interaction span over the iteration after iteration? Ever dreamt about a robotic agent who does all the UI simulation for you? Jemmy is your saviour.

Monday, June 6, 2011

TestRunner - A simple interface to pick and run your test from huge test suite.

Ever since I started writing the automated tests suites for web projectes, I was looking for an interface from which I can pick the a particular test run it and see the result on the same interface. I talked to guys about this and I understood that most of the guys dealing with the test scripts are in need for some thing like I dreamt off. I searched everywhere I could but with n luck at all.
then I started thinking about implementing a simple interface by myself. I definitely wanted an interface that mimic the dashboard of the continuous integration tools like cruise control and the hudson. But with more client side interaction for a good user experience.

Since most of our test scripts were written in java built upon TestNG I decided to write a custom parser with which I can generate a list of test classes and test methods. Since I posses mere basic knowledge of Java, I queried this to many colleagues and searched on the web. After days of wantering I successfully wrote a simple parser which build a map with classes and test methods. Then build the interface with ExtJs framework which displays a tree structure for the testsuites. When I showed this to my colleagues everyone encouraged me to build features on to this and I am currently working on it.

I am sure many of the Engineers who maintain the huge stack of test scripts will thrilled to see an interface like this. So I thought of putting this public and uploaded the code to git hub.

Checkout the code from here https://DenZie@github.com/DenZie/TestRunner.git

Wednesday, February 16, 2011

See Remote Webdriver in action.

Lets think about from the continuous integration perspective. You have a CI server setup using hudson bamboo or whatever you like and you want to run all your tests on different OS browser combination. How would you achieve that? Webdriver comes to your rescue. It's basic architecture is so flexible that you can get most out of it.

Here is what you have to do

You can dedicate some boxes having different OS and browsers as a remotewebdriver. All you have to do is just download the latest standalone server from here http://code.google.com/p/selenium/downloads/list When I srite this the latest distribution is http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.0b2.jar&can=2 and run the server from youtr teerminal using this command java -jar selenium-server-standalone-2.0b2.jar


Your server is now ready to act as remotewebdriver server. Now what you need is to do some client side coding. Dont worry its just few lines and thats bread and butter for you. Here is what I wrote after digging through the blogs and group posts


import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class remote {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
URL remoteAddress = new URL("http://rwd:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(remoteAddress, desiredCapabilities);
driver.get("http://www.google.com/");
driver.quit();
}
}

And when you run this test, you see the firefox windows pops up on your remote server and load the google page.


That give me lot of freedom to work with. I wish I could explore all the potential that this great toll has! 



Webdriver and flex-pilot together as flexdriver for flex automation


Good news for all those who wants to automate their flex apps using the selenium. 
If you are in love with webdriver aka selenium-2 flex pilot is the best companion you can get towards the goal of automating your flex apps.

Here is the sample code which implements a flexdriver which inturn use the webdriver and invoke the flex driver api using the javascript executor.

Before you see the flexdriver implementation and sample code which use the flex driver with the help of the sample application published on the github as part of the flex-pilot project Here is facts which you should do before thinking bat using the flexdriver.

https://github.com/mde/flex-pilot/wiki/setup-from-scratch-notes has the details if you start from scratch.
Or get started with flex-pilot here https://github.com/mde/flex-pilot/wiki/getting-started Or here is the copy of the content 

  • right click, save as for both those swfs in the download page: flex-pilot downloads
  • put them in the same directory as your application swf
  • add the lines outlined here to your application: flash-testing-setup and rebuild it
  • uninstall selenium ide, and get the latest here: selenium-ide-1.0.7.xpi
  • download the latest flex-pilot-x extension and install it from here: flex-pilot-x/flex-pilot-x.xpi
  • open firefox to the URL of your flex application, open the selenium IDE, click record and operate your flex application
  • verify that actions are appearing in the selenium IDE as you navigate around the flex application.
  • check out the API to see all of the available functionality


I have used the webdriver and implemented the "type" and "select" commands  from Flash Controller API using the javascript executor of webdriver.
the sample flexdriver class looks like this.


package com.selenium.flex;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

public class FlexWebDriver{
private  WebDriver webDriver;
private  String flashObjectId;

public FlexWebDriver(WebDriver webDriver,String flashObjectId) {
this.webDriver = webDriver;
this.flashObjectId = flashObjectId;
}
public void type(String locator, String value) {
((JavascriptExecutor)  webDriver).executeScript("document.getElementById('" + flashObjectId + "').fp_type({" + locator +", 'text':'"+ value +"'})");
}
public void select(String locator, String value) {
((JavascriptExecutor)  webDriver).executeScript("document.getElementById('" + flashObjectId + "').fp_select({" + locator +", 'label':'"+ value +"'})");
}

}


and the sample test class which uses the flexdriver mthos like "type" and "select" is quoted below

package com.selenium.flex.test;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.testng.annotations.*;

public class flexTest {

WebDriver driver;
FlexWebDriver flexDriver;

@BeforeMethod
public void startSelenium() {
driver = new FirefoxDriver();
flexDriver = new FlexWebDriver(driver"testApp");
}

@AfterMethod
public void stopSelenium() {
driver.close();

}

@Test
public void testFlex() throws InterruptedException {
driver.get("http://localhost/fp_demo");
Thread.sleep(10000); // Wait till flash loads completely.
flexDriver.type("'name':'UITextField18'""Flex Pilot Rocks.");
flexDriver.type("'name':'UITextField23'""Success.");
flexDriver.select("'name':'comboTest'""Alex");
}

}


Tuesday, February 15, 2011

webdriver aka selenium-2 -Run tests in parallel.

Ever since I started exploring the selenium-2 aka webdriver one of the major question irritated me is the fact that webriver doesn't support to run the tests in parallel. But even then I stick with the most promising web automation tool. Seeing the active community and the active development effort of this magnificent team, I always had the strong believe that we will taste that feature in the near future itself.

Time has run away and selenium-2 matured from its initial alpha releases which span over 7 releases to the second beta release. Now you have the selenium-2b2 available for download.

Selenium has matured and it slowly but steady growing to support the tets to be run in parallel. Seeing some of the posts in blogs and some groups, I smell the blood and decided to give it shot. I wrote a test class using the testNG framework and decided to run that test in parallel mode. I couldn't believe why I didn't try this earlier! And the reason for my surprise is that the tests run so smoothly and I saw the browser windows poping up simultaneously and I saw the standard Google test running on them.


Here is what I did

I  wrote a test class using testNG annotations

import org.openqa.selenium.By;
import org.testng.annotations.Test;

public class Parallel {
@BeforeClass
@Parameters ("browser"})
public void baseSetUp(String browser) {
driver = makeDriver(browser);
}


@Test
public void ffAndIe() throws InterruptedException {

driver.get("http://www.google.com");
Thread.sleep(2000);
driver.findElement(By.name("q")).sendKeys("Selenium");
driver.findElement(By.name("btnG")).click();
}

public WebDriver makeDriver(String browser) {
WebDriver driver = null;
if (browser.equals("ie")) {
driver = new InternetExplorerDriver();
} else if (browser.equals("firefox")) {
driver = new FirefoxDriver();
} else if (browser.equals("chrome")) {
driver = new ChromeDriver();
}
return driver;
}

@AfterClass
public void tearDown() {
driver.quit();
}

}

And thats my testNG test class and Now I wrote a testNG suite.xml file inorder to run the tests.
And here its is



<suite name="DenZie's test suite" parallel="tests" thread-count="3" verbose="10">
<test name="Test on FF">
<parameter name="browser" value="firefox"></parameter>
<classes>
<class name="Parallel"></class>
</classes>
</test>
<test name="Test on IE">
<parameter name="browser" value="ie"></parameter>
<classes>
<class name="Parallel"></class>
</classes>
</test>
<test name="Test on FF- 2"></test>
<parameter name="browser" value="chrome"></parameter>
<classes>
<class name="Parallel"></class>
</classes>
</test>
</suite>


All you to do is go to eclipse and run the test against this suite.

And Enjoy the sight of all three browsers opps up load the google page and search for you what you most care about "selenium".

webdriver rocks :)



webdriver code to bypass http authentication.

My fellow colleagues were asking me on tips to bypass the apache/http authentication. They badly want that hack in place since there is no compromise for the apache authentication to be removed from the QA code base.

I digged old code bases and backups and dust it off. finally I decided to write the hack code based on the webdriver. Basically I derived this from other blogs and groups.

Here is what It looked like.


import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class demo {
public static void main(String[] args) throws InterruptedException {
String url = "http://user:pass@demo.mydomain.com/";
String email ="tester@test.com";
String pwd = "password";
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.phishy-userpass-length", 255);
profile.setAcceptUntrustedCertificates(true);
profile.setPreference("network.automatic-ntlm-auth.trusteduris", "demo.mydomain.com");
FirefoxDriver driver = new FirefoxDriver(profile);
WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, "");

selenium.open(url);
selenium.click("link=Log In");
selenium.type("cust_email", email);
selenium.type("cust_pass", pwd);
selenium.click("//input[@value='Log In']");
}
}

As you can see from the code, its a hack for the firefox using the profile settings. you can use this code to access any site based on the apache authentication using the firefox.