Tuesday, August 21, 2012

Handling alert box using AutoIT

AutoIT is a scripting language designed for automating the Windows GUI. It uses simulated keystrokes, mouse movements and window manipulations.

Here we are going to use AutoIT for handling authentication boxes like below,



Step 1: 

Download the latest version of AutoIT.

Step 2: 

Write the code and Save it as 'Authentication.au3' 
(au3 is the AutoIT format)


Use the below code
WinWaitActive("Authentication Required")
Send("Username")
Send("{TAB}")
Send("Password")
Send("{ENTER}")

Step 3:

After that, right click on your Authentication.au3 file and click 'Compile Script'
This will covert your AutoIT script into an executable file

Step 4:

Now go to your Selenium code, and add the below line.

Runtime.getRuntime().exec("C://Path//Authentication.exe");



Thursday, August 9, 2012

Handling alerts in Selenium webdriver


Handling alerts in Webdriver :

Import this package in your script.
#import org.openqa.selenium.Alert;

For accepting the alert box:
Alert al = driver.switchTo ().alert ();
al.accept ();
       
For cancelling the alert box:
Alert al = driver.switchTo ().alert ();
al.dismiss ();

For getting the text of the alert box:

Alert al = driver.switchTo ().alert ();
String s = al.getText();
System.out.println(s);

Monday, August 6, 2012

Junit test suite for Selenium Webdriver 2.0

Using Junit test suite, we can run the test cases in Selenium Webriver. 

Here is the sample snippet.

// Test class1

public class c1 {
    @Test
    public void one(){
        System.out.println("one");
    }

}

//Test class 2
public class c2 {
    @Test
    public void two(){
        System.out.println("two");
    }

}

//JUnit suite

import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@SuppressWarnings("unused")
@RunWith(Suite.class)
@SuiteClasses({c1.class, c2.class})
public class suite {

}