Java Code Examples for org.openqa.selenium.remote.RemoteWebDriver

The following are top voted examples for showing how to use org.openqa.selenium.remote.RemoteWebDriver. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   View source code 8 votes vote down vote up
public static WebDriver getFirefoxDriver()
            throws Exception
	{
        baseDir = new File(".").getPath();
        System.out.println("******** " + baseDir);

        String path = "src/test/resources/geckodriver";
        System.out.println("******** " + path);
		System.setProperty("webdriver.gecko.driver", path);

        DesiredCapabilities capabilities =  DesiredCapabilities.firefox();
		capabilities.setCapability("marionette", true);
        capabilities.setCapability("networkConnectionEnabled", true);
        capabilities.setCapability("browserConnectionEnabled", true);


        WebDriver driver = new RemoteWebDriver(
                new URL("http://localhost:4444"),
                capabilities);

//		WebDriver driver = new MarionetteDriver(capabilities);

		return driver;
	}
 
Example 2
Project: SilkAppDriver   File: MultiWindowTests.java   View source code 7 votes vote down vote up
@Before
public void startApp() throws Exception {
	DesiredCapabilities capabilities = new DesiredCapabilities();

	Map<String, Object> baseState = new HashMap<>();
	baseState.put("type", "NATIVE");
	baseState.put("executable", APP);
	baseState.put("locator", "//Window");

	capabilities.setCapability("appdriver-basestate", baseState);

	Map<String, Object> options = new HashMap<>();
	options.put("closeOnQuit", true);

	capabilities.setCapability("appdriver-options", options);

	driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
}
 
Example 3
Project: selenium-testng-template   File: DownloadUtils.java   View source code 6 votes vote down vote up
public static final String download(RemoteWebDriver driver, String url) {
	String folder = DOWNLOAD_PATH + RandomStringUtils.randomAlphabetic(10);
	new File(folder).mkdirs();

	Map<String, String> headers = new HashMap<String, String>();
	headers.put("Cookie", getCookie(driver));
	byte[] data = HttpUtils.get(url, headers);
	try {
		String filename;
		String contentDisposition = headers.get("Content-Disposition");
		if (StringUtils.contains(contentDisposition, "=")) {
			filename = contentDisposition.substring(contentDisposition.indexOf("=") + 1);
		} else {
			filename = new URL(url).getPath();
			if (filename.contains("/")) {
				filename = filename.substring(filename.lastIndexOf("/") + 1);
			}
		}
		IOUtils.write(data, new FileOutputStream(folder + "/" + filename));
		return folder + "/" + filename;
	} catch (Exception e) {
		throw new RuntimeException("Download failed!", e);
	}
}
 
Example 4
Project: delay-repay-bot   File: PhantomJSTest.java   View source code 6 votes vote down vote up
@Test
public void testDriver() throws IOException {
    WebDriver driver = new RemoteWebDriver(toUrl("http://localhost:9515"), DesiredCapabilities.chrome());
    driver.get(URL2);

    String response = driver.getPageSource();
    Document doc = Jsoup.connect(URL2).ignoreContentType(true).get();
    Elements scriptTags = doc.select("body");

    // get All functions


    try {
        String result = (String) engine.eval(response);
    } catch (ScriptException e) {
        e.printStackTrace();
    }

    log.info("PageSource " + response);

    driver.quit();
}
 
Example 5
Project: webdriver-supplier   File: CoreTests.java   View source code 6 votes vote down vote up
@Test
public void shouldCreateRemoteDriverInstance() throws MalformedURLException {
    XmlConfig config = new XmlConfig(new HashMap<String, String>() {
        {
            put(BROWSER_NAME, "firefox");
            put(PLATFORM_NAME, "ANY");
            put(TEST_NAME, "shouldCreateRemoteDriverInstance");
        }
    });

    WebDriver driver = mock(RemoteWebDriver.class, RETURNS_DEEP_STUBS);
    WebDriverProvider spyFactory = spy(defaultFactory);
    Reflect spyReflectedDriver = spy(spyFactory.wrapDriver(firefox));

    doReturn(spyReflectedDriver).when(spyFactory).wrapDriver(firefox);
    doReturn(on(driver)).when(spyReflectedDriver).create(new URL(firefox.url()), firefox.configuration(config));

    assertThat(spyFactory.createDriver(firefox, config)).isInstanceOf(RemoteWebDriver.class);
}
 
Example 6
Project: SilkAppDriver   File: WpfSampleAppTests.java   View source code 6 votes vote down vote up
@Before
public void startApp() throws Exception {
	DesiredCapabilities capabilities = new DesiredCapabilities();

	Map<String, Object> baseState = new HashMap<>();
	baseState.put("type", "NATIVE");
	baseState.put("executable", APP);
	baseState.put("locator", "//WPFWindow");

	capabilities.setCapability("appdriver-basestate", baseState);

	Map<String, Object> options = new HashMap<>();
	options.put("closeOnQuit", true);

	capabilities.setCapability("appdriver-options", options);

	driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
}
 
Example 7
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   View source code 6 votes vote down vote up
public static WebDriver getFirefoxDriver()
            throws Exception
	{
        baseDir = new File(".").getPath();
        System.out.println("******** " + baseDir);

        String path = "src/test/resources/geckodriver";
        System.out.println("******** " + path);
		System.setProperty("webdriver.gecko.driver", path);

        DesiredCapabilities capabilities =  DesiredCapabilities.firefox();
		capabilities.setCapability("marionette", true);
        capabilities.setCapability("networkConnectionEnabled", true);
        capabilities.setCapability("browserConnectionEnabled", true);


        WebDriver driver = new RemoteWebDriver(
                new URL("http://localhost:4444"),
                capabilities);

//		WebDriver driver = new MarionetteDriver(capabilities);

		return driver;
	}
 
Example 8
Project: tdd-pingpong   File: PageObject.java   View source code 6 votes vote down vote up
protected PageObject(RemoteWebDriver driver, String title, String urlTail) {
  this.driver = driver;
  this.title = title;
  this.urlRoot = "http://localhost:8080";
  this.urlTail = urlTail;
  this.url = urlRoot + urlTail;

  String message = String.format(
      "Expected to be on page with"
      + "title containing %s and"
      + "url containing %s but"
      + "title was %s and"
      + "url was %s",
          title, url, driver.getTitle(), driver.getCurrentUrl());
  assertTrue(message, isCurrentPage());
}
 
Example 9
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   View source code 6 votes vote down vote up
public static WebDriver getFirefoxDriver()
            throws Exception
	{
        baseDir = new File(".").getPath();
        System.out.println("******** " + baseDir);

        String path = "src/test/resources/geckodriver";
        System.out.println("******** " + path);
		System.setProperty("webdriver.gecko.driver", path);

        DesiredCapabilities capabilities =  DesiredCapabilities.firefox();
		capabilities.setCapability("marionette", true);
        capabilities.setCapability("networkConnectionEnabled", true);
        capabilities.setCapability("browserConnectionEnabled", true);


        WebDriver driver = new RemoteWebDriver(
                new URL("http://localhost:4444"),
                capabilities);

//		WebDriver driver = new MarionetteDriver(capabilities);

		return driver;
	}
 
Example 10
Project: Cognizant-Intelligent-Test-Scripter   File: WebDriverFactory.java   View source code 6 votes vote down vote up
private static WebDriver createRemoteDriver(String url, DesiredCapabilities caps, Boolean checkForProxy,
        Properties props) {
    try {
        if (isAppiumNative(url, caps.asMap())) {
            if (isAndroidNative(caps.asMap())) {
                return new io.appium.java_client.android.AndroidDriver(new URL(url), caps);
            } else if (isIOSNative(caps.asMap())) {
                return new io.appium.java_client.ios.IOSDriver(new URL(url), caps);
            }
        }
        if (url == null) {
            return new RemoteWebDriver(caps);
        }
        if (checkForProxy) {
            return new RemoteWebDriver(RemoteProxy.getProxyExecutor(new URL(url), props), caps);
        }
        return new RemoteWebDriver(new URL(url), caps);
    } catch (MalformedURLException ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return null;
}
 
Example 11
Project: mpay24-java   File: TestToken.java   View source code 6 votes vote down vote up
@Test
public void testTokenPaymentWithout3DS() throws ParseException, PaymentException, InterruptedException {
	Token token = mpay24.token(getTestTokenRequest(null));
	assertEquals("REDIRECT", token.getReturnCode());
	assertNotNull(token.getApiKey());
	assertNotNull(token.getRedirectLocation());
	assertNotNull(token.getToken());
	
	RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
	driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
	driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
	driver.findElement(By.id("expiry")).sendKeys("0520");
	driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
	driver.findElement(By.name("cvc")).sendKeys("123");
	driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

	TimeUnit.SECONDS.sleep(1l);
	
	Payment response = mpay24.payment(getTestPaymentRequest(), getTokenPaymentType(token.getToken()));

	assertEquals("OK", response.getReturnCode());
	assertNotNull(response.getmPayTid());
}
 
Example 12
Project: mpay24-java   File: TestPaymentPanel.java   View source code 6 votes vote down vote up
@Test
public void testShoppingCartAmounts() throws PaymentException {
	Payment response = mpay24.paymentPage(getTestPaymentRequest(120.0, null), getTestShoppingCart());
	assertSuccessfullResponse(response);
	RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
	WebElement element = driver.findElementById("cart");
	assertEquals("Rabatt:", element.findElement(By.xpath("tfoot/tr[1]/th")).getText());
	assertEquals("-10,00", element.findElement(By.xpath("tfoot/tr[1]/td")).getText());

	assertEquals("Versandkosten:", element.findElement(By.xpath("tfoot/tr[2]/th")).getText());
	assertEquals("-5,00", element.findElement(By.xpath("tfoot/tr[2]/td")).getText());
	
	assertEquals("Zwischensumme:", element.findElement(By.xpath("tfoot/tr[3]/th")).getText());
	assertEquals("100,00", element.findElement(By.xpath("tfoot/tr[3]/td")).getText());
	
	assertEquals("20.00% USt.:", element.findElement(By.xpath("tfoot/tr[4]/th")).getText());
	assertEquals("20,00", element.findElement(By.xpath("tfoot/tr[4]/td")).getText());
			
	assertEquals("Gesamtpreis:", element.findElement(By.xpath("tfoot/tr[5]/th")).getText());
	assertEquals("EUR 120,00", element.findElement(By.xpath("tfoot/tr[5]/td")).getText());

}
 
Example 13
Project: mpay24-java   File: TestPaymentPanel.java   View source code 6 votes vote down vote up
@Test
public void testLanguageEnglish() throws PaymentException {
	Payment response = mpay24.paymentPage(getTestPaymentRequest(1.0, null, Language.EN), getTestShoppingCart(getTestShoppingCartItemList()));
	assertSuccessfullResponse(response);
	
	RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
	WebElement element = driver.findElementById("cart");
	assertEquals("No.", element.findElement(By.xpath("thead/tr[1]/th[1]")).getText());
	assertEquals("Prod. No.", element.findElement(By.xpath("thead/tr[1]/th[2]")).getText());
	assertEquals("Product Name", element.findElement(By.xpath("thead/tr[1]/th[3]")).getText());
	assertEquals("Amount ordered", element.findElement(By.xpath("thead/tr[1]/th[4]")).getText());
	assertEquals("Price/Item", element.findElement(By.xpath("thead/tr[1]/th[5]")).getText());
	assertEquals("Total", element.findElement(By.xpath("thead/tr[1]/th[6]")).getText());
	assertEquals("Discount:", element.findElement(By.xpath("tfoot/tr[1]/th")).getText());
	assertEquals("Shipping Costs:", element.findElement(By.xpath("tfoot/tr[2]/th")).getText());
	assertEquals("Subtotal:", element.findElement(By.xpath("tfoot/tr[3]/th")).getText());
	assertEquals("Order Total:", element.findElement(By.xpath("tfoot/tr[5]/th")).getText());
}
 
Example 14
Project: mpay24-java   File: TestPaymentPanel.java   View source code 6 votes vote down vote up
@Test
public void testShippingAddress() throws PaymentException {
	Payment response = mpay24.paymentPage(getTestPaymentRequest(), getCustomerWithAddress(null));
	assertSuccessfullResponse(response);
	
	RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
	driver.findElement(By.name("selCC|VISA")).click();
	WebDriverWait wait = new WebDriverWait(driver, 20);
	wait.until(ExpectedConditions.elementToBeClickable(By.id("cardnumber"))); 
	assertEquals("Testperson-de Approved", driver.findElement(By.name("BillingAddr/Name")).getAttribute("value"));
	assertEquals("Hellersbergstraße 14", driver.findElement(By.name("BillingAddr/Street")).getAttribute("value"));
	assertNotExistent(driver, By.name("BillingAddr/Street2"));
	assertEquals("41460", driver.findElement(By.name("BillingAddr/Zip")).getAttribute("value"));
	assertEquals("Neuss", driver.findElement(By.name("BillingAddr/City")).getAttribute("value"));
	assertEquals("Ankeborg", driver.findElement(By.name("BillingAddr/State")).getAttribute("value"));
	assertEquals("Deutschland", driver.findElement(By.name("BillingAddr/Country/@Code")).findElement(By.xpath("option[@selected='']")).getText());
}
 
Example 15
Project: mpay24-java   File: TestPaymentPanel.java   View source code 6 votes vote down vote up
@Test
public void testShippingAddressWithStreet2() throws PaymentException {
	Payment response = mpay24.paymentPage(getTestPaymentRequest(), getCustomerWithAddress("Coconut 3"));
	assertSuccessfullResponse(response);
	
	RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
	driver.findElement(By.name("selPAYPAL|PAYPAL")).click();
	WebDriverWait wait = new WebDriverWait(driver, 20);
	wait.until(ExpectedConditions.elementToBeClickable(By.name("BillingAddr/Street"))); 
	assertEquals("Testperson-de Approved", driver.findElement(By.name("BillingAddr/Name")).getAttribute("value"));
	assertEquals("Hellersbergstraße 14", driver.findElement(By.name("BillingAddr/Street")).getAttribute("value"));
	assertEquals("Coconut 3", driver.findElement(By.name("BillingAddr/Street2")).getAttribute("value"));
	assertEquals("41460", driver.findElement(By.name("BillingAddr/Zip")).getAttribute("value"));
	assertEquals("Neuss", driver.findElement(By.name("BillingAddr/City")).getAttribute("value"));
	assertEquals("Ankeborg", driver.findElement(By.name("BillingAddr/State")).getAttribute("value"));
	assertEquals("Deutschland", driver.findElement(By.name("BillingAddr/Country/@Code")).findElement(By.xpath("option[@selected='']")).getText());
}
 
Example 16
Project: selenium-jupiter   File: SeleniumExtension.java   View source code 6 votes vote down vote up
public SeleniumExtension() {
    handlerMap.put(ChromeDriver.class, ChromeDriverHandler.class);
    handlerMap.put(FirefoxDriver.class, FirefoxDriverHandler.class);
    handlerMap.put(EdgeDriver.class, EdgeDriverHandler.class);
    handlerMap.put(OperaDriver.class, OperaDriverHandler.class);
    handlerMap.put(SafariDriver.class, SafariDriverHandler.class);
    handlerMap.put(RemoteWebDriver.class, RemoteDriverHandler.class);
    handlerMap.put(AppiumDriver.class, AppiumDriverHandler.class);
    handlerMap.put(List.class, ListDriverHandler.class);
    handlerMap.put(PhantomJSDriver.class, OtherDriverHandler.class);

    templateHandlerMap.put("chrome", ChromeDriver.class);
    templateHandlerMap.put("firefox", FirefoxDriver.class);
    templateHandlerMap.put("edge", EdgeDriver.class);
    templateHandlerMap.put("opera", OperaDriver.class);
    templateHandlerMap.put("safari", SafariDriver.class);
    templateHandlerMap.put("appium", AppiumDriver.class);
    templateHandlerMap.put("phantomjs", PhantomJSDriver.class);
    templateHandlerMap.put("chrome-in-docker", RemoteWebDriver.class);
    templateHandlerMap.put("firefox-in-docker", RemoteWebDriver.class);
    templateHandlerMap.put("opera-in-docker", RemoteWebDriver.class);
}
 
Example 17
Project: hippo   File: WebDriverProvider.java   View source code 6 votes vote down vote up
/**
 * Initialises the WebDriver (client).
 *
 * This method should be called once before each test to ensure that the session state doesn't bleed from one test
 * to another (such as user being logged in).
 */
public void initialise() {

    final ChromeOptions chromeOptions = new ChromeOptions();

    final Map<String, Object> chromePrefs = new HashMap<>();
    log.info("Setting WebDriver download directory to '{}'.", downloadDirectory);
    chromePrefs.put("download.default_directory", downloadDirectory.toAbsolutePath().toString());

    chromeOptions.setExperimentalOption("prefs", chromePrefs);
    log.info("Configuring WebDriver to run in {} mode.", isHeadlessMode ? "headless" : "full, graphical");
    if (isHeadlessMode) {
        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("window-size=1920,1080");
    }

    webDriver = new RemoteWebDriver(webDriverServiceProvider.getUrl(), chromeOptions);
}
 
Example 18
Project: Bytecoder   File: BytecoderUnitTestRunner.java   View source code 6 votes vote down vote up
private WebDriver newDriverForTest() {
    ChromeOptions theOptions = new ChromeOptions();
    theOptions.addArguments("headless");
    theOptions.addArguments("disable-gpu");

    LoggingPreferences theLoggingPreferences = new LoggingPreferences();
    theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
    theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);

    DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
    theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);

    return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
 
Example 19
Project: teasy   File: BaseTeasyElement.java   View source code 5 votes vote down vote up
@Override
public <X> X getScreenshotAs(OutputType<X> target) {
    if (getWebDriver().getClass() == RemoteWebDriver.class) {
        WebDriver augmentedDriver = new Augmenter().augment(getWebDriver());
        return ((TakesScreenshot) augmentedDriver).getScreenshotAs(target);
    } else {
        return ((TakesScreenshot) getWebDriver()).getScreenshotAs(target);
    }
}
 
Example 20
Project: teasy   File: WebDriverDecorator.java   View source code 5 votes vote down vote up
@Override
public <X> X getScreenshotAs(final OutputType<X> target) throws WebDriverException {
    if (driver.getClass() == RemoteWebDriver.class) {
        WebDriver augmentedDriver = new Augmenter().augment(driver);
        return ((TakesScreenshot) augmentedDriver).getScreenshotAs(target);
    } else {
        return ((TakesScreenshot) driver).getScreenshotAs(target);
    }
}
 
Example 21
Project: teasy   File: ChromeConfigTest.java   View source code 5 votes vote down vote up
@Test
@NeedRestartDriver
public void chrome_config_test() {
    openPage("main.html", BasePage.class);
    WebDriver webDriver = ((FramesTransparentWebDriver) SeleniumHolder.getWebDriver()).getWrappedDriver();

    Assert.assertTrue(webDriver instanceof ChromeDriver);

    Assert.assertEquals(((RemoteWebDriver) webDriver).getCapabilities().getCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR), UnexpectedAlertBehaviour.IGNORE.toString());
}
 
Example 22
Project: talk2grid   File: RemoteWebDriverEnricher.java   View source code 5 votes vote down vote up
/**
 * A helper method that enriches a {@link RemoteWebDriver} instance with the ability to route all browser
 * interaction requests directly to the node on which the session was created and route only the session termination
 * request to the hub.
 *
 * @param driver - A {@link RemoteWebDriver} instance.
 * @param hub    - A {@link Host} object that represents the Hub information.
 * @return - A {@link RemoteWebDriver} instance that is enriched with the ability to route all browser interactions
 * directly to the node.
 */
public static RemoteWebDriver enrichRemoteWebDriverToInteractDirectlyWithNode(RemoteWebDriver driver, Host hub) {
    if (hub == null) {
        return driver;
    }
    try {
        CommandExecutor grid = driver.getCommandExecutor();
        String sessionId = driver.getSessionId().toString();
        GridApiAssistant assistant = new GridApiAssistant(hub);

        Host nodeHost = assistant.getNodeDetailsForSession(sessionId);
        URL url = new URL(String.format("http://%s:%d/wd/hub", nodeHost.getIpAddress(), nodeHost.getPort()));
        CommandExecutor node = new HttpCommandExecutor(url);
        CommandCodec commandCodec = getCodec(grid, "commandCodec");
        ResponseCodec responseCodec = getCodec(grid, "responseCodec");
        setCodec(node, commandCodec, "commandCodec");
        setCodec(node, responseCodec, "responseCodec");
        appendListenerToWebDriver(driver, grid, node);
        LOG.info("Traffic will now be routed directly to the node.");
        LOG.warning(constructWarningMessage(hub));
    } catch (Exception e) {
        //Gobble exceptions
        LOG.warning("Unable to enrich the RemoteWebDriver instance. Root cause :" + e.getMessage()
            + ". Returning back the original instance that was passed, as is.");
    }
    return driver;
}
 
Example 23
Project: talk2grid   File: RemoteWebDriverEnricher.java   View source code 5 votes vote down vote up
private static Host getHubInfo(RemoteWebDriver driver) {
    Host hub = null;
    CommandExecutor executor = driver.getCommandExecutor();
    if (executor instanceof HttpCommandExecutor) {
        URL url = ((HttpCommandExecutor) executor).getAddressOfRemoteServer();
        hub = new Host(url.getHost(), Integer.toString(url.getPort()));
    }
    return hub;
}
 
Example 24
Project: talk2grid   File: RemoteWebDriverEnricher.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void appendListenerToWebDriver(RemoteWebDriver rwd, CommandExecutor grid, CommandExecutor node)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    CommandExecutor executor = new CustomCommandExecutor(grid, node);
    Class clazz = rwd.getClass();
    while (!RemoteWebDriver.class.equals(clazz)) {
        clazz = clazz.getSuperclass();
    }
    Method m = clazz.getDeclaredMethod("setCommandExecutor", CommandExecutor.class);
    m.setAccessible(true);
    m.invoke(rwd, executor);
}
 
Example 25
Project: Selenium-Foundation   File: GridUtility.java   View source code 5 votes vote down vote up
/**
 * Get the Selenium driver for the specified test class instance.
 * 
 * @return driver object (may be 'null')
 */
public static WebDriver getDriver() {
    SeleniumConfig config = SeleniumConfig.getConfig();
    GridServerParms hubParms = GridServerParms.getHubParms(config);
    if (isHubActive()) {
        return new RemoteWebDriver(hubParms.endpointUrl, config.getBrowserCaps());
    } else {
        throw new IllegalStateException("No Selenium Grid instance was found at " + hubParms.endpointUrl);
    }
}
 
Example 26
Project: GitTalent   File: GitTalentIntegrationTest.java   View source code 5 votes vote down vote up
@Test
public void testDeveloperTab() throws InterruptedException {
    RemoteWebDriver driver = chrome.getWebDriver();
    driver.get("http://gittalentbackend:8080/githubimport/developer/ldoguin");
    driver.get("http://gittalentbackend:8080/githubimport/status");
    while(driver.getPageSource().contains("false")) {
        Thread.sleep(1000);
        driver.navigate().refresh();
    };
    driver.get("http://gittalentfrontend/");
    WebElement myDynamicElement = (new WebDriverWait(driver, 20))
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/app-root/div/developers/div[1]/div[2]/div[1]/table/tbody/tr/td[2]")));
    Assert.assertTrue(myDynamicElement.getText().equals("ldoguin"));
}
 
Example 27
Project: Selenium-Foundation   File: GridUtility.java   View source code 5 votes vote down vote up
/**
 * Get the Selenium driver for the specified test class instance.
 * 
 * @return driver object (may be 'null')
 */
public static WebDriver getDriver() {
    SeleniumConfig config = SeleniumConfig.getConfig();
    GridServerParms hubParms = GridServerParms.getHubParms(config);
    if (isHubActive()) {
        return new RemoteWebDriver(hubParms.endpointUrl, config.getBrowserCaps());
    } else {
        throw new IllegalStateException("No Selenium Grid instance was found at " + hubParms.endpointUrl);
    }
}
 
Example 28
Project: msa-cucumber-appium   File: MobileApp.java   View source code 5 votes vote down vote up
public static MobileApp getInstance() throws Throwable {
    if (ourInstance == null) {
        ourInstance = new MobileApp();
        System.out.println("**********************Session id created********************** new session id : "+((RemoteWebDriver) driver.get()).getSessionId());
    }

    if(ourInstance != null &&  ((RemoteWebDriver) driver.get()).getSessionId() == null){
        ourInstance = new MobileApp();
        System.out.println("**********************Session id killed and new session created********************** new session id : "+((RemoteWebDriver) driver.get()).getSessionId());
    }

    return ourInstance;
}
 
Example 29
Project: marathonv5   File: JavaDriverTest.java   View source code 5 votes vote down vote up
public void succeedsWhenRequestingNonNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", false);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(!capabilities.is("nativeEvents"));
}
 
Example 30
Project: marathonv5   File: JavaDriverTest.java   View source code 5 votes vote down vote up
public void getSessions() {
    driver = new JavaDriver();
    JavaDriver driver1 = new JavaDriver();
    SessionId id1 = ((RemoteWebDriver) driver).getSessionId();
    SessionId id2 = driver1.getSessionId();
    AssertJUnit.assertFalse(id1.equals(id2));
}
 
Example 31
Project: marathonv5   File: JavaDriverCapabilitiesTest.java   View source code 5 votes vote down vote up
public void javaDriver() {
    driver = new JavaDriver();
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertEquals("java", capabilities.getBrowserName());
    AssertJUnit.assertEquals(true, capabilities.is("takesScreenshot"));
    AssertJUnit.assertEquals(false, capabilities.is("nativeEvents"));
}
 
Example 32
Project: webdriver-supplier   File: BaseListener.java   View source code 5 votes vote down vote up
private void injectSessionId(final ITestResult testResult) {
    ofNullable(DRIVER_CONTAINER.get())
            .map(t -> t._1)
            .filter(d -> d instanceof RemoteWebDriver)
            .map(d -> ((RemoteWebDriver) d).getSessionId())
            .ifPresent(id -> testResult.setAttribute("sessionId", id));
}
 
Example 33
Project: webdriver-supplier   File: MockWDFactory.java   View source code 5 votes vote down vote up
@Override
public WebDriver createDriver(final Browser browser, final XmlConfig config) {
    final RemoteWebDriver driver = mock(RemoteWebDriver.class);
    when(driver.getScreenshotAs(OutputType.BYTES)).thenReturn(new byte[]{1, 2, 3});
    doReturn(new SessionId(randomAlphanumeric(14))).when(driver).getSessionId();
    return driver;
}
 
Example 34
Project: cucumber-framework-java   File: WebDriverThread.java   View source code 5 votes vote down vote up
private void instantiateWebDriver( DesiredCapabilities desiredCapabilities ) throws MalformedURLException
{

    System.out.println( String.format( "Current Operating System : {%s}"
            , operatingSystem ) );
    System.out.println( String.format( "Current System Architecture : {%s}"
            , systemArchitecture ) );
    System.out.println( String.format( "Current Browser : {%s}\n"
            , driverType ) );

    if( useRemoteWebDriver )
    {
        URL seleniumGridURL = new URL( System.getProperty( "gridURL" ) );
        System.out.println( "seleniumGridURL = " + seleniumGridURL );
        String desiredBrowserVersion = System.getProperty( "desiredBrowserVersion" );
        String desiredPlatform = System.getProperty( "desiredPlatform" );

        if( ( null != desiredPlatform ) && desiredPlatform.isEmpty() )
        {
            desiredCapabilities.setPlatform( Platform.valueOf( desiredPlatform ) );
        }

        if( null != desiredBrowserVersion && desiredBrowserVersion.isEmpty() )
        {
            desiredCapabilities.setVersion( desiredBrowserVersion );
        }
        driver = new RemoteWebDriver( seleniumGridURL, desiredCapabilities );

    } else
    {
        driver = selectedDriverType.getWebDriverObject( desiredCapabilities );
    }
}
 
Example 35
Project: WebAndAppUITesting   File: BaseOpt.java   View source code 5 votes vote down vote up
/**
 * 兼容循环执行时 不会重新加载构造方法的问题
 * 
 * @return
 */
public RemoteWebDriver getDriver() {
	if (driver == null || driver.getSessionId() == null) {
		driver = DriverFactory.getInstance().getDriver();
		wait = new WebDriverWait(driver, DRIVER_WAIT_TIMEOUT_IN_SECOND, 500);
	}
	return driver;
}
 
Example 36
Project: SilkAppDriver   File: MobileTests.java   View source code 5 votes vote down vote up
@Ignore
@Test
public void test() throws IOException {
	Map<String, String> baseState = new HashMap<>();
	baseState.put("type", "MOBILE");
	baseState.put("connectionString", "platformName=Android;app=C:\\apps\\InsuranceMobile.apk");

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("appdriver-basestate", baseState);

	WebDriver driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
	String title = driver.getTitle();

	assertEquals("", title); // TODO: Maybe we find something to use as the
								// title?

	WebElement email = driver
			.findElement(By.xpath("//MobileTextField[@resource-id='silktest.insurancemobile:id/email']"));
	email.sendKeys("test");
	assertEquals("test", email.getText());
	
	email.clear();
	assertEquals("", email.getText());
	email.sendKeys("[email protected]");

	driver.findElement(By.xpath("//MobileTextField[@resource-id='silktest.insurancemobile:id/password']"))
			.sendKeys("john");

	driver.findElement(By.xpath("//MobileButton[@resource-id='silktest.insurancemobile:id/log_in_button']"))
			.click();

	driver.findElement(By.xpath("//MobileObject[@content-desc='drawer_open']")).click();

	driver.findElement(By.xpath("//MobileObject[@caption='Logout']")).click();

	driver.quit();
}
 
Example 37
Project: SilkAppDriver   File: ExceptionTests.java   View source code 5 votes vote down vote up
@Before
public void startApp() throws Exception {
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("app", APP);

	driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
}
 
Example 38
Project: SilkAppDriver   File: NotepadDemoTest.java   View source code 5 votes vote down vote up
@Before
public void startApp() throws Exception {
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("app", APP);

	driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);

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

	String windowHandle = driver.getWindowHandle();
	assertNotNull(windowHandle);

	Point windowPosition = driver.manage().window().getPosition();
	assertNotNull(windowPosition);
}
 
Example 39
Project: Query   File: QueryTest.java   View source code 5 votes vote down vote up
private void initQueryObject() {
    Capabilities mockedCapabilities = mock(Capabilities.class);
    when(mockedCapabilities.getBrowserName()).thenReturn(BrowserType.GOOGLECHROME);
    when(mockedCapabilities.getPlatform()).thenReturn(Platform.YOSEMITE);

    RemoteWebDriver mockedWebDriver = mock(RemoteWebDriver.class);
    when(mockedWebDriver.getCapabilities()).thenReturn(mockedCapabilities);
    when(mockedWebDriver.findElement(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_FOR_DEFAULT);
    when(mockedWebDriver.findElements(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_LIST_FOR_DEFAULT);

    Query.initQueryObjects(mockedWebDriver);
}
 
Example 40
Project: Query   File: QueryTest.java   View source code 5 votes vote down vote up
private void initQueryObjectWithAppiumAndroid() {
    Capabilities mockedCapabilities = mock(Capabilities.class);
    when(mockedCapabilities.getBrowserName()).thenReturn("");
    when(mockedCapabilities.getPlatform()).thenReturn(Platform.fromString(MobilePlatform.ANDROID));
    when(mockedCapabilities.getCapability("automationName")).thenReturn("Appium");

    RemoteWebDriver mockedWebDriver = mock(AndroidDriver.class);
    when(mockedWebDriver.getCapabilities()).thenReturn(mockedCapabilities);
    when(mockedWebDriver.findElement(DEFAULT_LOCATOR)).thenReturn(MOCKED_MOBILE_ELEMENT_FOR_DEFAULT);
    when(mockedWebDriver.findElements(DEFAULT_LOCATOR)).thenReturn(MOCKED_MOBILE_ELEMENT_LIST_FOR_DEFAULT);

    Query.initQueryObjects(mockedWebDriver);
}