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(); } }
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/"); selenium.start(); selenium.windowMaximize();
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;
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;
@BeforeClass public void base() { selenium = new DefaultSelenium("localhost",4444,"*firefox","http://www.redbus.in"); selenium.start(); selenium.windowMaximize(); selenium.open("/"); selenium.waitForPageToLoad("10000"); }
/** * Creates default Selenium instance: {@link DefaultSelenium("localhost", * 4444, "*firefox", "http://localhost:8080")} * * @return A Selenium instance */ public static Selenium defaultSelenium() { return new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8080"); }
browser = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com"); browser.start();
/** * Creates default Selenium instance: {@link DefaultSelenium("localhost", * 4444, "*firefox", "http://localhost:8080")} * * @return A Selenium instance */ public static Selenium defaultSelenium() { return new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8080"); }
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(); }
public Selenium getUnwrappedRemoteSelenium(String baseUrl) { Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", baseUrl); selenium.start(); return selenium; }
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 static void startSeleniumSession(String seleniumHost, int seleniumPort, String browser, String webSite) { LOGGER.info("Contacting Selenium RC at " + seleniumHost + ":" + seleniumPort); threadLocalSelenium.set(new DefaultSelenium(seleniumHost, seleniumPort, browser, webSite)); session().start(); LOGGER.info("Got Selenese session:" + session()); }
@BeforeSuite @Parameters({"selenium.host", "selenium.port"}) public void attachScreenshotListener(@Optional("localhost") String host, @Optional("4444") String port, ITestContext context) { if (!"localhost".equals(host)) return; Selenium screenshotTaker = new DefaultSelenium(host, Integer.parseInt(port), "", ""); TestRunner tr = (TestRunner) context; File outputDirectory = new File(context.getOutputDirectory()); tr.addListener((IResultListener) new ScreenshotListener(outputDirectory, screenshotTaker)); }
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; }
@Override public Selenium get() { if (commandProcessor == null) { require(serverHost, "Selenium server host"); require(port, "Selenium server port"); require(browser, "Browser command"); require(website, "Target website"); commandProcessor = new HttpCommandProcessor(serverHost, port, browser, website); } return new DefaultSelenium(commandProcessor); } };
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 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 testMoreComplexExample() throws Throwable { MyCommandProcessor cp = new MyCommandProcessor(); DefaultSelenium selenium = new DefaultSelenium(cp); selenium.showContextualBanner(); assertEquals(prefix + "test More Complex Example\n", cp.commands.toString()); }
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()); }
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")); } }