com.teststeps.thekla4j.browser.selenium.RemoteBrowser Maven / Gradle / Ivy
package com.teststeps.thekla4j.browser.selenium;
import com.teststeps.thekla4j.browser.config.BrowserConfig;
import com.teststeps.thekla4j.browser.core.Browser;
import com.teststeps.thekla4j.browser.selenium.config.SeleniumConfig;
import io.vavr.Function1;
import io.vavr.Function3;
import io.vavr.control.Option;
import io.vavr.control.Try;
import lombok.extern.log4j.Log4j2;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.HashMap;
@Log4j2(topic = "Selenium Remote Browser")
class RemoteBrowser {
static Try with(Option testName, SeleniumConfig seleniumConfig, BrowserConfig browserConfig) {
return createCapabilities.apply(browserConfig)
.map(caps -> {
caps.setCapability("bstack:options", createBrowserStackCapabilities.apply(testName, seleniumConfig, browserConfig));
return caps;
})
.mapTry(caps -> new RemoteWebDriver(new URL(seleniumConfig.remoteUrl()), caps, false))
.peek(driver -> System.out.println("Connecting to: " + seleniumConfig.remoteUrl()))
.peek(driver -> System.out.println("SessionID: " + driver.getSessionId()))
.onFailure(System.err::println)
.map(SeleniumBrowser::new);
}
static Try defaultChromeBrowser(Option testName, SeleniumConfig seleniumConfig) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("chrome");
return Try.of(() -> capabilities)
.map(caps -> {
caps.setCapability("bstack:options", createBrowserStackCapabilities.apply(testName, seleniumConfig, null));
return caps;
})
.mapTry(url -> new SeleniumBrowser(new RemoteWebDriver(new URL(seleniumConfig.remoteUrl()), capabilities, false)));
}
private static final Function3