Search in sources :

Example 1 with MutableCapabilities

use of org.openqa.selenium.MutableCapabilities in project zalenium by zalando.

the class CloudTestingRemoteProxy method addCapabilitiesToRegistrationRequest.

public static RegistrationRequest addCapabilitiesToRegistrationRequest(RegistrationRequest registrationRequest, int concurrency, String proxyName) {
    MutableCapabilities desiredCapabilities = new MutableCapabilities();
    desiredCapabilities.setCapability(RegistrationRequest.MAX_INSTANCES, concurrency);
    desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, proxyName);
    desiredCapabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.ANY);
    registrationRequest.getConfiguration().capabilities.add(desiredCapabilities);
    registrationRequest.getConfiguration().maxSession = concurrency;
    return registrationRequest;
}
Also used : MutableCapabilities(org.openqa.selenium.MutableCapabilities)

Example 2 with MutableCapabilities

use of org.openqa.selenium.MutableCapabilities in project blueocean-plugin by jenkinsci.

the class AthModule method configure.

@Override
protected void configure() {
    Config cfg = new Config();
    File userConfig = new File(new File(System.getProperty("user.home")), ".blueocean-ath-config");
    if (userConfig.canRead()) {
        cfg.loadProps(userConfig);
    }
    bind(Config.class).toInstance(cfg);
    String webDriverType = cfg.getString("webDriverType");
    MutableCapabilities capability;
    if ("firefox".equals(webDriverType)) {
        capability = new FirefoxOptions();
    } else {
        capability = new ChromeOptions();
    }
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capability.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    String webDriverUrl = cfg.getString("webDriverUrl", "http://localhost:4444/wd/hub");
    String webDriverBrowserSize = cfg.getString("webDriverBrowserSize");
    try {
        String launchUrl = cfg.getString("jenkinsUrl");
        if (launchUrl == null) {
            launchUrl = new String(Files.readAllBytes(Paths.get("runner/.blueocean-ath-jenkins-url")));
        }
        capability.setCapability("extendedDebugging", "true");
        capability.setCapability("initialBrowserUrl", launchUrl);
        if (!StringUtils.isBlank(cfg.getString("TUNNEL_IDENTIFIER"))) {
            capability.setCapability("tunnelIdentifier", cfg.getString("TUNNEL_IDENTIFIER"));
        }
        WebDriver driver = new RemoteWebDriver(new URL(webDriverUrl), capability);
        LocalDriver.setCurrent(driver);
        driver = new Augmenter().augment(driver);
        if (webDriverBrowserSize == null) {
            driver.manage().window().maximize();
        } else {
            String[] widthXHeight = webDriverBrowserSize.split("x");
            driver.manage().window().setSize(new Dimension(Integer.parseInt(widthXHeight[0]), Integer.parseInt(widthXHeight[1])));
        }
        driver.manage().deleteAllCookies();
        bind(WebDriver.class).toInstance(driver);
        bindConstant().annotatedWith(BaseUrl.class).to(launchUrl);
        LocalDriver.setUrlBase(launchUrl);
        JenkinsUser admin = new JenkinsUser(cfg.getString("adminUsername", "alice"), cfg.getString("adminPassword", "alice"));
        bind(JenkinsUser.class).toInstance(admin);
        CustomJenkinsServer server = new CustomJenkinsServer(new URI(launchUrl), admin);
        bind(JenkinsServer.class).toInstance(server);
        bind(CustomJenkinsServer.class).toInstance(server);
        if (server.getComputerSet().getTotalExecutors() < 10) {
            server.runScript("jenkins.model.Jenkins.get().setNumExecutors(10);\n" + "jenkins.model.Jenkins.get().save();\n", true);
        }
        Properties properties = new Properties();
        File liveProperties = new File("live.properties");
        if (liveProperties.canRead()) {
            properties.load(new FileInputStream(liveProperties));
        }
        bind(Properties.class).annotatedWith(Names.named("live")).toInstance(properties);
    } catch (Exception e) {
        LocalDriver.destroy();
        throw new RuntimeException(e);
    }
    install(new FactoryModuleBuilder().implement(ActivityPage.class, ActivityPage.class).build(ActivityPageFactory.class));
    install(new FactoryModuleBuilder().implement(MultiBranchPipeline.class, MultiBranchPipeline.class).build(MultiBranchPipelineFactory.class));
    install(new FactoryModuleBuilder().implement(FreestyleJob.class, FreestyleJob.class).build(FreestyleJobFactory.class));
    install(new FactoryModuleBuilder().implement(ClassicPipeline.class, ClassicPipeline.class).build(ClassicPipelineFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsPipelinePage.class, RunDetailsPipelinePage.class).build(RunDetailsPipelinePageFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsArtifactsPage.class, RunDetailsArtifactsPage.class).build(RunDetailsArtifactsPageFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsTestsPage.class, RunDetailsTestsPage.class).build(RunDetailsTestsPageFactory.class));
    install(new FactoryModuleBuilder().implement(BranchPage.class, BranchPage.class).build(BranchPageFactory.class));
    install(new FactoryModuleBuilder().implement(PullRequestsPage.class, PullRequestsPage.class).build(PullRequestsPageFactory.class));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) RunDetailsArtifactsPageFactory(io.blueocean.ath.factory.RunDetailsArtifactsPageFactory) Properties(java.util.Properties) BranchPageFactory(io.blueocean.ath.factory.BranchPageFactory) URI(java.net.URI) URL(java.net.URL) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) PullRequestsPageFactory(io.blueocean.ath.factory.PullRequestsPageFactory) FreestyleJobFactory(io.blueocean.ath.factory.FreestyleJobFactory) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ClassicPipelineFactory(io.blueocean.ath.factory.ClassicPipelineFactory) RunDetailsPipelinePageFactory(io.blueocean.ath.factory.RunDetailsPipelinePageFactory) MultiBranchPipelineFactory(io.blueocean.ath.factory.MultiBranchPipelineFactory) RunDetailsTestsPageFactory(io.blueocean.ath.factory.RunDetailsTestsPageFactory) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) JenkinsServer(com.offbytwo.jenkins.JenkinsServer) Dimension(org.openqa.selenium.Dimension) FileInputStream(java.io.FileInputStream) Augmenter(org.openqa.selenium.remote.Augmenter) ActivityPageFactory(io.blueocean.ath.factory.ActivityPageFactory) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) File(java.io.File)

Example 3 with MutableCapabilities

use of org.openqa.selenium.MutableCapabilities in project flow by vaadin.

the class ChromeDeviceTest method setDevToolsRuntimeCapabilities.

/**
 * Sets the `se:cdp` and `se:cdpVersion` capabilities for the remote web
 * driver. Note that the capabilities are set at runtime because they depend
 * on the session id that becomes only available after the driver is
 * initialized. Without these capabilities, Selenium cannot establish a
 * connection with DevTools.
 */
private void setDevToolsRuntimeCapabilities(RemoteWebDriver driver, URL remoteUrl) throws RuntimeException {
    try {
        Field capabilitiesField = RemoteWebDriver.class.getDeclaredField("capabilities");
        capabilitiesField.setAccessible(true);
        String sessionId = driver.getSessionId().toString();
        String devtoolsUrl = String.format("ws://%s:%s/devtools/%s/page", remoteUrl.getHost(), remoteUrl.getPort(), sessionId);
        MutableCapabilities mutableCapabilities = (MutableCapabilities) capabilitiesField.get(driver);
        mutableCapabilities.setCapability("se:cdp", devtoolsUrl);
        mutableCapabilities.setCapability("se:cdpVersion", mutableCapabilities.getBrowserVersion());
    } catch (Exception e) {
        throw new RuntimeException("Failed to set DevTools capabilities for RemoteWebDriver");
    }
}
Also used : Field(java.lang.reflect.Field) MutableCapabilities(org.openqa.selenium.MutableCapabilities) IOException(java.io.IOException)

Example 4 with MutableCapabilities

use of org.openqa.selenium.MutableCapabilities in project zalenium by zalando.

the class ZaleniumConsoleServletTest method setUp.

@Before
public void setUp() throws IOException {
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
        new JMXHelper().unregister(objectName);
    } catch (MalformedObjectNameException | InstanceNotFoundException e) {
    // Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
    }
    registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    this.originalContainerClient = ContainerFactory.getContainerClientGenerator();
    ContainerFactory.setContainerClientGenerator(DockerContainerMock::getMockedDockerContainerClient);
    // Creating the configuration and the registration request of the proxy (node)
    RegistrationRequest registrationRequest = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
    DockerSeleniumStarterRemoteProxy proxyZero = DockerSeleniumStarterRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(30001, SauceLabsRemoteProxy.class.getCanonicalName());
    CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
    when(commonProxyUtilities.readJSONFromUrl(anyString(), anyString(), anyString())).thenReturn(null);
    SauceLabsRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
    SauceLabsRemoteProxy sauceLabsProxy = SauceLabsRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(30002, BrowserStackRemoteProxy.class.getCanonicalName());
    BrowserStackRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
    BrowserStackRemoteProxy browserStackRemoteProxy = BrowserStackRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(30003, TestingBotRemoteProxy.class.getCanonicalName());
    TestingBotRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
    TestingBotRemoteProxy testingBotRemoteProxy = TestingBotRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(40000, DockerSeleniumRemoteProxy.class.getCanonicalName());
    registrationRequest.getConfiguration().capabilities.clear();
    registrationRequest.getConfiguration().capabilities.addAll(DockerSeleniumStarterRemoteProxy.getCapabilities());
    DockerSeleniumRemoteProxy proxyOne = DockerSeleniumRemoteProxy.getNewInstance(registrationRequest, registry);
    registrationRequest = TestUtils.getRegistrationRequestForTesting(40001, DockerSeleniumRemoteProxy.class.getCanonicalName());
    registrationRequest.getConfiguration().capabilities.clear();
    List<MutableCapabilities> capabilities = DockerSeleniumStarterRemoteProxy.getCapabilities();
    MutableCapabilities desiredCapabilities = new MutableCapabilities();
    desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, "NEW_BROWSER");
    desiredCapabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    desiredCapabilities.setCapability(RegistrationRequest.MAX_INSTANCES, 1);
    capabilities.add(desiredCapabilities);
    registrationRequest.getConfiguration().capabilities.addAll(capabilities);
    DockerSeleniumRemoteProxy proxyTwo = DockerSeleniumRemoteProxy.getNewInstance(registrationRequest, registry);
    registry.add(proxyZero);
    registry.add(proxyOne);
    registry.add(proxyTwo);
    registry.add(sauceLabsProxy);
    registry.add(browserStackRemoteProxy);
    registry.add(testingBotRemoteProxy);
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    when(request.getParameter("config")).thenReturn("true");
    when(request.getParameter("configDebug")).thenReturn("true");
    when(request.getServerName()).thenReturn("localhost");
    when(response.getOutputStream()).thenReturn(TestUtils.getMockedServletOutputStream());
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) SauceLabsRemoteProxy(de.zalando.ep.zalenium.proxy.SauceLabsRemoteProxy) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) TestingBotRemoteProxy(de.zalando.ep.zalenium.proxy.TestingBotRemoteProxy) HttpServletResponse(javax.servlet.http.HttpServletResponse) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ObjectName(javax.management.ObjectName) HttpServletRequest(javax.servlet.http.HttpServletRequest) DockerContainerMock(de.zalando.ep.zalenium.util.DockerContainerMock) DockerSeleniumStarterRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumStarterRemoteProxy) Hub(org.openqa.grid.web.Hub) MutableCapabilities(org.openqa.selenium.MutableCapabilities) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) BrowserStackRemoteProxy(de.zalando.ep.zalenium.proxy.BrowserStackRemoteProxy) Before(org.junit.Before)

Example 5 with MutableCapabilities

use of org.openqa.selenium.MutableCapabilities in project zalenium by zalando.

the class TestUtils method getDockerSeleniumCapabilitiesForTesting.

public static List<MutableCapabilities> getDockerSeleniumCapabilitiesForTesting() {
    String screenResolution = String.format("%sx%s", DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getWidth(), DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getHeight());
    List<MutableCapabilities> dsCapabilities = new ArrayList<>();
    MutableCapabilities firefoxCapabilities = new MutableCapabilities();
    firefoxCapabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
    firefoxCapabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    firefoxCapabilities.setCapability(CapabilityType.VERSION, "57.0");
    firefoxCapabilities.setCapability(RegistrationRequest.MAX_INSTANCES, 1);
    firefoxCapabilities.setCapability("screenResolution", screenResolution);
    firefoxCapabilities.setCapability("tz", DockerSeleniumStarterRemoteProxy.getConfiguredTimeZone().getID());
    dsCapabilities.add(firefoxCapabilities);
    MutableCapabilities chromeCapabilities = new MutableCapabilities();
    chromeCapabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    chromeCapabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    chromeCapabilities.setCapability(CapabilityType.VERSION, "62.0.3202.94");
    chromeCapabilities.setCapability(RegistrationRequest.MAX_INSTANCES, 1);
    chromeCapabilities.setCapability("screenResolution", screenResolution);
    chromeCapabilities.setCapability("tz", DockerSeleniumStarterRemoteProxy.getConfiguredTimeZone().getID());
    dsCapabilities.add(chromeCapabilities);
    return dsCapabilities;
}
Also used : MutableCapabilities(org.openqa.selenium.MutableCapabilities) ArrayList(java.util.ArrayList)

Aggregations

MutableCapabilities (org.openqa.selenium.MutableCapabilities)7 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 JenkinsServer (com.offbytwo.jenkins.JenkinsServer)1 BrowserStackRemoteProxy (de.zalando.ep.zalenium.proxy.BrowserStackRemoteProxy)1 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)1 DockerSeleniumStarterRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumStarterRemoteProxy)1 SauceLabsRemoteProxy (de.zalando.ep.zalenium.proxy.SauceLabsRemoteProxy)1 TestingBotRemoteProxy (de.zalando.ep.zalenium.proxy.TestingBotRemoteProxy)1 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)1 DockerContainerMock (de.zalando.ep.zalenium.util.DockerContainerMock)1 ActivityPageFactory (io.blueocean.ath.factory.ActivityPageFactory)1 BranchPageFactory (io.blueocean.ath.factory.BranchPageFactory)1 ClassicPipelineFactory (io.blueocean.ath.factory.ClassicPipelineFactory)1 FreestyleJobFactory (io.blueocean.ath.factory.FreestyleJobFactory)1 MultiBranchPipelineFactory (io.blueocean.ath.factory.MultiBranchPipelineFactory)1 PullRequestsPageFactory (io.blueocean.ath.factory.PullRequestsPageFactory)1 RunDetailsArtifactsPageFactory (io.blueocean.ath.factory.RunDetailsArtifactsPageFactory)1 RunDetailsPipelinePageFactory (io.blueocean.ath.factory.RunDetailsPipelinePageFactory)1