Friday 28 June 2013

Selenium RC example program


Selenium RC(Remote Control) was familiar automation framework, which is released to overcome the disadvantages of the selenium IDE. Since Selenium RC supports for

  • multiple browsers
  • multiple languages and 
  • multiple platforms

 it became the favorite automation tool of the automatians. Selenium is an open source tool, Obviously this is also one of the major reason to become popular.

Selenium RC supports for the following languages,

  • C#
  • Java
  • Python
  • Perl
  • PHP
  • Ruby
  • Java script


Components of Selenium RC:


  • Selenium RC Server
  • Client library


Selenium RC Server:


Selenium Server(selenium-server-standalone -<version number>.jar) receives Selenium commands from your test program, interprets them, and reports back to your program the results of running those tests.

The RC server bundles Selenium Core and automatically injects it into the browser. This occurs when your test program opens the browser (using a client library API function). Selenium-Core is a JavaScript program, actually a set of JavaScript functions which interprets and executes Selenese commands using the browser’s built-in JavaScript interpreter.

The Server receives the Selenese commands from your test program using simple HTTP GET/POST requests. This means you can use any programming language that can send HTTP requests to automate Selenium tests on the browser.

Client Library:


The client libraries provide the programming support that allows you to run Selenium commands from a program of your own design. There is a different client library for each supported language.

A Selenium client library provides a programming interface (API), i.e., a set of functions, which run Selenium commands from your own program. Within each interface, there is a programming function that supports each Selenese command.

The client library takes a Selenese command and passes it to the Selenium Server for processing a specific action or test against the application under test (AUT). The client library also receives the result of that command and passes it back to your program. Your program can receive the result and store it into a program variable and report it as a success or failure, or possibly take corrective action if it was an unexpected error.




Sample program


import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class TestNaukri {

public static void main(String[] args) throws InterruptedException {

String expected = "G.Elangovan";

Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.naukri.com");
selenium.start();
selenium.open("/");
selenium.windowMaximize();
Thread.sleep(5000);

selenium.type("id=username", "tester@gmail.com");
selenium.type("id=password", "password");
selenium.click("name=Login");

Thread.sleep(5000);
String actual = selenium.getText("id=nameDisplaySpan");

System.out.println("usernmae is: "+actual);

boolean condition = expected.equals(actual);
System.out.println(condition);

selenium.close();
selenium.stop();
}

}

How to start the selenium server:


Before we run this program we have to start to the selenium server as below,

  • Open the command prompt
  • Go to the path of the folder, where you keep selenium server
  • Enter the command 
  •         java -jar selenium-standalone-server<version-number>.jar
  • Hit the enter key
Now selenium server is started.

Now if we run the above sample program, it will run successfully.

Friday 7 June 2013

How to use Appium Inspector???....

Appium Inspector


Initially when I started to learn about appium inspector and its usage, I did not get better documentation with the steps on it. Finally I got it with the help of appium google group and some exploration. So I thought to document that here, and it would be helpful for new starters...

I used appium inspector for the following purpose,


  • To understand the element hierarchy
  • To find the xpath, name and value of the objects
  • To record the manual actions


The steps to use appium inspector are as below,



  • Initially download the appium.app from here, then add it to the Applications in your machine
  • Now Double click on the appium.app, it will open the appium server with the default IP Address 0.0.0.0 and  the port 4723 as below,
Appium Server



  • Next we have to specify the app, which we want to open in appium inspector.  
                 1. Check the check box 'App Path', Now 'Choose' button is enabled

                 2. Click on the 'Choose' button and select your .app file from your local, e.g. Recipes.app

                                 
Add the .app file in the server
                                 

  • Now click on the 'Launch' button, Once you launched the appium server, the blue color icon, which present beside the 'Launch' button is enabled.
       
Blue color icon is enabled


  • Click on the blue color icon, it will open up the appium inspector and simulator with your application as below,


Appium Inspector



  • Now you will see the element hierarchy of the application in the first column of appium inspector.
  • Choosing the particular element will display ,

             1. Its childs in the second column
             2. Highlights the object in the app.
             3. Element's xpath and its attributes at the right bottom corner.


Parts of Appium Inspector

  • And you can do actions by clicking on the action buttons Tap, Swipe etc displayed in the left bottom of the appium inspector.

  • By clicking on the 'Record' button we can create the automation script as below, you can see the recording script below the appium inspector,


Recording