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;
}
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));
}
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");
}
}
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());
}
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;
}
Aggregations