Showing posts with label Simple example. Show all posts
Showing posts with label Simple example. Show all posts

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, June 25, 2012

Working with Frames


java.util.List<WebElement> f = driver.findElements(By.tagName("iframe")); 
            System.out.println(f.size());
             if(f.size()>0) { 
                   for (WebElement frameid : f){ 
                         
                         if(frameid.getAttribute("id").equals("frame_name"))
                         {
                         
                              driver.switchTo().frame(frameid);
                             
                         }
}
}

Tuesday, May 15, 2012

Introduction to Web Driver 2.0 with a simple example

A simple way to begin web driver 2.0. Install Selenium IDE in your firefox browser and create the script by record and playback method. For instance, try google or irctc site.


Convert your code into Webdriver by Export test case option available in IDE.


A sample script is given below,



public class google {
private WebDriver driver;


@Before
public void setUp() throws Exception {
driver = new FirefoxDriver(); //Initializing firefox driver
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
}


@Test
public void test() throws Exception {
driver.get("http://www.google.co.in/");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("Testing");
driver.findElement(By.id("gbqfq")).sendKeys(Keys.ENTER); //Hitting Enter for search
driver.findElement(By.linkText("Software testing - Wikipedia, the free encyclopedia")).click();
}


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

}

}