Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #291 from Cognifide/288-bobcatwait-reworked
Browse files Browse the repository at this point in the history
288 bobcatwait reworked
  • Loading branch information
mkrzyzanowski committed Oct 3, 2018
2 parents 85e7eae + 77dc779 commit ef63f2f
Show file tree
Hide file tree
Showing 19 changed files with 639 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public final class ConfigKeys {

public static final String WEBDRIVER_CAP_PLATFORM_NAME = "webdriver.cap.platformName";

/**
* @deprecated since 1.6.0; use {@code timings.*} properties
*/
@Deprecated
public static final String WEBDRIVER_DEFAULT_TIMEOUT = "webdriver.defaultTimeout";

public static final String WEBDRIVER_FIREFOX_BIN = "webdriver.firefox.bin";
Expand All @@ -52,10 +56,13 @@ public final class ConfigKeys {

public static final String WEBDRIVER_URL = "webdriver.url";

@Deprecated
public static final String CONFIGURATION_PATHS = "configuration.paths";

@Deprecated
public static final String DEFAULT_PROPERTIES_NAME = "default.properties";

@Deprecated
public static final String JUNIT_RERUNS = "junit.reruns";

public static final String CONFIG_STRATEGY = "bobcat.config";
Expand All @@ -64,6 +71,12 @@ public final class ConfigKeys {
public static final String COOKIES_LOAD_AUTOMATICALLY = "cookies.loadAutomatically";
public static final String COOKIES_FILE = "cookies.file";

public static final String MODIFIERS_IMPLICIT_TIMEOUT = "modifiers.implicitTimeout";

public static final String TIMINGS_EXPLICIT_TIMEOUT = "timings.explicitTimeout";
public static final String TIMINGS_IMPLICIT_TIMEOUT = "timings.implicitTimeout";
public static final String TIMINGS_POLLING_INTERVAL = "timings.pollingInterval";

private ConfigKeys() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@

/**
* Class contains custom ExpectedConditions for explicit waiting (provided by BobcatWait)
*
* @deprecated to be removed in 2.0; use methods from {@link org.openqa.selenium.support.ui.ExpectedConditions} or {@link com.cognifide.qa.bb.webelement.WebElementConditions}
*/
@Deprecated
public final class CommonExpectedConditions {

private static final Logger LOG = LoggerFactory.getLogger(CommonExpectedConditions.class);
Expand All @@ -56,9 +59,9 @@ public static ExpectedCondition<Boolean> elementNotPresent(final By bySelector)
/**
* Check if element has attribute with provided value
*
* @param attributeName name of the attribute
* @param attributeName name of the attribute
* @param attributeValue value of the attribute
* @param element WebElement to check
* @param element WebElement to check
* @return true if element has attribute with provided value
*/
public static ExpectedCondition<Boolean> elementHasAttributeWithValue(final WebElement element,
Expand All @@ -71,7 +74,7 @@ public static ExpectedCondition<Boolean> elementHasAttributeWithValue(final WebE
* Check if element located by specified By locator exists in DOM in an
* element's context
*
* @param scope scope in which element will be searched for
* @param scope scope in which element will be searched for
* @param locator {@link By} locator of the searched element
* @return false if element does not exist or WebDriver is null
*/
Expand Down Expand Up @@ -102,7 +105,7 @@ public static ExpectedCondition<Boolean> elementNotPresentOrVisible(final By byS
/**
* Check if provided element height is greater than expected height
*
* @param element - WebElement to check
* @param element - WebElement to check
* @param expectedHeight - expected height of an element
* @return true if element height is greater than expected
*/
Expand All @@ -115,7 +118,7 @@ public static ExpectedCondition<Boolean> heightOfElementGreaterThan(final WebEle
* List of WebElements found in provided scope using provided locator is
* constant
*
* @param element WebElement to set scope for elements finder
* @param element WebElement to set scope for elements finder
* @param byElement By selector
* @return true if list of WebElements is the same after one second
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;

/**
* Class contains custom ExpectedConditions for testing current URL
*
* @deprecated use methods from {@link ExpectedConditions}
*/
@Deprecated
public final class UrlExpectedConditions {

private UrlExpectedConditions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@

/**
* This is an utility class that extends Selenium's wait functionality. If you need wait/until replacement,
* inject instance of this class into your PageObject. If you only need "sleep" function, call it directly
* from BobcatWait statically, because "sleep" is static.
* inject instance of this class into your PageObject.
* <p>
* This class serves as a factory for BobcatWebDriverWait instances.
*
* @deprecated moved under {@link com.cognifide.qa.bb.wait.BobcatWait}
*/
@Deprecated
public class BobcatWait {

private static final Logger LOG = LoggerFactory.getLogger(BobcatWait.class);
Expand All @@ -52,18 +54,9 @@ public class BobcatWait {
private WebDriverProvider webDriverProvider;

/**
* This is a wrapper method for Thread's sleep method.
* <p>
* It catches and logs InterruptedException thrown from original sleep method,
* so the user doesn't need to bother with writing a try-catch block.
* <p>
* Use this method only if you can't use "withTimeout" (which is more flexible).
* <p>
* If you don't use "withTimeout", call "sleep" directly from BobcatWait,
* without creating an instance.
*
* @param durationInSec Thread will sleep for durationInSec seconds.
* @deprecated it's 2018, don't use sleeps in your tests :)
*/
@Deprecated
public static void sleep(double durationInSec) {
try {
TimeUnit.MILLISECONDS.sleep((long) (durationInSec * 1000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
/**
* This class performs actual wait. It should always be used with BobcatWait class which acts as a factory for
* BobcatWebDriverWait.
*
* @deprecated will be removed in 2.0
*/
@Deprecated
public class BobcatWebDriverWait {

private static final int IMPLICITLY_WAIT_TIME = 1;
Expand Down Expand Up @@ -88,7 +91,8 @@ public <T> T until(ExpectedCondition<T> condition) {
*/
public <T> T until(ExpectedCondition<T> condition, long delay) {
webDriver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT_TIME, TimeUnit.SECONDS);
final T result = new WebDriverWait(webDriver, timeOutInSeconds, delay * 1000L).until(condition::apply);
final T result =
new WebDriverWait(webDriver, timeOutInSeconds, delay * 1000L).until(condition::apply);
webDriver.manage().timeouts().implicitlyWait(defaultTimeout, TimeUnit.SECONDS);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
public class ImplicitTimeoutModifier implements WebDriverModifier {

@Inject
@Named(ConfigKeys.WEBDRIVER_DEFAULT_TIMEOUT)
@Named(ConfigKeys.TIMINGS_IMPLICIT_TIMEOUT)
private int defaultTimeout;

@Inject
@Named(ConfigKeys.MODIFIERS_IMPLICIT_TIMEOUT)
private boolean enabled;

@Override
public boolean shouldModify() {
return true;
return enabled;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -25,6 +25,7 @@
import org.openqa.selenium.WebDriver;

import com.cognifide.qa.bb.guice.ThreadScoped;
import com.cognifide.qa.bb.wait.BobcatWait;
import com.google.inject.Inject;

/**
Expand All @@ -38,7 +39,7 @@ public final class BrowserTabsHelper {
private WebDriver webDriver;

@Inject
private WebElementUtils webElementUtils;
private BobcatWait bobcatWait;

/**
* Checks if expected tabs count is opened with timeout defined in
Expand All @@ -48,7 +49,7 @@ public final class BrowserTabsHelper {
* @return value indicating if expected tabs count is opened.
*/
public boolean isExpectedTabsCountOpened(int tabsCount) {
return webElementUtils.isConditionMet(driver -> getOpenedTabsCount() == tabsCount);
return bobcatWait.isConditionMet(driver -> getOpenedTabsCount() == tabsCount);
}

/**
Expand Down Expand Up @@ -77,8 +78,8 @@ public void switchToPreviousTab() {
}

/**
* Switches to the browser tab with specified index offset from active tab. If resulting index
* exceeds the index of first or last tab counting continues from another end.
* Switches to the browser tab with specified index offset from active tab. If resulting index
* exceeds the index of first or last tab counting continues from another end.
*
* @param tabOffset tab index offset from active tab.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
*/
package com.cognifide.qa.bb.utils;

import static org.openqa.selenium.support.ui.ExpectedConditions.not;
import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElement;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElements;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.*;

import java.util.ArrayDeque;
import java.util.Deque;
Expand All @@ -41,13 +37,17 @@
import com.cognifide.qa.bb.constants.Timeouts;
import com.cognifide.qa.bb.guice.ThreadScoped;
import com.cognifide.qa.bb.provider.selenium.BobcatWait;
import com.cognifide.qa.bb.webelement.WebElementConditions;
import com.google.inject.Inject;

/**
* This class contains utility methods for checking with waits if WebElements are meeting different
* conditions.
*
* @deprecated use {@link WebElementConditions} together with {@link com.cognifide.qa.bb.wait.BobcatWait}
*/
@ThreadScoped
@Deprecated
public final class WebElementUtils {

private static final Logger LOG = LoggerFactory.getLogger(WebElementUtils.class);
Expand Down
Loading

0 comments on commit ef63f2f

Please sign in to comment.