Example usage for org.openqa.selenium.remote RemoteWebDriver quit

List of usage examples for org.openqa.selenium.remote RemoteWebDriver quit

Introduction

In this page you can find the example usage for org.openqa.selenium.remote RemoteWebDriver quit.

Prototype

@Override
    public void quit() 

Source Link

Usage

From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.TestRemoteWebDriverFactorySessionStoring.java

License:Apache License

@Test
public void when_session_is_created_and_persisted_but_nonreusable_then_next_creation_should_remove_it_from_list_of_reusable_sessions()
        throws Exception {

    // having/*from  w  w  w  .j  ava2s  .  c  o m*/
    RemoteWebDriverFactory factory1 = new MockRemoteWebDriverFactory();
    RemoteWebDriverFactory factory2 = new MockRemoteWebDriverFactory();
    injector.get().inject(factory1);
    injector.get().inject(factory2);

    when(configuration.getBrowser()).thenReturn("xyz");
    when(configuration.isRemoteReusable()).thenReturn(true);
    when(configuration.getCapabilities()).thenReturn(desiredCapabilities);
    when(configuration.getRemoteAddress()).thenReturn(hubUrl);

    // when
    fire(new BeforeSuite());

    // creates new session
    RemoteWebDriver webdriver1 = factory1.createInstance(configuration);
    // persists session into store
    factory1.destroyInstance(webdriver1);
    // makes driver non-reusable
    webdriver1.quit();

    // new suite
    fire(new BeforeSuite());
    // pulls non-reusable session from store, so creates new session
    RemoteWebDriver webdriver2 = factory2.createInstance(configuration);
    // quit newly created session
    factory2.destroyInstance(webdriver2);
    webdriver2.quit();
    // persists available sessions (none should be available)
    // persistEvent.fire(new PersistReusedSessionsEvent());

    // new suite
    fire(new BeforeSuite());
    // pulls session - should *NOT* be empty
    ReusedSession reusedSession = sessionStore.get().pull(initializationParameter);
    assertNotNull("reusedSession must be stored", reusedSession);
    // pulls session - should be empty - it was cleared by last pull
    reusedSession = sessionStore.get().pull(initializationParameter);
    assertNull("reusedSession must not be stored", reusedSession);

}

From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.TestReusableRemoteWebDriver.java

License:Apache License

@Test
public void whenBrowserIsCreatedAndQuitAndTriedToReuseThenItShouldThrowException(
        @Drone @Reusable RemoteWebDriver driver) {

    driver.navigate().to(SERVER_URL.toString());
    new AugmentingEnhancer().deenhance(driver, Reusable.class); // without deenhancing we can't serialize capabilities
    Capabilities reusedCapabilities = serializeDeserialize(
            ReusedSession.createReusableCapabilities(driver.getCapabilities()));
    SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString()));
    driver.quit();

    try {/*  w  w  w. j a  v  a2  s  .c  o  m*/
        ReusableRemoteWebDriver.fromReusedSession(HUB_URL, reusedCapabilities, reusedSessionId);
        fail("Original driver had quited before, so session should not be reusable");
    } catch (UnableReuseSessionException e) {
        // exception should be thrown
    }
}

From source file:org.jboss.arquillian.drone.webdriver.factory.RemoteWebDriverFactory.java

License:Apache License

@Override
public void destroyInstance(RemoteWebDriver instance) {
    if (instance.getSessionId() == null) {
        log.warning("The driver has been already destroyed and can't be destroyed again.");
        return;//from w w  w  . j  a  v a2  s.c o m
    }

    InitializationParameter param = initParams.get().remove(instance.getSessionId());

    if (param != null) {
        ReusedSession session = new ReusedSession(instance.getSessionId(), instance.getCapabilities());
        sessionStore.get().store(param, session);
        persistEvent.fire(new PersistReusedSessionsEvent());
    } else {
        instance.quit();
    }

}

From source file:org.tanaguru.rules.generator.json.TanaguruJsTestCaseExtractor.java

License:Open Source License

/**
 * @param args the command line arguments
 * @throws java.net.MalformedURLException
 */// w  w  w  .  j  a va  2  s .  co m
public static void main(String[] args) throws MalformedURLException, IOException, InterruptedException {
    //        DesiredCapabilities caps = new DesiredCapabilities();
    //        caps.setJavascriptEnabled(true);
    //        WebDriver driver = new PhantomJSDriver(caps);
    //        FirefoxDriver driver = 
    //                new FirefoxDriver(
    //                        new FirefoxBinary(new File(PATH_TO_FF)), 
    //                        new FirefoxProfile());

    DesiredCapabilities ff = DesiredCapabilities.firefox();
    //        DesiredCapabilities chrome = DesiredCapabilities.chrome();
    RemoteWebDriver driver = null;
    try {
        driver = new RemoteWebDriver(new URL(HUB_URL), ff);
        //            driver = new RemoteWebDriver(new URL("http://172.17.0.23:4444/wd/hub"), chrome);
        String script = IOUtils.toString(
                TanaguruJsTestCaseExtractor.class.getClassLoader().getResourceAsStream(JS_SCRIPT_NAME));

        for (Element el : Jsoup.parse(new URL(URL_LIST), 5000).select("a")) {
            String url = el.attr("abs:href");
            String resourceName = StringUtils.remove(el.attr("href"), ".html");
            if (StringUtils.contains(url, "html")) {
                driver.get(url);
                driver.findElementByTagName("body").sendKeys(Keys.TAB);
                try {
                    FileUtils.write(new File(PATH_TO_WRITE + resourceName + ".json"),
                            new JSONArray(driver.executeScript(script).toString()).toString(4));
                } catch (JSONException ex) {
                }
            }
        }
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:org.uiautomation.ios.Demo.java

License:Apache License

public static void main2(String[] args) throws Exception {
    String[] a = { "-port", "4445", "-host", "localhost", "-aut", SampleApps.getUICatalogFile(), "-aut",
            SampleApps.getUICatalogIpad(), "-aut", "/Users/freynaud/eBay3.1_19.app" };

    IOSServerConfiguration config = IOSServerConfiguration.create(a);

    IOSServer server = new IOSServer(config);
    server.start();// w  ww. j av a  2  s  .c  o m

    IOSCapabilities cap = IOSCapabilities.iphone("eBay");
    cap.setCapability(IOSCapabilities.SIMULATOR, true);

    if (useQA) {
        cap.setCapability(IOSCapabilities.IOS_SWITCHES, Arrays.asList(new String[] { "-e", "useQA", "YES" }));
    }

    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4445/wd/hub"), cap);
    WebElement agree = driver.findElement(By.name("Agree"));
    agree.click();
    WebElement searchField = driver.findElement(By.linkText("value=Search eBay"));
    searchField.sendKeys("ihpone5");
    WebElement search = driver.findElement(By.xpath("//UIAButton[@label='search']"));
    search.click();

    driver.quit();
    server.stop();

}

From source file:org.uiautomation.ios.Demo.java

License:Apache License

public static void main(String[] args) throws Exception {

    String[] a = { "-port", "5555", "-host", "127.0.0.1",
            //"-aut", SampleApps.getUICatalogFile(),
            //"-aut", SampleApps.getUICatalogIpad(),
            //"-beta",
            "-folder", "applications", "-simulators", "-hub", "http://127.0.0.1:4444/grid/register" };

    IOSServerConfiguration config = IOSServerConfiguration.create(a);

    IOSServer server = new IOSServer(config);
    server.start();//w w  w. j  a  v a2  s. c  om

    IOSCapabilities cap = IOSCapabilities.iphone("eBay");
    cap.setCapability(IOSCapabilities.IOS_SWITCHES, Arrays.asList(new String[] { "-e", "useQA", "YES" }));

    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
    try {

        driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

        WebElement agree = driver.findElement(By.name("Agree"));
        agree.click();

        //driver.switchTo().alert().dismiss();
        WebElement signInButton = driver.findElement(By.xpath("//UIAButton[@name='Sign In']"));
        signInButton.click();
        WebElement user = driver.findElement(By.xpath("//UIATextField[@value='User ID or email']"));
        user.sendKeys(userId);
        WebElement pass = driver.findElement(By.xpath("//UIASecureTextField[@value='Password']"));
        pass.sendKeys(password);
        WebElement element4 = driver.findElement(By.xpath("//UIAButton[@name='Done']"));
        element4.click();

        Thread.sleep(2000);
        boolean cartDown = false;
        // navigate
        String itemId = "220003725262";
        if (cartDown) {
            WebElement search = driver.findElement(By.xpath("//UIAButton[@name='Search']"));
            search.click();

            //validate
            WebElement element1 = driver.findElement(By.xpath("//UIASearchBar[@value='Search Watching']"));
            element1.sendKeys(itemId);

            // check it's there.
            WebElement result = driver.findElement(By.className("UIATableCell"));
            System.out.println(result.getAttribute("name"));

        } else {
            WebElement basket = driver.findElement(By.xpath("//UIAButton[@name='Basket, 1 item']"));
            //By.xpath("//UIAButton[matches(@name,l10n('ItemCountFormatStringPlural'))]"));
            //ItemCountFormatStringSingular
            basket.click();

            //WebElement firstItem = driver.findElement(By.xpath("//UIATableCell[2]"));
            //firstItem.click();

            WebElement search = driver.findElement(By.name("Checkout"));
            search.click();

        }

        // watch
        WebElement paypal = driver.findElement(By.name("Please login to your account"));
        paypal.click();

        while (driver.getWindowHandles().size() != 3) {
            Thread.sleep(1000);
        }

        WebElement email = null;
        while (email == null) {
            try {
                driver.switchTo().window("Web_3");
                email = driver.findElement(By.id("email"));
            } catch (NoSuchElementException e) {
                Thread.sleep(1000);
                System.out.println("not found");
            }
        }

        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

        driver.findElement(By.cssSelector(".resetter")).click();
        email.sendKeys("ppbuild-1920977828325914@paypal.com");

        WebElement password = driver.findElement(By.id("password"));
        password.sendKeys("11111111");

        WebElement login = driver.findElement(By.id("login"));
        login.click();

        Thread.sleep(30000);

    } finally {
        driver.quit();
        server.stop();
    }

}

From source file:org.uiautomation.ios.Demo.java

License:Apache License

public static void main3(String[] args) throws Exception {
    String[] a = { "-port", "4444", "-host", "localhost", "-aut", "/Users/freynaud/PayPal Here.app" };

    IOSServerConfiguration config = IOSServerConfiguration.create(a);

    IOSServer server = new IOSServer(config);
    server.start();/*from   w w w .  j a va2s  .c o m*/

    IOSCapabilities cap = IOSCapabilities.iphone("PayPal Here");
    cap.setCapability(IOSCapabilities.SIMULATOR, true);

    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);

    WebElement agree = driver.findElement(By.name("Sign Up for PayPal Here"));
    agree.click();

    driver.quit();
    server.stop();
}

From source file:org.uiautomation.ios.selenium.Demo.java

License:Apache License

public static void main3(String[] args) throws Exception {

    DesiredCapabilities safari = IOSCapabilities.ipad("Safari");
    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), safari);

    driver.get("http://ebay.co.uk");

    ((Rotatable) new Augmenter().augment(driver)).rotate(ScreenOrientation.LANDSCAPE);

    WebElement search = driver.findElement(By.id("srchDv"));
    search.sendKeys("ipod");
    search.submit();//from w  ww  .  ja v  a2 s .co m

    waitFor(pageTitleToBe(driver, "ipod | eBay Mobile Web"));

    driver.quit();
}

From source file:org.uiautomation.ios.selenium.Demo.java

License:Apache License

public static void main(String[] args) throws Exception {
    IOSCapabilities catalog = IOSCapabilities.iphone("UICatalog");

    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), catalog);
    // by default, the app starts in native mode.
    WebElement web = driver.findElement(By.xpath("//UIATableCell[contains(@name,'Web')]"));
    web.click();//from  w w  w  . j  av  a 2 s. com

    // now that a webview is displayed, switch to web mode.
    driver.switchTo().window("Web");

    // and select items using natural web selectors.
    final By cssSelector = By.cssSelector("a[href='http://store.apple.com/']");

    // reuse whatever contrust your webdriver tests are using.
    WebElement el = waitFor(elementToExist(driver, cssSelector));
    Assert.assertEquals(el.getAttribute("href"), "http://store.apple.com/");

    driver.quit();
}

From source file:org.uiautomation.ios.selenium.Demo.java

License:Apache License

public static void main2(String[] args) throws Exception {

    DesiredCapabilities safari = IOSCapabilities.iphone("Safari");
    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), safari);

    driver.get("http://hp.mobileweb.ebay.co.uk/home");
    WebElement search = driver.findElement(By.id("srchDv"));
    search.sendKeys("ipod");
    search.submit();/*from   ww  w  .java 2 s .  c  o m*/

    waitFor(pageTitleToBe(driver, "ipod | eBay Mobile Web"));

    driver.quit();
}