Skip to content

Commit

Permalink
#70 updated ConditionalWait methods signature. (#71)
Browse files Browse the repository at this point in the history
* #70 updated ConditionalWait methods signature.
Added waitFor method which return true or false
* #70 changed browser version to latest
* #70 added documentation, increased version, fixed test names
* #70 excluded sonar coverage check from pipeline
* #70 fixed dynamic controls from and related tests
* #70 updated version in readme
  • Loading branch information
knysh authored and DmitryBogatko committed Jan 8, 2020
1 parent 34b1995 commit a2fae13
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 102 deletions.
8 changes: 8 additions & 0 deletions Documentation.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The main benefits from using Aquality Selenium:
- <a href='#5-forms'>5. FORMS</a>
- <a href='#6-javascript-execution'>6. JAVASCRIPT EXECUTION</a>
- <a href='#7-json-file'>7. JSON FILE</a>
- <a href='#8-conditional-wait'>8. CONDITIONAL WAIT</a>

### 1. PLATFORM SUPPORT
At the moment Aquality Selenium allows to automate web tests for Chrome, Firefox, Safari, IExplorer and Edge. Also you can implement support of new browsers that Selenium supports
Expand Down Expand Up @@ -346,3 +347,10 @@ For example, if user wants to keep URL to web site that is automating he can put
JsonFile environment = new JsonFile("settings.json")
String url = environment.getValue("/url").toString();
```
### **8. CONDITIONAL WAIT**

If you need to wait for any condition to be met, you can use the [ConditionalWait](./src/main/java/aquality/selenium/waitings/ConditionalWait.java) class provided by Aquality Selenium.
All class methods wait for the condition to be met, but return values and handle exceptions ​​differently:
1. ```waitForTrue``` - throws an exception if the condition is not met, returns nothing.
2. ```boolean waitFor``` - returns true if the condition is fulfilled or false otherwise. Method does not throw any exception.
3. ```<T> T waitFor``` - uses the WebDriver's wait, returns a T object or an exception if the condition is not met.
9 changes: 9 additions & 0 deletions Documentation.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Aquality Selenium является надстройкой над инструм
- <a href='#5-forms'>5. FORMS</a>
- <a href='#6-javascript-execution'>6. JAVASCRIPT EXECUTION</a>
- <a href='#7-json-file'>7. JSON FILE</a>
- <a href='#8-conditional-wait'>8. CONDITIONAL WAIT</a>

### 1. PLATFORM SUPPORT
В настоящее время Aquality Selenium позволяет автоматизировать веб тесты для Chrome, Firefox, Safari, IExplorer, Edge. Также присутствуют возможности самостоятельно реализовать поддержку новых браузеров, которые поддерживаются Selenium (подробнее [здесь](https://www.seleniumhq.org/about/platforms.jsp)).
Expand Down Expand Up @@ -318,3 +319,11 @@ Aquality Selenium использует для своей работы и пре
JsonFile environment = new JsonFile("settings.json")
String url = environment.getValue("/url").toString();
```

### **8. CONDITIONAL WAIT**

В случае необходимости ожидания выполнения какого-либо условия можно воспользоваться предоставляемым в Aquality Selenium классом [ConditionalWait](./src/main/java/aquality/selenium/waitings/ConditionalWait.java).
Все методы класса ждут выполнения условия, но по разному возвращают значения и обрабатывают ошибки:
1. waitForTrue - выкидывает ошибку в случае, если условие не выполнилось, ничего не возвращает.
2. boolean waitFor - возвращает true если условие выполнилось или false если не выполнилось, ошибок не выбрасывает.
3. <T> T waitFor - использует ожидание WebDriver'a, возвращает объект T или ошибку, в случае если условие не выполнилось.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We use interfaces where is possible, so you can implement your own version of ta
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium</artifactId>
<version>1.1.3</version>
<version>1.2.0</version>
</dependency>
```

Expand Down
4 changes: 3 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ steps:
organization: 'aqualityautomation'
scannerMode: 'CLI'
configMode: 'file'
extraProperties: |
sonar.coverage.exclusions=**/**
- task: ScreenResolutionUtility@1
inputs:
Expand All @@ -27,7 +29,7 @@ steps:
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean test -DdriverSettings.chrome.webDriverVersion=75.0.3770.140 -Dprofile=local'
goals: 'clean test -Dprofile=local'

- task: SonarCloudAnalyze@1

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium</artifactId>
<version>1.1.3</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>Aquality Selenium</name>
Expand Down
47 changes: 35 additions & 12 deletions src/main/java/aquality/selenium/waitings/ConditionalWait.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,10 @@ private ConditionalWait() {
* Default values for timeouts used from configuration settings file
* @param condition condition with boolean result (predicate)
* @param message Part of error message in case of Timeout exception
* @return true if the condition has been met during the timeout
* @throws TimeoutException will be thrown in case if timeout is over but condition was not met
*/
public static boolean waitForTrue(BooleanSupplier condition, String message)
{
try
{
waitForTrue(condition, getTimeoutConfiguration().getCondition(), getTimeoutConfiguration().getPollingInterval(), message);
return true;
}
catch (TimeoutException e) {
return false;
}
public static void waitForTrue(BooleanSupplier condition, String message) throws TimeoutException {
waitForTrue(condition, getTimeoutConfiguration().getCondition(), getTimeoutConfiguration().getPollingInterval(), message);
}

/**
Expand Down Expand Up @@ -78,6 +70,37 @@ public static void waitForTrue(BooleanSupplier condition, long timeoutInSeconds,
}
}

/**
* Waits for function will be true or return false. Method does not use WebDriverWait.
* Default timeout condition from settings is using.
* @param condition condition with boolean result (predicate).
* @param message Part of error message in case of Timeout exception.
* @return true if condition is satisfied, false otherwise.
*/
public static boolean waitFor(BooleanSupplier condition, String message) {
return waitFor(condition,
getTimeoutConfiguration().getCondition(),
getTimeoutConfiguration().getPollingInterval(),
message);
}

/**
* Waits for function will be true or return false. Method does not use WebDriverWait.
* @param condition condition with boolean result (predicate)
* @param timeOutInSeconds Condition timeout
* @param pollingIntervalInMilliseconds Condition check interval
* @param message Part of error message in case of Timeout exception
* @return true if condition is satisfied, false otherwise.
*/
public static boolean waitFor(BooleanSupplier condition, long timeOutInSeconds, long pollingIntervalInMilliseconds, String message) {
try {
waitForTrue(condition, timeOutInSeconds, pollingIntervalInMilliseconds, message);
return true;
}catch (TimeoutException e){
return false;
}
}

/**
* Waits for function will be true or return some except false.
* Default timeout condition from settings is using.
Expand All @@ -104,7 +127,7 @@ public static <T> T waitFor(ExpectedCondition<T> condition, String message) {
* @param message the message that will be added to an error in case if the condition is not matched during the timeout
* @param exceptionsToIgnore list of exceptions that should be ignored during waiting
* @param <T> Type of object which is waiting
* @return Object which waiting for or null - is exceptions occured
* @return Object which waiting for or null - is exceptions occurred
*/
public static <T> T waitFor(ExpectedCondition<T> condition, long timeOutInSeconds, long pollingIntervalInMilliseconds, String message, Collection<Class<? extends Throwable>> exceptionsToIgnore) {
getBrowser().setImplicitWaitTimeout(0L);
Expand Down
Loading

0 comments on commit a2fae13

Please sign in to comment.