-
Notifications
You must be signed in to change notification settings - Fork 20
Properties sample #27
Changes from 9 commits
d7e8f17
4c6d611
20968a9
6d51716
0aaf5da
f7b5b79
6677456
40611eb
68b2fd4
ab9d9c8
e23c6ef
453913f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,21 +41,27 @@ public class TagWebDriver { | |
private static final Logger log = LoggerFactory.getLogger(TagWebDriver.class); | ||
|
||
private static WebDriver webDriver; | ||
private static final int ATTEMPTS_TO_START_WEBDRIVER = Integer.parseInt(Props.get("driver.create.attempts", "3")); | ||
private static BrowserMobProxy proxy; | ||
private static final int WEBDRIVER_CREATE_ATTEMPTS = Integer.parseInt(Props.get("webdriver.create.attempts", "3")); | ||
private static final String WEBDRIVER_PATH = "src/test/resources/webdrivers/"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move it to config and by default get it from system PATH |
||
private static final String WEBDRIVER_URL = Props.get("webdriver.url"); | ||
private static final String WEBDRIVER_STARTING_URL = Props.get("webdriver.starting.url"); | ||
private static final String WEBDRIVER_PROXY_ENABLED = Props.get("webdriver.proxy.enabled", "false"); | ||
private static final String WEBDRIVER_BROWSER_IE_KILLONDISPOSE = Props.get("webdriver.browser.ie.killOnDispose", "false"); | ||
private static final String VIDEO_ENABLED = Props.get("video.enabled", "false"); | ||
|
||
|
||
public static org.openqa.selenium.WebDriver getDriver() { | ||
if (Environment.WEB != PageFactory.getEnvironment()) { | ||
throw new FactoryRuntimeException("Failed to get web driver while environment is not web"); | ||
} | ||
|
||
if (null == webDriver) { | ||
if (Boolean.valueOf(Props.get("video.enable"))) { | ||
if (Boolean.valueOf(VIDEO_ENABLED)) { | ||
VideoRecorder.getInstance().startRecording(); | ||
} | ||
|
||
for (int i = 1; i <= ATTEMPTS_TO_START_WEBDRIVER; i++) { | ||
for (int i = 1; i <= WEBDRIVER_CREATE_ATTEMPTS; i++) { | ||
log.info("Attempt #" + i + " to start web driver"); | ||
try { | ||
createDriver(); | ||
|
@@ -78,10 +84,10 @@ public static org.openqa.selenium.WebDriver getDriver() { | |
private static void createDriver() throws UnsupportedBrowserException { | ||
DesiredCapabilities capabilities = new DesiredCapabilitiesParser().parse(); | ||
|
||
if (Props.get("webdriver.remote.host").isEmpty()) { | ||
if (WEBDRIVER_URL.isEmpty()) { | ||
|
||
//Local proxy available on local webdriver instances only | ||
if (!Props.get("proxy.enable").isEmpty()) { | ||
if (!WEBDRIVER_PROXY_ENABLED.isEmpty()) { | ||
setProxy(new BrowserMobProxyServer()); | ||
proxy.start(0); | ||
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); | ||
|
@@ -138,15 +144,15 @@ private static void createDriver() throws UnsupportedBrowserException { | |
throw new UnsupportedBrowserException("'" + PageFactory.getBrowserName() + "' is not supported yet"); | ||
} | ||
try { | ||
URL remoreUrl = new URL("http://" + Props.get("webdriver.remote.host") + ":4444/wd/hub"); | ||
setWebDriver(new RemoteWebDriver(remoreUrl, capabilities)); | ||
URL remoteUrl = new URL(WEBDRIVER_URL); | ||
setWebDriver(new RemoteWebDriver(remoteUrl, capabilities)); | ||
} catch (MalformedURLException e) { | ||
log.error("Can not parse remote url. Check webdriver.remote.host property"); | ||
log.error("Could not parse remote url. Check 'webdriver.url' property"); | ||
} | ||
} | ||
webDriver.manage().timeouts().pageLoadTimeout(getTimeOutInSeconds(), TimeUnit.SECONDS); | ||
webDriver.manage().window().maximize(); | ||
webDriver.get(PageFactory.getInitialUrl()); | ||
webDriver.get(WEBDRIVER_STARTING_URL); | ||
} | ||
|
||
public static void dispose() { | ||
|
@@ -178,7 +184,7 @@ public static void dispose() { | |
|
||
try { | ||
if ("IE".equals(PageFactory.getBrowserName()) | ||
&& Boolean.parseBoolean(Props.get("browser.ie.killOnDispose", "true"))) { | ||
&& Boolean.parseBoolean(WEBDRIVER_BROWSER_IE_KILLONDISPOSE)) { | ||
// Kill IE by Windows means instead of webdriver.quit() | ||
Runtime.getRuntime().exec("taskkill /f /im iexplore.exe").waitFor(); | ||
Runtime.getRuntime().exec("taskkill /f /im IEDriverServer.exe").waitFor(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#mobile or web | ||
driver.environment = mobile | ||
|
||
#path to page objects | ||
page.package = ru.sbtqa.tag.mobilefactory.entries | ||
#default wait timeout in milliseconds | ||
page.load.timeout = 60000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. milliseconds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I need to fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment that it is in ms |
||
|
||
video.enabled = false | ||
video.path.dest = /tmp/video | ||
video.path.temp = /tmp/video | ||
video.highlight.enabled = false | ||
|
||
#driver or raw | ||
screenshot.strategy = driver | ||
|
||
#tasks to kill before test (ONLY FOR WINDOWS) | ||
tasks.to.kill = iexplorer,chrome | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it OS independent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not. check this issue #26 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add in commet please whait is for windows only |
||
|
||
#IN CASE OF MOBILE | ||
#parameters for mobile driver create | ||
appium.url = http://127.0.0.1:4723/wd/hub | ||
appium.device.name = Android Emulator | ||
appium.device.platform = 6.0 | ||
appium.app.package = com.android.settings | ||
appium.app.activity = .Settings | ||
|
||
#IN CASE OF WEB | ||
#parameters for web driver create | ||
webdriver.browser.name = Chrome | ||
#kill ie browser process after test (ONLY FOR WINDOWS) | ||
webdriver.browser.ie.killOnDispose = true | ||
webdriver.starter.url = "http://google.com" | ||
webdriver.create.attempts = 3 | ||
webdriver.proxy.enabled = false | ||
#optional. In case of using remote WebDriver | ||
webdriver.url = http://127.0.0.1:4444/wd/hub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current url is fetched as a URL instance, why not build it with the same class, instead of string concatenations and COLON_TWO_SLASHES variables? Or use https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html or https://github.com/mikaelhg/urlbuilder for URL buildings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And no, this is not a legacy. When one touches legacy shit and changes "//" string to a const, he gets involved. So one must make a good code from legacy shit, not a less shitty legacy shit.