2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.frontend.ci.tests.execute.setup;
23 import java.net.MalformedURLException;
25 import org.onap.sdc.backend.ci.tests.config.Config;
26 import org.onap.sdc.frontend.ci.tests.exception.WebDriverThreadRuntimeException;
27 import org.openqa.selenium.Dimension;
28 import org.openqa.selenium.WebDriver;
29 import org.openqa.selenium.firefox.FirefoxDriver;
30 import org.openqa.selenium.firefox.FirefoxOptions;
31 import org.openqa.selenium.firefox.FirefoxProfile;
32 import org.openqa.selenium.remote.CapabilityType;
33 import org.openqa.selenium.remote.LocalFileDetector;
34 import org.openqa.selenium.remote.RemoteWebDriver;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public class WebDriverThread {
40 private final static Logger LOGGER = LoggerFactory.getLogger(SetupCDTest.class);
42 private WebDriver webdriver;
43 private FirefoxProfile firefoxProfile;
44 private static final String SELENIUM_NODE_URL = "http://%s:%s/wd/hub";
46 WebDriverThread(Config config) {
48 webdriver.manage().window().maximize();
51 public WebDriver getDriver() {
56 if (webdriver != null) {
63 private void initDriver(final Config config) {
64 if (config.isRemoteTesting()) {
65 LOGGER.info("Opening REMOTE browser");
66 final String remoteEnvIP = config.getRemoteTestingMachineIP();
67 final String remoteEnvPort = config.getRemoteTestingMachinePort();
68 FirefoxOptions firefoxOptions = new FirefoxOptions();
69 firefoxOptions.setProfile(initFirefoxProfile(config));
70 firefoxOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
71 final String remoteUrlString = String.format(SELENIUM_NODE_URL, remoteEnvIP, remoteEnvPort);
74 remoteUrl = new URL(remoteUrlString);
75 } catch (MalformedURLException e) {
76 throw new WebDriverThreadRuntimeException(String.format("Malformed URL '%s'", remoteUrlString), e);
78 final RemoteWebDriver remoteWebDriver = new RemoteWebDriver(remoteUrl, firefoxOptions);
79 remoteWebDriver.setFileDetector(new LocalFileDetector());
80 remoteWebDriver.manage().window().setSize(new Dimension(1920,1440));
81 webdriver = remoteWebDriver;
84 LOGGER.info("Opening LOCAL browser");
85 System.setProperty("webdriver.gecko.driver", "target/gecko/geckodriver");
86 FirefoxOptions firefoxOptions = new FirefoxOptions();
87 final FirefoxProfile firefoxProfile = initFirefoxProfile(config);
88 firefoxProfile.setPreference("browser.download.dir", config.getDownloadAutomationFolder());
89 firefoxProfile.setPreference("browser.download.folderList", 2);
90 firefoxOptions.setProfile(firefoxProfile);
91 firefoxOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
92 firefoxOptions.setHeadless(false);
93 webdriver = new FirefoxDriver(firefoxOptions);
94 webdriver.manage().window().maximize();
98 private FirefoxProfile initFirefoxProfile(Config config) {
99 firefoxProfile = new FirefoxProfile();
100 firefoxProfile.setPreference("browser.download.folderList", 0);
101 //firefoxProfile.setPreference("browser.alwaysOpenInSystemViewerContextMenuItem", false);
102 //firefoxProfile.setPreference("browser.download.useDownloadDir", false);
103 //firefoxProfile.setPreference("browser.download.downloadDir", config.getContainerDownloadAutomationFolder());
104 //firefoxProfile.setPreference("browser.download.dir", config.getContainerDownloadAutomationFolder());
105 //firefoxProfile.setPreference("app.update.notifyDuringDownload", false);
106 //firefoxProfile.setPreference("browser.download.lastDir", config.getContainerDownloadAutomationFolder());
107 firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream, application/xml, text/plain, text/xml, image/jpeg");
108 firefoxProfile.setPreference("network.proxy.type", 4);
109 firefoxProfile.setAcceptUntrustedCertificates(true);
110 firefoxProfile.setAssumeUntrustedCertificateIssuer(true);
112 return firefoxProfile;
115 FirefoxProfile getFirefoxProfile() {
116 return firefoxProfile;