package com.example.tests; import com.thoughtworks.selenium.*; public class selenium extends SeleneseTestCase { private static Selenium selenium; public void setUp() throws Exception { selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/"); selenium.start(); selenium.windowMaximize(); } public void testSelenium() throws Exception { selenium.open("/"); selenium.waitForPageToLoad("30000"); Assert.assertEquals("Google", selenium.getTitle()); } public void tearDown() throws Exception { selenium.close(); } }
public void setUp(String url, String browserString, int port) { if (url == null) { url = "http://localhost:" + port; } selenium = new DefaultSelenium("localhost", port, browserString, url); selenium.start(); }
/** checks for verification errors and stops the browser */ public void tearDown() throws Exception { try { checkForVerificationErrors(); } finally { if (selenium != null) { selenium.stop(); selenium = null; } } }
public void testSetSingleWindowWhenMultiWindowWasAlreadySet() { BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setMultiWindow().setSingleWindow(); assertTrue(bco.isSingleWindow()); assertFalse(bco.isMultiWindow()); assertTrue(bco.isSet(BrowserConfigurationOptions.SINGLE_WINDOW)); }
public void testDangerousLabels() { String[] labels = sel.getSelectOptions("dangerous-labels"); assertEquals("Wrong number of labels", 3, labels.length); assertEquals("mangled label", "veni, vidi, vici", labels[0]); assertEquals("mangled label", "c:\\foo\\bar", labels[1]); assertEquals("mangled label", "c:\\I came, I \\saw\\, I conquered", labels[2]); }
public void testSetBrowserExcecutablePathWithValidPath() { String path = "c:\\chrome\\is\\cool.exe with_arg"; BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setBrowserExecutablePath(path); assertTrue(bco.isSet(BrowserConfigurationOptions.BROWSER_EXECUTABLE_PATH)); assertEquals(path, bco.getBrowserExecutablePath()); }
public void testBrowserModeWithNonNullMode() { String mode = "hta"; BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setBrowserMode(mode); assertTrue(bco.isSet(BrowserConfigurationOptions.BROWSER_MODE)); assertEquals(mode, bco.getBrowserMode()); }
public void testSetProfileWithNonNullDoesSet() { String profile = "foo"; BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setProfile(profile); assertTrue(bco.isSet(BrowserConfigurationOptions.PROFILE_NAME)); assertEquals(profile, bco.getProfile()); }
public void testSetTimeoutInSeconds() { int timeout = 17; BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setTimeoutInSeconds(timeout); assertTrue(bco.isSet(BrowserConfigurationOptions.TIMEOUT_IN_SECONDS)); assertEquals(timeout, bco.getTimeoutInSeconds()); }
public void testResourcesClosedWhenIoeOnGetInputStream() { IOEThrowingHttpCommandProcessor cmdProc = new IOEThrowingHttpCommandProcessor( "localhost", 4444, "*chrome", "http://www.google.com"); cmdProc.throwIoeOnGetInputStream = true; try { String response = cmdProc.getCommandResponseAsString("testCommand"); fail(); } catch (IOException ioe) { cmdProc.verifyClosedResources(true, true, false); } }
public void testSetSingleWindow() { BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setSingleWindow(); assertTrue(bco.isSingleWindow()); assertTrue(bco.isSet(BrowserConfigurationOptions.SINGLE_WINDOW)); }
public void testSetMultiWindow() { BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setMultiWindow(); assertTrue(bco.isMultiWindow()); assertTrue(bco.isSet(BrowserConfigurationOptions.MULTI_WINDOW)); }
public void testUntil() { finished = now + 500l; new Wait() { public boolean until() { tries++; return System.currentTimeMillis() > finished; } }.wait("clock stopped"); assertTrue("didn't try enough times: " + tries, tries > 1); }
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/"); selenium.start(); selenium.windowMaximize();
public void testSetMultiWindowWhenSingleWindowWasAlreadySet() { BrowserConfigurationOptions bco = new BrowserConfigurationOptions().setSingleWindow().setMultiWindow(); assertTrue(bco.isMultiWindow()); assertFalse(bco.isSingleWindow()); assertTrue(bco.isSet(BrowserConfigurationOptions.MULTI_WINDOW)); }
public void testResourcesClosedWhenNoIoes() { IOEThrowingHttpCommandProcessor cmdProc = new IOEThrowingHttpCommandProcessor( "localhost", 4444, "*chrome", "http://www.google.com"); try { String response = cmdProc.getCommandResponseAsString("testCommand"); cmdProc.verifyClosedResources(true, true, true); } catch (IOException ioe) { fail(); } }
import com.thoughtworks.selenium.*; import java.util.regex.Pattern; Boolean result = true; try { selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/"); selenium.start(); selenium.windowMaximize(); selenium.open("/"); selenium.waitForPageToLoad("30000"); if (!selenium.isTextPresent("Google")) result = false; } catch (Exception ex) { ex.printStackTrace(); IsSuccess = false; ResponseCode = "500"; ResponseMessage = ex.getMessage(); } finally { selenium.stop(); } IsSuccess = result; return result;
public void testResourcesClosedWhenIoeOnGetConnection() { IOEThrowingHttpCommandProcessor cmdProc = new IOEThrowingHttpCommandProcessor( "localhost", 4444, "*chrome", "http://www.google.com"); cmdProc.throwIoeOnGetConnection = true; try { String response = cmdProc.getCommandResponseAsString("testCommand"); fail(); } catch (IOException ioe) { cmdProc.verifyClosedResources(false, false, false); } }
import com.thoughtworks.selenium.*; import java.util.regex.Pattern; Boolean result = true; try { selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/"); selenium.start(); selenium.windowMaximize(); selenium.open("/"); selenium.waitForPageToLoad("30000"); if (!selenium.isTextPresent("Google")) result = false; } catch (Exception ex) { ex.printStackTrace(); log.error(ex.getMessage()); SampleResult.setSuccessful(false); SampleResult.setResponseCode("500"); SampleResult.setResponseMessage(ex.getMessage()); } finally { selenium.stop(); } SampleResult.setSuccessful(result); return result;
public void testResourcesClosedWhenIoeOnGetOutputStream() { IOEThrowingHttpCommandProcessor cmdProc = new IOEThrowingHttpCommandProcessor( "localhost", 4444, "*chrome", "http://www.google.com"); cmdProc.throwIoeOnGetOutputStream = true; try { String response = cmdProc.getCommandResponseAsString("testCommand"); fail(); } catch (IOException ioe) { cmdProc.verifyClosedResources(true, false, false); } }