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();
}
}