Showing posts with label Selenium web driver. Show all posts
Showing posts with label Selenium web driver. 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);

Saturday, May 19, 2012

Maximizing windows in webdriver

Maximizing windows in webdriver


//Include this package in your script.
import java.awt.Toolkit;


//Add this snippet to your code.
 Toolkit toolkit = Toolkit.getDefaultToolkit();
 Dimension screenResolution = new Dimension((int)toolkit.getScreenSize().getWidth(),(int)toolkit.getScreenSize().getHeight());
driver.manage().window().setSize(screenResolution);

Thursday, May 17, 2012

Setting up Selenium Web driver

Selenium is a popular open source automation tool. Working with selenium is quite easy. The advantage in selenium is you can use various programming languages like Java, C#, Ruby, Python etc.


You can use Java because it has many features and it is secured. I'm using Eclipse for developing the scripts.


Steps for setting up selenium web driver 2.0


Prerequisites:

  • Download latest version of eclipse.
  • Ensure your system has jdk version 1.6 and above.
  • Download Selenium Standalone server (latest version 2.21) Download here


Creating a new project:
  • Open Eclipse.
  • Go to File -> New -> Java project.
  • Create a package and class under the project.
  • Right click your project. Go to Build Path -> Configure Build Path.
  • Add the selenium standalone server under libraries.
Now write the scripts and run the project as Junit test(Alt+Shift+X,T).

Click here for a simple example.