Like us on Facebook

LightBlog

July 25, 2011

Working on New Window

July 25, 2011 2
Working on New Window

Below example is to:
  • open the new window by clicking on one link in Main window, 
  • performing some operations in pop up window,
  • then close the pop up window,
  • and operate some function in main window again.

Program:

package one;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

public class Newwindowselenium extends SeleneseTestCase {
public SeleniumServer ss;
@Before
public void setUp() throws Exception {
ss=new SeleniumServer();
ss.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.bitmotif.com/");
selenium.start();
}

@Test
public void testNewwindowselenium() throws Exception {
// open the URL http://www.bitmotif.com/test-page-for-selenium-remote-control/
selenium.open("/test-page-for-selenium-remote-control/");
// Maximizing the main window
selenium.windowMaximize();
// Click on the link This link opens a popup
selenium.click("link=This link opens a popup");
selenium.waitForPopUp("popup", "30000");
// Select the popup window 
selenium.selectWindow("name=popup");
// Click the link About on popup window 
selenium.click("link=About");
selenium.waitForPageToLoad("30000");
// Close the popup window 
selenium.close();
// back to the main window
selenium.selectWindow("null");
// Click on the link This link goes to another page
selenium.click("link=This link goes to another page");
selenium.waitForPageToLoad("30000");
Thread.sleep(10000);
}

@After
public void tearDown() throws Exception {
selenium.stop();
ss.stop();
}
}

July 4, 2011

Selenium 2.0 Sample program

July 04, 2011 1
Selenium 2.0 Sample program
Here is my first post..related to Selenium 2.0 ...

This script is to search for "selenium"  on google...

Below is code with comments..


package setup;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.thoughtworks.selenium.Selenium;

public class Default {

WebDriver driver;
Selenium selenium;

@BeforeMethod
public void startSelenium() {
//driver = new FirefoxDriver();  //--To run tests on FF
//Internet Explorer Driver --to Run test in IE
driver = new InternetExplorerDriver();
//driver = new ChromeDriver(); //Chrome Driver -- to run tests in google Chrome
/*Below command is optional if we want to use Selenium commands 
instead of selenium2 we have to declare this*/
//selenium = new WebDriverBackedSelenium(driver, "http://www.pdfonline.com/");
}

@AfterMethod
public void stopSelenium() {
//Closing the Driver
driver.close();
}

@Test
public void testAlert() throws Exception {
//Open Home Page
driver.get("http://www.google.com");
//Enter text in search box
driver.findElement(By.name("q")).sendKeys("selenium");
Thread.sleep(1000);
//Click Search button
driver.findElement(By.name("btnG")).click();
Thread.sleep(10000);


}

}