Monday 22 December 2014

Adding firebug add-on to the FirefoxDriver instance

When automation scripts are executed, firefox browser is launched with out add-ons in it.
Adding the firebug add-on to the the FirefoxDriver instance is possible with the below approach.

1. Download the "firebug-<<version>>.xpi" file in Internet Explorer browser.
https://addons.mozilla.org/en-US/firefox/addon/firebug/


Note: if the url "https://addons.mozilla.org/en-US/firefox/addon/firebug/" is accessed in firefox browser, add-on will be directly installed in to firefox browser.

2. Click on "Download" button.

3. Click on "download anyway" link.

4. Click on "Save"



Program:
import java.io.File;
import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class FF {
    public static void main(String[] args) throws IOException {
        //Path of the firebug addon(i.e. firebug-<<version>>.xpi file)       
        File addonpath = new File(System.getProperty("user.dir")+"\\other\\firebug-2.0.7-fx.xpi");
       
        FirefoxProfile firefoxprofile = new FirefoxProfile();
       
        //This will add Firebug add-on to the new profile created.
        firefoxprofile.addExtension(addonpath);
       
        //Pass the Firefox profile to the FirefoxDriver instance.
        WebDriver driver = new FirefoxDriver(firefoxprofile);
        driver.get("http://www.google.com");
       
        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("Webdriver");
    }
}
Note:  Above program is not integrated with TestNG/Junit, execution is done from the main method.

Executing the program in Debug mode:

Script execution is paused at break point.

Firebug add-on is added to the firefox browser launched by webdriver api and is visible on the top right corner of the browser.
By default there will be no add-ons present in the firefox browser launched by using webdriver api.
This add-on(i.e. firebug addon) is added only if the firebug extension is added to the FirefoxDriver instance. ex: WebDriver driver = new FirefoxDriver(firefoxprofile);

Press keyboard 'F6'
 


 Press keyboard 'F8'

Wednesday 17 December 2014

Executing simple python programs in Eclipse IDE

IDE helps in preventing the simple syntax errors while writing the python program's,  we can write, compile and execute the code in IDE. Productivity is more using IDE(i.e. scripts can be developed very fastly)

Below procedure demonstrates executing the python programs in Eclipse IDE.

Prerequisites:
1. Python is installed, click here for python installation.
2. PyDev extension is installed in Eclipse IDE, click here for PyDev extension installation

Executing simple python program:
Create new python project.
Select "File" >> "Open File" >> "Other"

Expand "PyDev", select "PyDev project" and click on "Next >" button.

Enter the project name and click on "Finish"button.



Create "PyDev Module":
mouse right click on the project created, select "New" >> "PyDev Module".

Enter the module name and click on "Finish" button




Simple python program:
'''
Created on 15-Dec-2014

@author:
'''
print("My First Program");


Executing the python program:



Tuesday 16 December 2014

Installing Pydev Extenstions for Eclipse IDE

Once Pydev Extenstions is installed  in Eclipse IDE, developer can write and execute the python program in Eclipse IDE.

Prerequisite:
1. Python is already installed in the system, click here for python installation.

2. PyDev requires java 7 in order to run.

3. Installation folder should have the permissions to write(i.e. install)

4. Eclipse version should be 3.6.1 or greater, since there are some issues while installing in shared folder with Eclipse 3.6.0
Refernece: https://bugs.eclipse.org/bugs/show_bug.cgi?id=322929

Installing Pydev Extensions:
Open the Eclipse IDE, Select the menu "Help" >> "Install New Software"

Click "Add" button

Enter the name & location and click on "OK" button.
location url: http://pydev.org/updates

Select the checkboxes and click on "Next" button.


Click on "Next" button in 'Install Details'

Accept the license agreements and click on "finish" button.


Restart the Eclipse IDE and verify PyDev is installed.

Verify PyDev is installed, Select "Window" >> "Preferences"


Set the Python Interpreter:
Click 'Browse' button, select "python.exe" file and click on "OK" button.






Python Installation

Below procedure demonstrates the python installation on Windows OS.

Python can be downloaded from below URL
https://www.python.org/downloads/

Click on "Download Python 3.4.2" button.

Click on "Save File" button.

python-<<Version>>.msi is downloaded

double click "python-<<Version>>.msi" to install

Verify python is installed in the system.


Python bindings for Selenium

Selenium Python binding helps in accessing the Webdriver API, to write the automation scripts using python programming language.
Using Webdriver API, automation scripts can be executed in Firefox, InternetExplorer, etc.

Prerequisites:
1. Python is already installed, click here for python installation.
2. Eclipse IDE is already installed.
3. PyDev extension is installed in Eclipse IDE, click here for installing PyDev extension for Eclipse IDE.

Use 'pip' to install selenium package for python.

Below procedure  demonstrates installing selenium packages in python:

Navigate to 'Scripts' folder present in the python installation folder.


Run command 'pip install selenium' for installing latest selenium package.



Restart the Eclipse IDE, to verify selenium packages are installed.

Verify latest selenium packages are installed:

Click here for additional configuration.

Simple python automation script:
Writing the simple automation script using webdriver api in python.

 '''
Created on 15-Dec-2014

@author:
'''
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()

browser.get('http://www.google.com')
assert 'Google' in browser.title

# Find the search box
elem = browser.find_element_by_name('q') 
elem.send_keys('seleniumhq' + Keys.RETURN)

browser.quit();

Executing the automation script.
Automation scripts are executed in python language using webdriver api.