Fish

Monday, March 3, 2014

Uploading a file using AutoIt

As we all know, Selenium will not support window based elements. To upload/download we need to use some third party tools.

Below post explains how to upload a file from local drive using AutoIt.


(This code is to select a file from window after clicking on browse button from web page, After this we have click on upload button from web page)

WinWaitActive("File Upload")
Send("C:\Temp\Test.txt")
Send("{ENTER}")

Write this code in Notepad and save the file as “Upload.au3”
Right Clicked on the created file “Upload.au3” and click on Compile Script.
You will get “Upload.exe” file

Call this file in Selenium script or in RFT script as below:

Process proc = Runtime.getRuntime().exec("C:\\Temp\\ Upload.exe");

Sample Selenium Code using AutoIt upload:

public class Upload {
public WebDriver driver;

@Before
public void setUp() throws Exception {
driver= new FirefoxDriver();
driver.manage().window().maximize();
}
@Test
public void testTestScenario1() throws Exception
{
driver.get("http://www.2shared.com/");
driver.findElement(By.id("upField")).click();
Thread.sleep(5000);
Process proc = Runtime.getRuntime().exec("C:\\Temp\\Upload.exe");
driver.findElement(By.xpath("//input[@title='Upload file']")).click();

}
@After
public void tearDown() throws Exception {
driver.quit();
}
}



Sunday, March 2, 2014

Cross BrowserTesting using Selenium Webdriver and TestNG

This is an attempt to explain the feature of selenium webdriver and TestNG.

Generally we will run a single test case or script at a time. If you want to run  a single test on different browsers it is possible with selenium webdriver and TestNG. Test will be executed parallel in two browsers.

Lets see..how we can achieve this

Prerequisites:

Sample Script:
Create a sample webdriver script using TestNG and in that script define a parameter using @Parameter annotation.

Below is the sample script:

Create TestNG:
Create a testNG.xml file to run your script. Parameter value we can pass it from here.

Below is the sample TestNG.xml file




Run your TestNG.xml file and three browsers will open and script will run on 3 browsers parallel.



Tuesday, February 25, 2014

Screenshot on Failure using Selenium WebDriver

Below post explains you how to capture screenshot when scripts fails using Selenium WebDriver.


In this script I used simple try --Catch and Finally blocks..if any error occurs in try block control will go to catch block.

In Catch block i have written code for capturing screenshot and flag is set to true.

If the flag is true then finally block statement will be executed.

In Finally block  I have written exception that will raise an exception so that you can see the results if the script as failure. 

Below is the code.....

Saturday, January 4, 2014

New Features in Selenium IDE (2.5.0)

I Just noticed on 2nd Jan that a new version of selenium is released. I Just had a glance at release notes there are 3 enhancements and few fixes to existing issues.

But today when I open selenium IDE I saw the enhancements..they are really useful...

Below is Release Notes for 2.5.0













I would like to talk about a new Enhancement:

1. Select an element for a command by clicking on the element in the browser window

This is a new feature added to selenium IDE.

They added new Button Select in the Target field.


How it works:

Select a row in selenium IDE test case Pane
Click on select and move your cursor to the element which you want to locate.

In below example i would like to find locator for "Search Selenium:"


It will automatically identify the xpath or CSS or any other appropriate way to find locator...

Try this feature this is really awesome feature from Selenium.

2. Start playing a test suite from any test case (Using right click menu)

If you already have a test suite in place (Ex: A test suite with  5 test cases) and you want to run from 2nd test case.  The newly added feature supports those kind of requirement.

Just you need to right click on the specific test case in test suite and select Paly Test suite from here. Execution of Test Suite starts from that particular test case.

See below screenshot for more details


3. Add a new test case using a keyboard shortcut (ctrl-N or cmd+N) 

From selenium IDE you can a new test case by using keyboard shrotcut CTRL+N..It will automatically add new test case in selenium IDE.

Hope all these feature are very helpful for selenium IDE users...

HAPPY NEW YEAR...





Wednesday, January 1, 2014

Get row count based on row text

Below post explains how to get the count of the row.

Generally we will have scenarios like get a particular text from the table, but in this example i am trying to get the number of the row based on the row text.

In this example a table contains number of rows and each row represents a company name. If we have row number we can get the company name easily...the below scenarios is different  ..based on the company name it will find out the number of the row.