From bdc2b2c5bf226d49a5a42f3a3d952a214ce0d9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Wed, 7 Sep 2022 16:41:21 +0200 Subject: [PATCH 1/9] Fixed custom failure message at assertions --- docs/src/docs/migration.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/docs/migration.adoc b/docs/src/docs/migration.adoc index c2df52ed5..58986651a 100644 --- a/docs/src/docs/migration.adoc +++ b/docs/src/docs/migration.adoc @@ -266,7 +266,7 @@ uiElement.expect().text() Custom failure messages ```java -uiElement.expect().displayed(true, "Element is displayed"); +uiElement.expect().displayed().is(true, "Element is displayed"); ``` === Page assertions From 566a008e329609e773cfeb1505138fc507ccfd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Thu, 8 Sep 2022 09:33:39 +0200 Subject: [PATCH 2/9] Added custom assertion message --- .../guielement/guielement-assertions.adoc | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/src/docs/guielement/guielement-assertions.adoc b/docs/src/docs/guielement/guielement-assertions.adoc index f52244794..4907b60b7 100644 --- a/docs/src/docs/guielement/guielement-assertions.adoc +++ b/docs/src/docs/guielement/guielement-assertions.adoc @@ -4,6 +4,8 @@ UiElements provide many kinds of assertion methods to verify your elements. If an assertion fails, it will make the whole test fail and abort. You can control that by using a <> +== Default assertions + [source,java] ---- UiElement element = find(By.id("button")); @@ -59,3 +61,32 @@ image1.expect().bounds().fromBottom().toBottomOf(image3).is(0); // Assertions are false image1.expect().bounds().fromBottom().toBottomOf(image2).is(0); ---- + +== Custom assertion message + +Testerra generates a readable assertion message with name of UiElement, page and checked attribute. + +.Example of a page and a test method +[source,java] +---- +public class DragAndDropPage extends Page { + ... + private UiElement columnA = find(By.id("column-a")); + + public TestableUiElement getColumnA() { + return this.columnA; + } +} +... +public MyTest extends TesterraTest implements PageFactoryProvider { + @Test + public void myTest() { + DragAndDropPage page = PAGE_FACTORY.createPage(DragAndDropPage.class); + page.getColumnA().expect().displayed().is(false); <1> + page.getColumnB().expect().displayed().is(false, "Foo"); <2> + } +} +---- + +<1> Error message: `UiElementAssertionError: Expected that DragAndDropPage -> columnB displayed is false` +<2> Error message: `UiElementAssertionError: Expected that Foo is false` From 6529f3e69f47300fa61d78b8c86a416814c815e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Thu, 8 Sep 2022 09:45:28 +0200 Subject: [PATCH 3/9] Improved UiElement assertion chapter --- docs/src/docs/guielement.adoc | 1 - .../guielement/guielement-assertions.adoc | 43 ++++++++++++++++++- .../docs/guielement/guielement-checks.adoc | 37 ---------------- 3 files changed, 41 insertions(+), 40 deletions(-) delete mode 100644 docs/src/docs/guielement/guielement-checks.adoc diff --git a/docs/src/docs/guielement.adoc b/docs/src/docs/guielement.adoc index 3c15fcc56..d0b2323b1 100644 --- a/docs/src/docs/guielement.adoc +++ b/docs/src/docs/guielement.adoc @@ -10,7 +10,6 @@ UiElements are *self refreshing*: Every action on it will trigger a find call, s include::guielement/guielement-creation.adoc[leveloffset=+1] include::guielement/xpath-builder.adoc[leveloffset=+1] -include::guielement/guielement-checks.adoc[leveloffset=+1] include::guielement/guielement-assertions.adoc[leveloffset=+1] include::guielement/guielement-actions.adoc[leveloffset=+1] include::guielement/guielement-waiters.adoc[leveloffset=+1] diff --git a/docs/src/docs/guielement/guielement-assertions.adoc b/docs/src/docs/guielement/guielement-assertions.adoc index 4907b60b7..24ff68e01 100644 --- a/docs/src/docs/guielement/guielement-assertions.adoc +++ b/docs/src/docs/guielement/guielement-assertions.adoc @@ -2,9 +2,48 @@ UiElements provide many kinds of assertion methods to verify your elements. -If an assertion fails, it will make the whole test fail and abort. You can control that by using a <> +If an assertion fails, it will make the whole test fail and abort. You can control that by using a <> -== Default assertions +== UiElement checks + +Checks are assertions which verify the condition of an UiElement. + +Checks if the element is present in the DOM +[source,java] +---- +element.expect().present(boolean); +---- + +Checks if the element is present in the Viewport, +if it is visible by it's `display` and `visibility` style properties and if it's `width` and `height` are both greater than 0. +[source,java] +---- +element.expect().displayed(boolean); +---- + +Checks if the element is displayed and if it's partially or fully visible +in the scroll area of the viewport. + +[source,java] +---- +element.expect().visible(boolean fullyVisible).is(boolean); +---- + +NOTE: It doesn't relate to `opacity` or `z-index` style properties. If you need to test the perceptually visibility to the human eye, you should consider to implement an image based <>. + +Some more WebElement checks + +[source,java] +---- +// The following methods are calling the standard webelement method +element.expect().enabled(boolean); +element.expect().selected(boolean); + +// Tries to find out if an element could be selected. +element.expect().selectable(boolean); +---- + +== Assertions of UiElement attributes [source,java] ---- diff --git a/docs/src/docs/guielement/guielement-checks.adoc b/docs/src/docs/guielement/guielement-checks.adoc deleted file mode 100644 index 69d8d5cda..000000000 --- a/docs/src/docs/guielement/guielement-checks.adoc +++ /dev/null @@ -1,37 +0,0 @@ -= Checks - -Checks if the element is present in the DOM -[source,java] ----- -element.expect().present(boolean); ----- - -Checks if the element is present in the Viewport, -if it is visible by it's `display` and `visibility` style properties -and if it's `width` and `height` are both greater than 0. -[source,java] ----- -element.expect().displayed(boolean); ----- - -Checks if the element is displayed and if it's partially or fully visible -in the scroll area of the viewport. - -[source,java] ----- -element.expect().visible(boolean fullyVisible).is(boolean); ----- - -NOTE: It doesn't relate to `opacity` or `z-index` style properties. If you need to test the perceptually visibility to the human eye, you should consider to implement an image based <>. - -== Standard WebElement checks - -[source,java] ----- -// The following methods are calling the standard webelement method -element.expect().enabled(boolean); -element.expect().selected(boolean); - -// Tries to find out if an element could be selected. -element.expect().selectable(boolean); ----- From 19561c1bbfe0f2a7750b36827113011788b980d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Thu, 8 Sep 2022 09:52:47 +0200 Subject: [PATCH 4/9] Improved pageobject chapter --- docs/src/docs/pageobject/pageobjects-overview.adoc | 7 ++----- integration-tests/src/test/resources/test.properties | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/src/docs/pageobject/pageobjects-overview.adoc b/docs/src/docs/pageobject/pageobjects-overview.adoc index 44cd21c2b..5f67b769a 100644 --- a/docs/src/docs/pageobject/pageobjects-overview.adoc +++ b/docs/src/docs/pageobject/pageobjects-overview.adoc @@ -38,12 +38,10 @@ The annotation `Check` marks the UiElements as mandatory for the page. Testerra public class SearchPage extends Page { @Check - private final UiElement searchButton = - find(By.name("searchButton")); + private final UiElement searchButton = find(By.name("searchButton")); @Check - private final UiElement inputField = - find(By.name("inputField")); + private final UiElement inputField = find(By.name("inputField")); // constructor public SearchPage(WebDriver driver) { @@ -67,7 +65,6 @@ public class TestClass extends TesterraTest implements PageFactoryProvider { @Test public void myTest() { - WebDriver driver = WebDriverManager.getWebDriver(); HomePage homePage = PAGE_FACTORY.createPage(HomePage.class); SearchPage searchPage = homePage.openSearch(); ResultPage resultPage = searchPage.search("search text"); diff --git a/integration-tests/src/test/resources/test.properties b/integration-tests/src/test/resources/test.properties index 1e5a02216..15eb13049 100644 --- a/integration-tests/src/test/resources/test.properties +++ b/integration-tests/src/test/resources/test.properties @@ -1,5 +1,5 @@ -tt.browser=chromeHeadless -#tt.browser=chrome +#tt.browser=chromeHeadless +tt.browser=chrome #tt.browser=firefox tt.browser.maximize=false #tt.browser.maximize=true From efa5ce2e5a0c24ac2e8b26a305e43fb50d8083c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Thu, 8 Sep 2022 11:22:04 +0200 Subject: [PATCH 5/9] Added snippet to get current WebDriverRequest --- .../webdrivermanager/webdrivermanager-config.adoc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/src/docs/webdrivermanager/webdrivermanager-config.adoc b/docs/src/docs/webdrivermanager/webdrivermanager-config.adoc index b40dcd9e4..f2669c0dc 100644 --- a/docs/src/docs/webdrivermanager/webdrivermanager-config.adoc +++ b/docs/src/docs/webdrivermanager/webdrivermanager-config.adoc @@ -36,6 +36,17 @@ myRequest.setWindowSize(new Dimension(2560,1440)); WebDriver driver = WEB_DRIVER_MANAGER.getWebDriver(myRequest); ---- +Via the `SessionContext` you can get the current configuration of a WebDriver session: + +[source,java] +---- +Optional sessionContext = WEB_DRIVER_MANAGER.getSessionContext(webDriver); +// In case of a desktop browser you can cast to 'DesktopWebDriverRequest' +// Be careful if you are using Appium Connector! +DesktopWebDriverRequest webDriverRequest + = (DesktopWebDriverRequest) sessionContext.get().getWebDriverRequest(); +---- + == Configure with WebDriverManagerConfig (`@deprecated`) Since this `WebDriverManagerConfig` is actually a `DesktopWebDriverRequest`, you should prefer using that when creating a new WebDriver. From a632958fb6bd95c460c4b279cfc29d3a88b7657a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Thu, 8 Sep 2022 11:26:44 +0200 Subject: [PATCH 6/9] Reverted default configuration --- integration-tests/src/test/resources/test.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/src/test/resources/test.properties b/integration-tests/src/test/resources/test.properties index 15eb13049..1e5a02216 100644 --- a/integration-tests/src/test/resources/test.properties +++ b/integration-tests/src/test/resources/test.properties @@ -1,5 +1,5 @@ -#tt.browser=chromeHeadless -tt.browser=chrome +tt.browser=chromeHeadless +#tt.browser=chrome #tt.browser=firefox tt.browser.maximize=false #tt.browser.maximize=true From 7475e7f6591f1de7099a101b00516b1ed5d10611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Thu, 15 Sep 2022 15:09:22 +0200 Subject: [PATCH 7/9] Fixed migration guide --- docs/src/docs/migration.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/docs/migration.adoc b/docs/src/docs/migration.adoc index 58986651a..f76ad6337 100644 --- a/docs/src/docs/migration.adoc +++ b/docs/src/docs/migration.adoc @@ -501,7 +501,7 @@ public void test_TestSomething_fast() { ``` [NOTE] -.Setting timeouts using static `POConfig` is now `@deprecated` +.Setting timeouts using static `POConfig` was removed! ==== ```java POConfig.setThreadLocalUiElementTimeoutInSeconds(1); From 4daef3cbfa8f2c29eaac13491826ea93ef553d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Fri, 16 Sep 2022 09:30:34 +0200 Subject: [PATCH 8/9] Fixed Testerra migration example --- docs/src/docs/migration.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/docs/migration.adoc b/docs/src/docs/migration.adoc index f76ad6337..384ee89fd 100644 --- a/docs/src/docs/migration.adoc +++ b/docs/src/docs/migration.adoc @@ -21,7 +21,7 @@ When implementing the `PageFactoryProvider` interface, you get an `PAGE_FACTORY` ```java import eu.tsystems.mms.tic.testframework.testing.PageFactoryProvider; -class MyTest extends TesterraTest implements PageFactoryProvider { +class MyTest extends TesterraTest implements PageFactoryProvider, WebDriverManagerProvider { @Test public void test_MyPageTest() { From db72ece60b1141f2c893e4df49f812b874d5fa0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gro=C3=9Fmann?= Date: Fri, 16 Sep 2022 15:08:04 +0200 Subject: [PATCH 9/9] Fixed migration guide --- docs/src/docs/migration.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/docs/migration.adoc b/docs/src/docs/migration.adoc index 384ee89fd..d2314afb0 100644 --- a/docs/src/docs/migration.adoc +++ b/docs/src/docs/migration.adoc @@ -374,11 +374,11 @@ CONTROL.collectAssertions(() -> { }); ``` -For custom assertions +For custom assertions using `AssertProvider` ```java CONTROL.collectAssertions(() -> { String data = loadSomeData(); - Assert.assertEquals(data, "Hello World", "some data"); + ASSERT.assertEquals(data, "Hello World", "some data"); }); ```