Thursday, 22 March 2012

Total Pageviews 2222




Window Handle example with selenium webdriver + using Java - The Set Interface for selenium automation testing


package testngtest;

import java.util.Iterator;
import java.util.Set;

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
importorg.testng.annotations.Test;
importorg.testng.annotations.BeforeMethod;
importorg.testng.annotations.AfterMethod;

public classTestNG_WindowHandleExample_by_jasmine {
      
       // Declare global test varialbles
      
        WebDriver jasminedriver = new FirefoxDriver();
        String Open_a_popup_window;
        String Positioned_Popup;
        String JavaScript_Popup_Windows;

        
        @Test
  public void f() throws InterruptedException {
             
               // A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction.


               Set windowids = jasminedriver.getWindowHandles();
               
             
               //iterator( )
               //Returns an Iterator object for the collection which may be used to retrieve an object
               Iterator iter= windowids.iterator();
               JavaScript_Popup_Windows=iter.next();

              // Open first popup
               jasminedriver.findElement(By.xpath("//*[@id='content']/div[3]/a")).click();
             
             
              windowids = jasminedriver.getWindowHandles();
              iter= windowids.iterator();
              iter.next();
               Open_a_popup_window=iter.next();
             
              System.out.println(JavaScript_Popup_Windows);
              System.out.println(Open_a_popup_window);
             
              Thread.sleep(3000L);
              System.out.println();
              System.out.println("Positioned_Popup");
             
              // switch to main window to click on other popup link
              jasminedriver.switchTo().window(JavaScript_Popup_Windows);
             
              // Open second  popup
              jasminedriver.findElement(By.xpath("//*[@id='content']/div[5]/p/a")).click();
             
              windowids = jasminedriver.getWindowHandles();
              iter= windowids.iterator();
              iter.next();
              iter.next();
               Positioned_Popup = iter.next();
             
              System.out.println(JavaScript_Popup_Windows);
              System.out.println(Open_a_popup_window);
              System.out.println(Positioned_Popup);
              System.out.println();
              Thread.sleep(3000L);
             
              System.out.println("Centered_Popup");
  }
  @BeforeMethod
  public void beforeMethod() {
        
         jasminedriver.get("http://www.quackit.com/javascript/popup_windows.cfm");
  }

  @AfterMethod
  public void afterMethod() {
         jasminedriver.switchTo().window(Open_a_popup_window);
         jasminedriver.close();
             
         jasminedriver.switchTo().window(Positioned_Popup);
         jasminedriver.close();
      
             
         jasminedriver.switchTo().window(JavaScript_Popup_Windows);

         jasminedriver.quit();
  }


}

Saturday, 10 March 2012

Enter text into JavaScript Prompt Dialog Box [JavaScript alert messages ] in web application using selenium automation testing + WebDriver

importorg.openqa.selenium.Alert;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;

//JavaScript Prompt Dialog Box  [JavaScript alert messages ] in web application using selenium automation testing
public class JavaScriptAlert_LearnSeleniumWithJasmine{

       public static void main(String[] args) throws InterruptedException {
             
             
              WebDriver Jasminedriver = new FirefoxDriver();
              Jasminedriver.get("http://www.javascripter.net/faq/prompt.htm#top");
             
              Jasminedriver.findElement(By.xpath("html/body/p[1]/table/tbody/tr/td[1]/form/input")).click();
              Alert javascriptAlert = Jasminedriver.switchTo().alert();
              Thread.sleep(5000);
              javascriptAlert.sendKeys("Hi Jasmine ");
             
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
              javascriptAlert = Jasminedriver.switchTo().alert();
             
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
              Jasminedriver.findElement(By.xpath("html/body/p[1]/table/tbody/tr/td[1]/form/input")).click();
             
              javascriptAlert = Jasminedriver.switchTo().alert();
              Thread.sleep(5000);
              javascriptAlert.sendKeys("Hi Jasmine ");
              javascriptAlert.dismiss();
              System.out.println("Jasmine OK");
             

              javascriptAlert = Jasminedriver.switchTo().alert();
             
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");

              Jasminedriver.quit();
             
             
             
       }

}

JavaScript Prompt Dialog Box [JavaScript alert messages ] in web application using selenium automation testing


importorg.openqa.selenium.Alert;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;

//JavaScript Prompt Dialog Box  [JavaScript alert messages ] in web application using selenium automation testing
public classJavaScriptAlert_LearnSeleniumWithJasmine {

       public static void main(String[] args) throws InterruptedException {
              WebDriver Jasminedriver = new FirefoxDriver();
              Jasminedriver.get("http://www.javascripter.net/faq/prompt.htm#top");
             
              Jasminedriver.findElement(By.xpath("html/body/p[1]/table/tbody/tr/td[1]/form/input")).click();
              Alert javascriptAlert = Jasminedriver.switchTo().alert();
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
              javascriptAlert = Jasminedriver.switchTo().alert();
             
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
              Jasminedriver.findElement(By.xpath("html/body/p[1]/table/tbody/tr/td[1]/form/input")).click();
             
              javascriptAlert = Jasminedriver.switchTo().alert();
              Thread.sleep(5000);
              javascriptAlert.dismiss();
              System.out.println("Jasmine OK");
             

              javascriptAlert = Jasminedriver.switchTo().alert();
             
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
       }

}