private BrowserLauncher createBrowserLauncher( Class c, String browserStartCommand, String sessionId, SeleneseQueue queue) { try { BrowserLauncher browserLauncher; if (null == browserStartCommand) { Constructor ctor = c.getConstructor(new Class[] {int.class, String.class}); Object[] args = new Object[] {new Integer(server.getPort()), sessionId}; browserLauncher = (BrowserLauncher) ctor.newInstance(args); } else { Constructor ctor = c.getConstructor(new Class[] {int.class, String.class, String.class}); Object[] args = new Object[] { new Integer(SeleniumServer.getPortDriversShouldContact()), sessionId, browserStartCommand }; browserLauncher = (BrowserLauncher) ctor.newInstance(args); } if (browserLauncher instanceof SeleneseQueueAware) { ((SeleneseQueueAware) browserLauncher).setSeleneseQueue(queue); } return browserLauncher; } catch (InvocationTargetException e) { throw new RuntimeException( "failed to contruct launcher for " + browserStartCommand + "for" + e.getTargetException()); } catch (Exception e) { throw new RuntimeException(e); } }
public static void main(String[] args) throws Exception { // prepare SeleniumServer SeleniumServer server = new SeleniumServer(); try { // start server server.start(); // create AnadixSelenium AnadixSelenium selenium = new AnadixSelenium("localhost", server.getPort(), "firefox", "http://www.redhat.com"); try { selenium.start(); // set up AnadixSelenium if (!sourcesDir.exists()) { sourcesDir.mkdir(); } selenium.setSourcesDir(sourcesDir); if (!reportsDir.exists()) { reportsDir.mkdir(); } selenium.setReportsDir(reportsDir); // perform some browsing with later analysis selenium.setAnalyzer(null); // stores pages sources selenium.open("http://www.redhat.com"); selenium.click("link=JBoss Enterprise Middleware"); selenium.waitForPageToLoad("30000"); selenium.click("//div[@id='contentColRight_v2']/div/map/area[9]"); selenium.waitForPageToLoad("30000"); // perform some browsing with immediate analysis selenium.setAnalyzer(Anadix.newAnalyzer()); selenium.open("http://www.jboss.org/drools"); selenium.click("link=Drools Fusion"); selenium.waitForPageToLoad("30000"); selenium.click("link=Mailing Lists"); selenium.waitForPageToLoad("30000"); selenium.click("link=Documentation"); selenium.waitForPageToLoad("30000"); // analyze previous selenium.analyzeStoredPages(); // dump all reports selenium.dumpReports(new XHTMLReportFormatter()); } finally { selenium.stop(); selenium.dispose(); } } finally { server.stop(); } System.out.println("finished"); }
/** This method stops selenium server and sets its instance to null. */ public void stopSeleniumServer() { try { logger.info("Stopping selenium server"); server.stop(); logger.info("Setting selenium server as null"); server = null; } catch (Exception e) { // do nothing } }
@BeforeClass public static void setUp() throws Exception { System.out.println("*** Starting selenium ... ***"); RemoteControlConfiguration seleniumConfig = new RemoteControlConfiguration(); seleniumConfig.setPort(4444); seleniumServer = new SeleniumServer(seleniumConfig); seleniumServer.start(); String host = System.getProperty("myParam", "localhost"); selenium = createSeleniumClient("http://" + host + ":" + "8080/client/"); selenium.start(); System.out.println("*** Started selenium ***"); }
@Override protected void launch(String url) { final String fileUrl; String query; query = LauncherUtils.getQueryString(url); query += "&driverUrl=http://localhost:" + getPort() + "/selenium-server/driver/"; try { if (SeleniumServer.isEnsureCleanSession()) { ensureCleanSession(); } fileUrl = createExtractedFiles().toURL() + "?" + query; launchSafari(fileUrl); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Method to start selenium server * * @author Gaurav Bansal */ public void startSeleniumServer() { logger.info("Starting Selenium Server.........This might take around 10-15 seconds."); RemoteControlConfiguration rcc = new RemoteControlConfiguration(); rcc.setPort(4444); rcc.setTimeoutInSeconds(600); rcc.setSingleWindow(false); rcc.setFirefoxProfileTemplate( new File(ConfigFileReader.getConfigItemValue("selenium.firefox.profile"))); // rcc.setAvoidProxy(true); rcc.setTrustAllSSLCertificates(true); try { server = new SeleniumServer(false, rcc); server.boot(); } catch (Exception e) { logger.info(e.getMessage()); logger.info("Server is already running so reusing that....."); } }
@BeforeSuite(alwaysRun = true) public void setupBeforeSuite(ITestContext context) { String seleniumHost = "localhost"; String seleniumPort = "9080"; String seleniumBrowser = "firefox"; String seleniumUrl = "http://localhost:8080/molgenis_apps/"; RemoteControlConfiguration rcc = new RemoteControlConfiguration(); rcc.setSingleWindow(true); rcc.setPort(Integer.parseInt(seleniumPort)); try { server = new SeleniumServer(false, rcc); server.boot(); } catch (Exception e) { throw new IllegalStateException("Can't start selenium server", e); } proc = new HttpCommandProcessor( seleniumHost, Integer.parseInt(seleniumPort), seleniumBrowser, seleniumUrl); selenium = new DefaultSelenium(proc); selenium.start(); }
@Override public void printUsage() { String separator = "\n-------------------------------\n"; SeleniumServer.usage(separator + "Running as a standalone server:" + separator); }
@Override public void launch(String[] args, Logger log) throws Exception { log.info("Launching a standalone Selenium Server"); SeleniumServer.main(args); log.info("Selenium Server is up and running"); }