From a2fae134966193a758d6273e9724f54a66fa5545 Mon Sep 17 00:00:00 2001 From: knysh Date: Wed, 8 Jan 2020 17:19:06 +0300 Subject: [PATCH] #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 --- Documentation.en.md | 8 + Documentation.ru.md | 9 + README.md | 2 +- azure-pipelines.yml | 4 +- pom.xml | 2 +- .../selenium/waitings/ConditionalWait.java | 47 +++-- .../waitings/ConditionalWaitTests.java | 186 +++++++++++------- .../java/tests/integration/ActionTests.java | 2 +- .../tests/integration/ElementStateTests.java | 2 +- .../java/tests/integration/ElementTests.java | 2 +- .../ElementExistNotDisplayedTest.java | 2 +- .../tests/usecases/FileDownloadingTests.java | 10 +- .../forms/DynamicControlsForm.java | 2 +- 13 files changed, 176 insertions(+), 102 deletions(-) diff --git a/Documentation.en.md b/Documentation.en.md index ef66cfd..02bf288 100644 --- a/Documentation.en.md +++ b/Documentation.en.md @@ -39,6 +39,7 @@ The main benefits from using Aquality Selenium: - 5. FORMS - 6. JAVASCRIPT EXECUTION - 7. JSON FILE + - 8. CONDITIONAL WAIT ### 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 @@ -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 waitFor``` - uses the WebDriver's wait, returns a T object or an exception if the condition is not met. \ No newline at end of file diff --git a/Documentation.ru.md b/Documentation.ru.md index bf6b748..15ed876 100644 --- a/Documentation.ru.md +++ b/Documentation.ru.md @@ -40,6 +40,7 @@ Aquality Selenium является надстройкой над инструм - 5. FORMS - 6. JAVASCRIPT EXECUTION - 7. JSON FILE + - 8. CONDITIONAL WAIT ### 1. PLATFORM SUPPORT В настоящее время Aquality Selenium позволяет автоматизировать веб тесты для Chrome, Firefox, Safari, IExplorer, Edge. Также присутствуют возможности самостоятельно реализовать поддержку новых браузеров, которые поддерживаются Selenium (подробнее [здесь](https://www.seleniumhq.org/about/platforms.jsp)). @@ -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 waitFor - использует ожидание WebDriver'a, возвращает объект T или ошибку, в случае если условие не выполнилось. diff --git a/README.md b/README.md index fe3bdfb..297e9eb 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ We use interfaces where is possible, so you can implement your own version of ta com.github.aquality-automation aquality-selenium - 1.1.3 + 1.2.0 ``` diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1e7025e..0c5a3b0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,6 +13,8 @@ steps: organization: 'aqualityautomation' scannerMode: 'CLI' configMode: 'file' + extraProperties: | + sonar.coverage.exclusions=**/** - task: ScreenResolutionUtility@1 inputs: @@ -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 diff --git a/pom.xml b/pom.xml index 9a56269..170d58c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.aquality-automation aquality-selenium - 1.1.3 + 1.2.0 jar Aquality Selenium diff --git a/src/main/java/aquality/selenium/waitings/ConditionalWait.java b/src/main/java/aquality/selenium/waitings/ConditionalWait.java index 5f29482..474d89e 100644 --- a/src/main/java/aquality/selenium/waitings/ConditionalWait.java +++ b/src/main/java/aquality/selenium/waitings/ConditionalWait.java @@ -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); } /** @@ -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. @@ -104,7 +127,7 @@ public static T waitFor(ExpectedCondition 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 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 waitFor(ExpectedCondition condition, long timeOutInSeconds, long pollingIntervalInMilliseconds, String message, Collection> exceptionsToIgnore) { getBrowser().setImplicitWaitTimeout(0L); diff --git a/src/test/java/aquality/selenium/waitings/ConditionalWaitTests.java b/src/test/java/aquality/selenium/waitings/ConditionalWaitTests.java index 60b43cb..c166074 100644 --- a/src/test/java/aquality/selenium/waitings/ConditionalWaitTests.java +++ b/src/test/java/aquality/selenium/waitings/ConditionalWaitTests.java @@ -4,6 +4,7 @@ import aquality.selenium.configuration.Configuration; import aquality.selenium.configuration.ITimeoutConfiguration; import org.openqa.selenium.StaleElementReferenceException; +import org.testng.Assert; import org.testng.annotations.Test; import utils.DurationSample; import utils.Timer; @@ -21,76 +22,62 @@ public class ConditionalWaitTests { private static final double defaultDeviation = 7; @Test - public void testFalseShouldBeReturnedIfConditionIsNotMetAndDefaultTimeoutIsOver(){ - long timeoutCondition = getTimeoutConfig().getCondition(); - + public void testTimeoutExceptionShouldBeThrownIfConditionIsNotMetAndDefaultTimeoutIsOver() { Timer timer = new Timer(); - boolean result = ConditionalWait.waitForTrue(() -> + Assert.expectThrows(TimeoutException.class, () -> ConditionalWait.waitForTrue(() -> { timer.start(); return false; - }, "Condition should be true"); - DurationSample durationSample = new DurationSample(timer.duration(), timeoutCondition, defaultDeviation); - - assertFalse(result); + }, "Condition should be true")); + DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition(), defaultDeviation); assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); } @Test - public void testTimeoutExceptionShouldBeThrownIfConditionIsMetAndTimeoutIsOver(){ + public void testTimeoutExceptionShouldBeThrownIfConditionIsNotMetAndTimeoutIsOver() { Timer timer = new Timer(); - try { - ConditionalWait.waitForTrue(() -> - { - timer.start(); - return false; - }, waitForTimeoutCondition, waitForTimeoutPolling,"Condition should be true"); - } catch (TimeoutException e) { - DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition, defaultDeviation); - assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); - } + Assert.expectThrows(TimeoutException.class, () -> ConditionalWait.waitForTrue(() -> + { + timer.start(); + return false; + }, waitForTimeoutCondition, waitForTimeoutPolling, "Condition should be true")); + DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition, defaultDeviation); + assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); } @Test - public void testTimeoutExceptionShouldNotBeThrownIfConditionIsMetAndDefaultTimeoutIsNotOver(){ - long timeoutCondition = getTimeoutConfig().getCondition(); + public void testTimeoutExceptionShouldNotBeThrownIfConditionMetAndTimeoutIsNotOver() throws TimeoutException { Timer timer = new Timer(); - - boolean result = ConditionalWait.waitForTrue(() -> + ConditionalWait.waitForTrue(() -> { timer.start(); return true; - }, "Timeout exception should not be thrown"); - DurationSample durationSample = new DurationSample(timer.duration(), timeoutCondition); - - assertTrue(result); - assertTrue(durationSample.getDuration() < timeoutCondition); + }, waitForTimeoutCondition, waitForTimeoutPolling, "Timeout exception should not be thrown"); + DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition); + assertTrue(durationSample.getDuration() < waitForTimeoutCondition); } @Test - public void testTimeoutExceptionShouldNotBeThrownIfConditionMetAndTimeoutIsNotOver() throws TimeoutException { + public void testTimeoutExceptionShouldNotBeThrownIfConditionMetAndDefaultTimeoutIsNotOver() throws TimeoutException { Timer timer = new Timer(); - ConditionalWait.waitForTrue(() -> { timer.start(); return true; - }, waitForTimeoutCondition, waitForTimeoutPolling, "Timeout exception should not be thrown"); - DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition); - assertTrue(durationSample.getDuration() < waitForTimeoutCondition); + }, "Timeout exception should not be thrown"); + DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition()); + assertTrue(durationSample.getDuration() < getTimeoutConfig().getCondition()); } @Test(expectedExceptions = IllegalArgumentException.class) - public void testNullCannotBePassedAsCondition(){ + public void testNullCannotBePassedAsCondition() throws TimeoutException { ConditionalWait.waitForTrue(null, "Condition should not be null"); } @Test - public void testTimeoutExceptionShouldBeThrownIfDriverConditionIsNotMetAndDefaultTimeoutIsOver(){ - long timeoutCondition = getTimeoutConfig().getCondition(); + public void testTimeoutExceptionShouldBeThrownIfDriverConditionIsNotMetAndDefaultTimeoutIsOver() { Timer timer = new Timer(); - - try{ + try { ConditionalWait.waitFor((driver) -> { timer.start(); @@ -98,19 +85,18 @@ public void testTimeoutExceptionShouldBeThrownIfDriverConditionIsNotMetAndDefaul }, "Condition should be true"); - }catch (org.openqa.selenium.TimeoutException e){ - DurationSample durationSample = new DurationSample(timer.duration(), timeoutCondition, defaultDeviation); - BrowserManager.getBrowser().quit(); - + } catch (org.openqa.selenium.TimeoutException e) { + DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition(), defaultDeviation); assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); + } finally { + BrowserManager.getBrowser().quit(); } } @Test - public void testTimeoutExceptionShouldBeThrownIfDriverConditionIsNotMetAndTimeoutIsOver(){ + public void testTimeoutExceptionShouldBeThrownIfDriverConditionIsNotMetAndTimeoutIsOver() { Timer timer = new Timer(); - - try{ + try { ConditionalWait.waitFor((driver) -> { timer.start(); @@ -118,34 +104,34 @@ public void testTimeoutExceptionShouldBeThrownIfDriverConditionIsNotMetAndTimeou }, waitForTimeoutCondition, waitForTimeoutPolling, "Conditional should be true", Collections.singleton(StaleElementReferenceException.class)); - }catch (org.openqa.selenium.TimeoutException e){ + } catch (org.openqa.selenium.TimeoutException e) { DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition, defaultDeviation); - BrowserManager.getBrowser().quit(); - assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); + } finally { + BrowserManager.getBrowser().quit(); } } @Test - public void testTimeoutExceptionShouldNotBeThrownIfDriverConditionIsMetAndDefaultTimeoutIsNotOver(){ + public void testTimeoutExceptionShouldNotBeThrownIfDriverConditionIsMetAndDefaultTimeoutIsNotOver() { Timer timer = new Timer(); - - ConditionalWait.waitFor((driver) -> - { - timer.start(); - return true; - }, - "Conditional should be true"); - DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition); - BrowserManager.getBrowser().quit(); - - assertTrue(durationSample.getDuration() < getTimeoutConfig().getCondition()); + try { + ConditionalWait.waitFor((driver) -> + { + timer.start(); + return true; + }, + "Conditional should be true"); + DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition()); + assertTrue(durationSample.getDuration() < getTimeoutConfig().getCondition()); + } finally { + BrowserManager.getBrowser().quit(); + } } @Test - public void testExceptionShouldBeCatchedConditionIsMetAndDefaultTimeoutIsNotOver(){ + public void testExceptionShouldBeCaughtConditionIsMetAndDefaultTimeoutIsNotOver(){ Timer timer = new Timer(); - try{ ConditionalWait.waitFor((driver) -> { @@ -155,26 +141,80 @@ public void testExceptionShouldBeCatchedConditionIsMetAndDefaultTimeoutIsNotOver "Conditional should be true", Collections.singleton(IllegalArgumentException.class)); } catch (org.openqa.selenium.TimeoutException e){ DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition, defaultDeviation); - BrowserManager.getBrowser().quit(); - assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); + } finally { + BrowserManager.getBrowser().quit(); } } @Test - public void testTimeoutExceptionShouldNotBeThrownIfDriverConditionIsMetAndTimeoutIsNotOver(){ + public void testTimeoutExceptionShouldNotBeThrownIfDriverConditionIsMetAndTimeoutIsNotOver() { Timer timer = new Timer(); + try { + boolean conditionResult = ConditionalWait.waitFor((driver) -> + { + timer.start(); + return true; + }, waitForTimeoutCondition, waitForTimeoutPolling, + "Conditional should be true", Collections.singleton(IllegalArgumentException.class)); + DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition); + assertTrue(durationSample.getDuration() < waitForTimeoutCondition); + assertTrue(conditionResult, "Condition result should be true"); + } finally { + BrowserManager.getBrowser().quit(); + } + } - ConditionalWait.waitFor((driver) -> - { - timer.start(); - return true; - }, waitForTimeoutCondition, waitForTimeoutPolling, - "Conditional should be true", Collections.singleton(IllegalArgumentException.class)); + @Test + public void testTrueShouldNotBeReturnedIfConditionIsMetAndTimeoutIsNotOver(){ + Timer timer = new Timer(); + boolean conditionResult = ConditionalWait.waitFor(() -> + { + timer.start(); + return true; + }, waitForTimeoutCondition, waitForTimeoutPolling, "Timeout exception should not be thrown"); DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition); - BrowserManager.getBrowser().quit(); - assertTrue(durationSample.getDuration() < waitForTimeoutCondition); + assertTrue(conditionResult, "Condition result should be true"); + } + + @Test + public void testFalseShouldBeReturnedIfConditionIsNotMetAndTimeoutIsOver(){ + Timer timer = new Timer(); + boolean conditionResult = ConditionalWait.waitFor(() -> + { + timer.start(); + return false; + }, waitForTimeoutCondition, waitForTimeoutPolling, "Timeout exception should not be thrown"); + DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition, defaultDeviation); + assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); + assertFalse(conditionResult, "Condition result should be false"); + } + + @Test + public void testTrueShouldBeReturnedIfConditionIsMetAndDefaultTimeoutIsNotOver(){ + Timer timer = new Timer(); + boolean conditionResult = ConditionalWait.waitFor(() -> + { + timer.start(); + return true; + }, "Timeout exception should not be thrown"); + DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition()); + assertTrue(durationSample.getDuration() < getTimeoutConfig().getCondition()); + assertTrue(conditionResult, "Condition result should be true"); + } + + @Test + public void testFalseShouldBeReturnedIfConditionIsNotMetAndDefaultTimeoutIsOver(){ + Timer timer = new Timer(); + boolean conditionResult = ConditionalWait.waitFor(() -> + { + timer.start(); + return false; + }, "Timeout exception should not be thrown"); + DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition(), defaultDeviation); + assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); + assertFalse(conditionResult, "Condition result should be false"); } private ITimeoutConfiguration getTimeoutConfig(){ diff --git a/src/test/java/tests/integration/ActionTests.java b/src/test/java/tests/integration/ActionTests.java index 3e5cb2a..426cb84 100644 --- a/src/test/java/tests/integration/ActionTests.java +++ b/src/test/java/tests/integration/ActionTests.java @@ -52,7 +52,7 @@ public void testMoveMouseToElement() { public void testMoveMouseFromElement() { ProductListForm productListForm = new ProductListForm(); - Assert.assertTrue(ConditionalWait.waitForTrue(() -> { + Assert.assertTrue(ConditionalWait.waitFor(() -> { IButton button = productListForm.getBtnLastProductMoreFocused(); return button.getText().contains("More"); }, "element is not focused after moveMouseToElement()")); diff --git a/src/test/java/tests/integration/ElementStateTests.java b/src/test/java/tests/integration/ElementStateTests.java index 5817582..904ca2b 100644 --- a/src/test/java/tests/integration/ElementStateTests.java +++ b/src/test/java/tests/integration/ElementStateTests.java @@ -127,7 +127,7 @@ public void testShouldBePossibleToWaitElementNotExistsCustom(){ boolean isMissed = dynamicControlsForm.getChbACheckbox().state().waitForNotExist(waitTime); DurationSample durationSample = new DurationSample(timer.duration(), waitTime, customDeviation); - Assert.assertFalse(isMissed); + Assert.assertTrue(isMissed); Assert.assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString()); } diff --git a/src/test/java/tests/integration/ElementTests.java b/src/test/java/tests/integration/ElementTests.java index 720694f..0e956d8 100644 --- a/src/test/java/tests/integration/ElementTests.java +++ b/src/test/java/tests/integration/ElementTests.java @@ -143,7 +143,7 @@ public void testTextBox() { txbPass.submit(); String expectedValue = ""; - boolean result = ConditionalWait.waitFor(webDriver -> txbPass.getValue().equalsIgnoreCase(expectedValue), "Value of textbox should be equal " + expectedValue); + boolean result = ConditionalWait.waitFor(() -> txbPass.getValue().equalsIgnoreCase(expectedValue), "Value of textbox should be equal " + expectedValue); softAssert.assertTrue(result); softAssert.assertAll(); } diff --git a/src/test/java/tests/usecases/ElementExistNotDisplayedTest.java b/src/test/java/tests/usecases/ElementExistNotDisplayedTest.java index 30a001b..7e46622 100644 --- a/src/test/java/tests/usecases/ElementExistNotDisplayedTest.java +++ b/src/test/java/tests/usecases/ElementExistNotDisplayedTest.java @@ -23,6 +23,6 @@ public void beforeMethod() { @Test public void testElementExistNotDisplayed() { IButton button = new SliderForm().getBtnAddToCart(ElementState.EXISTS_IN_ANY_STATE); - Assert.assertTrue(ConditionalWait.waitFor(driver -> button.state().isExist() && !button.state().isDisplayed(), "Button should exists in the DOM but should not be displayed ")); + Assert.assertTrue(ConditionalWait.waitFor(() -> button.state().isExist() && !button.state().isDisplayed(), "Button should exists in the DOM but should not be displayed ")); } } diff --git a/src/test/java/tests/usecases/FileDownloadingTests.java b/src/test/java/tests/usecases/FileDownloadingTests.java index cf10183..d98f45e 100644 --- a/src/test/java/tests/usecases/FileDownloadingTests.java +++ b/src/test/java/tests/usecases/FileDownloadingTests.java @@ -4,8 +4,6 @@ import aquality.selenium.elements.interfaces.ILabel; import aquality.selenium.waitings.ConditionalWait; import org.openqa.selenium.By; -import org.openqa.selenium.TimeoutException; -import org.openqa.selenium.support.ui.ExpectedCondition; import org.testng.Assert; import org.testng.annotations.Test; import tests.BaseTest; @@ -38,12 +36,6 @@ public void testDownloading() { downloaderForm.getLnkDownload(fileName).getJsActions().clickAndWait(); BrowserManager.getBrowser().getDriver().switchTo().window(tabs.get(0)); - ExpectedCondition fileDownloadedExpectedCondition = webDriver -> FileUtil.isFileDownloaded(fileAddress, lblFileContent); - try { - ConditionalWait.waitFor(fileDownloadedExpectedCondition, String.format("File %1$s should be downloaded", fileAddress)); - } catch (TimeoutException e) { - BrowserManager.getBrowser().quit(); - ConditionalWait.waitFor(fileDownloadedExpectedCondition, String.format("File %1$s should be downloaded", fileAddress)); - } + Assert.assertTrue(ConditionalWait.waitFor(() -> FileUtil.isFileDownloaded(fileAddress, lblFileContent), String.format("File %1$s should be downloaded", fileAddress))); } } \ No newline at end of file diff --git a/src/test/java/theinternet/forms/DynamicControlsForm.java b/src/test/java/theinternet/forms/DynamicControlsForm.java index c56405d..cd65170 100644 --- a/src/test/java/theinternet/forms/DynamicControlsForm.java +++ b/src/test/java/theinternet/forms/DynamicControlsForm.java @@ -12,7 +12,7 @@ public class DynamicControlsForm extends Form { private final IButton btnEnable = getElementFactory().getButton(By.xpath("//button[contains(@onclick, 'swapInput()')][contains(.,'Enable')]"), "Enable"); private final IButton btnDisable = getElementFactory().getButton(By.xpath("//button[contains(@onclick, 'swapInput()')][contains(.,'Disable')]"), "Disable"); private final IButton btnRemove = getElementFactory().getButton(By.xpath("//button[contains(@onclick, 'swapCheckbox()')]"), "Remove"); - private final ICheckBox chbACheckbox = getElementFactory().getCheckBox(By.xpath("//div[@id='checkbox']"), "A Checkbox"); + private final ICheckBox chbACheckbox = getElementFactory().getCheckBox(By.xpath("//input[@id='checkbox']"), "A Checkbox"); public DynamicControlsForm() { super(By.id("content"), "Dynamic Controls");