Skip to content

Commit a2fae13

Browse files
knyshDmitryBogatko
authored andcommitted
#70 updated ConditionalWait methods signature. (#71)
* #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
1 parent 34b1995 commit a2fae13

File tree

13 files changed

+176
-102
lines changed

13 files changed

+176
-102
lines changed

Documentation.en.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The main benefits from using Aquality Selenium:
3939
- <a href='#5-forms'>5. FORMS</a>
4040
- <a href='#6-javascript-execution'>6. JAVASCRIPT EXECUTION</a>
4141
- <a href='#7-json-file'>7. JSON FILE</a>
42+
- <a href='#8-conditional-wait'>8. CONDITIONAL WAIT</a>
4243

4344
### 1. PLATFORM SUPPORT
4445
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
@@ -346,3 +347,10 @@ For example, if user wants to keep URL to web site that is automating he can put
346347
JsonFile environment = new JsonFile("settings.json")
347348
String url = environment.getValue("/url").toString();
348349
```
350+
### **8. CONDITIONAL WAIT**
351+
352+
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.
353+
All class methods wait for the condition to be met, but return values and handle exceptions ​​differently:
354+
1. ```waitForTrue``` - throws an exception if the condition is not met, returns nothing.
355+
2. ```boolean waitFor``` - returns true if the condition is fulfilled or false otherwise. Method does not throw any exception.
356+
3. ```<T> T waitFor``` - uses the WebDriver's wait, returns a T object or an exception if the condition is not met.

Documentation.ru.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Aquality Selenium является надстройкой над инструм
4040
- <a href='#5-forms'>5. FORMS</a>
4141
- <a href='#6-javascript-execution'>6. JAVASCRIPT EXECUTION</a>
4242
- <a href='#7-json-file'>7. JSON FILE</a>
43+
- <a href='#8-conditional-wait'>8. CONDITIONAL WAIT</a>
4344

4445
### 1. PLATFORM SUPPORT
4546
В настоящее время Aquality Selenium позволяет автоматизировать веб тесты для Chrome, Firefox, Safari, IExplorer, Edge. Также присутствуют возможности самостоятельно реализовать поддержку новых браузеров, которые поддерживаются Selenium (подробнее [здесь](https://www.seleniumhq.org/about/platforms.jsp)).
@@ -318,3 +319,11 @@ Aquality Selenium использует для своей работы и пре
318319
JsonFile environment = new JsonFile("settings.json")
319320
String url = environment.getValue("/url").toString();
320321
```
322+
323+
### **8. CONDITIONAL WAIT**
324+
325+
В случае необходимости ожидания выполнения какого-либо условия можно воспользоваться предоставляемым в Aquality Selenium классом [ConditionalWait](./src/main/java/aquality/selenium/waitings/ConditionalWait.java).
326+
Все методы класса ждут выполнения условия, но по разному возвращают значения и обрабатывают ошибки:
327+
1. waitForTrue - выкидывает ошибку в случае, если условие не выполнилось, ничего не возвращает.
328+
2. boolean waitFor - возвращает true если условие выполнилось или false если не выполнилось, ошибок не выбрасывает.
329+
3. <T> T waitFor - использует ожидание WebDriver'a, возвращает объект T или ошибку, в случае если условие не выполнилось.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ We use interfaces where is possible, so you can implement your own version of ta
1818
<dependency>
1919
<groupId>com.github.aquality-automation</groupId>
2020
<artifactId>aquality-selenium</artifactId>
21-
<version>1.1.3</version>
21+
<version>1.2.0</version>
2222
</dependency>
2323
```
2424

azure-pipelines.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ steps:
1313
organization: 'aqualityautomation'
1414
scannerMode: 'CLI'
1515
configMode: 'file'
16+
extraProperties: |
17+
sonar.coverage.exclusions=**/**
1618
1719
- task: ScreenResolutionUtility@1
1820
inputs:
@@ -27,7 +29,7 @@ steps:
2729
jdkArchitectureOption: 'x64'
2830
publishJUnitResults: true
2931
testResultsFiles: '**/surefire-reports/TEST-*.xml'
30-
goals: 'clean test -DdriverSettings.chrome.webDriverVersion=75.0.3770.140 -Dprofile=local'
32+
goals: 'clean test -Dprofile=local'
3133

3234
- task: SonarCloudAnalyze@1
3335

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.aquality-automation</groupId>
88
<artifactId>aquality-selenium</artifactId>
9-
<version>1.1.3</version>
9+
<version>1.2.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Aquality Selenium</name>

src/main/java/aquality/selenium/waitings/ConditionalWait.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,10 @@ private ConditionalWait() {
2727
* Default values for timeouts used from configuration settings file
2828
* @param condition condition with boolean result (predicate)
2929
* @param message Part of error message in case of Timeout exception
30-
* @return true if the condition has been met during the timeout
30+
* @throws TimeoutException will be thrown in case if timeout is over but condition was not met
3131
*/
32-
public static boolean waitForTrue(BooleanSupplier condition, String message)
33-
{
34-
try
35-
{
36-
waitForTrue(condition, getTimeoutConfiguration().getCondition(), getTimeoutConfiguration().getPollingInterval(), message);
37-
return true;
38-
}
39-
catch (TimeoutException e) {
40-
return false;
41-
}
32+
public static void waitForTrue(BooleanSupplier condition, String message) throws TimeoutException {
33+
waitForTrue(condition, getTimeoutConfiguration().getCondition(), getTimeoutConfiguration().getPollingInterval(), message);
4234
}
4335

4436
/**
@@ -78,6 +70,37 @@ public static void waitForTrue(BooleanSupplier condition, long timeoutInSeconds,
7870
}
7971
}
8072

73+
/**
74+
* Waits for function will be true or return false. Method does not use WebDriverWait.
75+
* Default timeout condition from settings is using.
76+
* @param condition condition with boolean result (predicate).
77+
* @param message Part of error message in case of Timeout exception.
78+
* @return true if condition is satisfied, false otherwise.
79+
*/
80+
public static boolean waitFor(BooleanSupplier condition, String message) {
81+
return waitFor(condition,
82+
getTimeoutConfiguration().getCondition(),
83+
getTimeoutConfiguration().getPollingInterval(),
84+
message);
85+
}
86+
87+
/**
88+
* Waits for function will be true or return false. Method does not use WebDriverWait.
89+
* @param condition condition with boolean result (predicate)
90+
* @param timeOutInSeconds Condition timeout
91+
* @param pollingIntervalInMilliseconds Condition check interval
92+
* @param message Part of error message in case of Timeout exception
93+
* @return true if condition is satisfied, false otherwise.
94+
*/
95+
public static boolean waitFor(BooleanSupplier condition, long timeOutInSeconds, long pollingIntervalInMilliseconds, String message) {
96+
try {
97+
waitForTrue(condition, timeOutInSeconds, pollingIntervalInMilliseconds, message);
98+
return true;
99+
}catch (TimeoutException e){
100+
return false;
101+
}
102+
}
103+
81104
/**
82105
* Waits for function will be true or return some except false.
83106
* Default timeout condition from settings is using.
@@ -104,7 +127,7 @@ public static <T> T waitFor(ExpectedCondition<T> condition, String message) {
104127
* @param message the message that will be added to an error in case if the condition is not matched during the timeout
105128
* @param exceptionsToIgnore list of exceptions that should be ignored during waiting
106129
* @param <T> Type of object which is waiting
107-
* @return Object which waiting for or null - is exceptions occured
130+
* @return Object which waiting for or null - is exceptions occurred
108131
*/
109132
public static <T> T waitFor(ExpectedCondition<T> condition, long timeOutInSeconds, long pollingIntervalInMilliseconds, String message, Collection<Class<? extends Throwable>> exceptionsToIgnore) {
110133
getBrowser().setImplicitWaitTimeout(0L);

0 commit comments

Comments
 (0)