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 startSelenium() { DefaultSelenium selenium = getSelenium(); if (selenium == null) { selenium = new DefaultSelenium("localhost", 4444, browserName, applicationRoot); ((ConfigurableApplicationContext) applicationContext).getBeanFactory(). registerSingleton(SELENIUM_BEAN_NAME, selenium); } if (state == State.STOPPED) { selenium.start(); state = State.STARTED; } }
public DefaultSelenium createInstance(SeleniumConfiguration configuration) { DefaultSelenium selenium = new DefaultSelenium(configuration.getServerHost(), configuration.getServerPort(), configuration.getBrowser(), configuration.getUrl()); selenium.start(); selenium.setSpeed(String.valueOf(configuration.getSpeed())); selenium.setTimeout(String.valueOf(configuration.getTimeout())); return selenium; }
public void testEvenMOREComplexExample() throws Throwable { MyCommandProcessor cp = new MyCommandProcessor(); DefaultSelenium selenium = new DefaultSelenium(cp); selenium.showContextualBanner(); assertEquals(prefix + "test Even MORE Complex Example\n", cp.commands.toString()); }
public void start(Object optionsObject) { start(optionsObject.toString()); }
/** * Should not be called by paxml */ void start() { selenium.start(); if (this.browserStartCommand.equals("*iexplore")) { log.debug("We are running explorer, lets use javascript-xpath"); selenium.useXpathLibrary("javascript-xpath"); } initialized = true; }
public void stopSelenium() { DefaultSelenium selenium = getSelenium(); if (selenium != null) { selenium.stop(); state = State.STOPPED; } }
/** * Should not be called by paxml. */ void close() { errorClosing = false; if (log.isDebugEnabled()) { log.debug("Attempt to close selenium"); } if (initialized) { if (log.isDebugEnabled()) { log.debug("Closing selenium"); } try { selenium.close(); } catch (Exception e) { errorClosing = true; log.warn("Error closing selenium", e); } } }
file = new File(dir, entity + "." + fn + "." + i + ".png"); final String base64 = selenium.captureEntirePageScreenshotToString(""); try { FileUtils.writeByteArrayToFile(file, Base64.decodeBase64(base64.getBytes()));
public void testShouldLeaveOtherExceptionAlone() { FailOnStartCommandProcessor failOnStartCommandProcessor; failOnStartCommandProcessor = new FailOnStartCommandProcessor("some crazy unexpected exception"); try { new DefaultSelenium(failOnStartCommandProcessor).start(); fail("Did not catch RuntimeException as expected"); } catch (RuntimeException expected) { /* Catching RuntimeEception as expected */ assertTrue(-1 != expected.getMessage().indexOf("Could not start Selenium session: ")); assertTrue(-1 != expected.getMessage().indexOf("some crazy unexpected exception")); } }
public void testBannerSimple() throws Throwable { MyCommandProcessor cp = new MyCommandProcessor(); DefaultSelenium selenium = new DefaultSelenium(cp); selenium.showContextualBanner(); assertEquals(prefix + "test Banner Simple\n", cp.commands.toString()); }
@Override public void start() { super.start(); dumpSessionId(); }
public void terminate() { if (terminated) { return; } try { selenium.close(); } catch (Exception e) { log.error("Error closing selenium", e); } finally { try { selenium.stop(); } catch (Exception e) { log.error("Error stopping selenium", e); } } terminated = true; if (log.isInfoEnabled()) { log.info("Selenium session terminated: " + this); } }
/** * Should not be called by paxml */ void start() { selenium.start(); if (this.browserStartCommand.equals("*iexplore")) { log.debug("We are running explorer, lets use javascript-xpath"); selenium.useXpathLibrary("javascript-xpath"); } initialized = true; }
/** * Should not be called by paxml. */ void stop() { if (errorClosing) { if (log.isWarnEnabled()) { log.warn("Skipping stopping selenium due to error in closing"); } return; } if (log.isDebugEnabled()) { log.debug("Attempt to stop selenium"); } if (initialized) { initialized = false; if (log.isDebugEnabled()) { log.debug("Stopping selenium"); } try { selenium.stop(); } catch (Exception e) { log.warn("Error stopping selenium", e); } } }
/** * Should not be called by paxml. */ void close() { errorClosing = false; if (log.isDebugEnabled()) { log.debug("Attempt to close selenium"); } if (initialized) { if (log.isDebugEnabled()) { log.debug("Closing selenium"); } try { selenium.close(); } catch (Exception e) { errorClosing = true; log.warn("Error closing selenium", e); } } }
file = new File(dir, entity + "." + fn + "." + i + ".png"); final String base64 = selenium.captureEntirePageScreenshotToString(""); try { FileUtils.writeByteArrayToFile(file, Base64.decodeBase64(base64.getBytes()));
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/"); selenium.start(); selenium.windowMaximize();
public void testWrapsConnectionRefusedWithUserFriendlyExceptionMessage() { final FailOnStartCommandProcessor failOnStartCommandProcessor; failOnStartCommandProcessor = new FailOnStartCommandProcessor("Connection refused: connect"); try { new DefaultSelenium(failOnStartCommandProcessor).start(); fail("Did not catch RuntimeException as expected"); } catch (RuntimeException expected) { assertTrue(-1 != expected.getMessage().indexOf("Could not contact Selenium Server; have you started it on '' ?")); assertTrue(-1 != expected.getMessage().indexOf("Connection refused: connect")); } }