From be0e3957e3261211e1f784ea598e1672cdd56028 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 25 Nov 2016 01:46:35 +0300 Subject: [PATCH] Fix bug with property checkbox 1. Make checkbox property working 2. Add fillProperty test 3. Removed unused package --- .travis.yml | 2 +- .../wmp/uitesting/{auth => }/Auther.java | 2 +- .../wmp/uitesting/{auth => }/Opener.java | 2 +- .../wmp/uitesting/dia/PropertyEditor.java | 28 ++++++++++++++----- .../com/qreal/wmp/uitesting/dia/Scene.java | 2 +- .../qreal/wmp/uitesting/dia/SceneWindow.java | 8 +++--- .../{auth => }/innertests/AuthTest.java | 6 ++-- .../{auth => }/innertests/DiaTest.java | 11 ++++---- .../testspace/DiagramConstructingTest.java | 18 ++++++++++-- 9 files changed, 53 insertions(+), 26 deletions(-) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/{auth => }/Auther.java (97%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/{auth => }/Opener.java (98%) rename ui-testing/src/test/java/com/qreal/wmp/uitesting/{auth => }/innertests/AuthTest.java (96%) rename ui-testing/src/test/java/com/qreal/wmp/uitesting/{auth => }/innertests/DiaTest.java (93%) rename ui-testing/src/test/java/com/qreal/wmp/uitesting/{auth => }/testspace/DiagramConstructingTest.java (80%) diff --git a/.travis.yml b/.travis.yml index 96a7a826..73eab8d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,7 +70,7 @@ script: - cd ../ui-testing - mvn test -P travis & - - sleep 150 + - sleep 180 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java similarity index 97% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java index f66a3a09..6129e6e2 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.auth; +package com.qreal.wmp.uitesting; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import org.openqa.selenium.By; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java similarity index 98% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java index 4ec5f676..e1b87ca5 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.auth; +package com.qreal.wmp.uitesting; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import org.slf4j.Logger; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java index 12fd9ae3..9c4374f7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java @@ -23,26 +23,40 @@ public class PropertyEditor { private static final Logger logger = LoggerFactory.getLogger(PropertyEditor.class); /** Set property of element which on the focus. */ - public void setProperty(final String propertyName, final String propertyValue) throws NoSuchElementException { - getInputOfElement(propertyName).setValue(propertyValue); + public void setProperty(final SelenideElement element, final String propertyName, final String propertyValue) + throws NoSuchElementException { + element.click(); + SelenideElement property = getInputOfElement(propertyName); + if (property.attr("class").equals("input-group")) { + property.find(By.xpath(".//*")).setValue(propertyValue); + } else { + property.selectOptionByValue(propertyValue); + } logger.info("Set property {} to {}", propertyName, propertyValue); } /** Return the value of property by name. */ - public String getProperty(final String propertyName) throws NoSuchElementException { + public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException { + $(By.cssSelector(Scene.selector)).click(); + element.click(); + SelenideElement property = getInputOfElement(propertyName); logger.info("Get value of preperty {}", propertyName); - return getInputOfElement(propertyName).getValue(); + if (property.attr("class").equals("input-group")) { + return property.find(By.xpath(".//*")).getValue(); + } else { + return property.getSelectedOption().getValue(); + } } /** To set/get property we need to take web element which describes needed field. */ private SelenideElement getInputOfElement(final String propertyName) { final List allChilds = $$(By.cssSelector(selector + " tbody > * > *")); final OptionalInt indexOfNeeded = IntStream.range(0, allChilds.size()).filter(index -> - allChilds.get(index).getText().equals(propertyName)).findFirst(); + allChilds.get(index).getText().contains(propertyName)).findFirst(); if (!indexOfNeeded.isPresent()) { throw new NoSuchElementException("There is no property with name " + propertyName); } - return $(By.cssSelector(selector + " tbody > * > *:nth-of-type(" - + (indexOfNeeded.getAsInt() + 2) + ") > * > *" )); + return $(By.cssSelector(selector + " tbody > *:nth-of-type(" + (indexOfNeeded.getAsInt() / 2 + 1) + + ") > *:nth-of-type(2) > *" )); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java index 871ba2f9..3f9dfc98 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java @@ -21,7 +21,7 @@ @Service public class Scene { - private static final String selector = ".scene-wrapper"; + public static final String selector = ".scene-wrapper"; private static final Logger logger = LoggerFactory.getLogger(Pallete.class); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java index cf88c6e9..b79d4f5b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java @@ -95,15 +95,15 @@ private Actions callMovementAction(int src, int dst, int step, Actions actions, private Actions callDragAndDropByX(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { final List elements = scene.getAllBlocks(); return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByX(src + step, dst, step, - actions.sendKeys(key).clickAndHold(element).moveByOffset(jump(elements, step, src), 0), key, element) - : actions.sendKeys(key, key); + actions.sendKeys(key).clickAndHold(element).moveByOffset(jump(elements, 2 * step, src), 0), + key, element) : actions.sendKeys(key, key); } private Actions callDragAndDropByY(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { final List elements = scene.getAllBlocks(); return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByY(src + step, dst, step, - actions.sendKeys(key).clickAndHold(element).moveByOffset(0, jump(elements, step, src)), key, element) - : actions.sendKeys(key, key); + actions.sendKeys(key).clickAndHold(element).moveByOffset(0, jump(elements, 2 * step, src)), + key, element) : actions.sendKeys(key, key); } private int jump(final List elements, int step, int current) { diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java similarity index 96% rename from ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/AuthTest.java rename to ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java index 897750ed..c89ba493 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java @@ -1,8 +1,8 @@ -package com.qreal.wmp.uitesting.auth.innertests; +package com.qreal.wmp.uitesting.innertests; import com.codeborne.selenide.WebDriverRunner; -import com.qreal.wmp.uitesting.auth.Auther; -import com.qreal.wmp.uitesting.auth.Opener; +import com.qreal.wmp.uitesting.Auther; +import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import io.github.bonigarcia.wdm.ChromeDriverManager; diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java similarity index 93% rename from ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/DiaTest.java rename to ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 07e446d3..0bb80dec 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -1,8 +1,8 @@ -package com.qreal.wmp.uitesting.auth.innertests; +package com.qreal.wmp.uitesting.innertests; import com.codeborne.selenide.SelenideElement; import com.codeborne.selenide.WebDriverRunner; -import com.qreal.wmp.uitesting.auth.Opener; +import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.Pallete; import com.qreal.wmp.uitesting.dia.PropertyEditor; @@ -86,9 +86,8 @@ public void addLink() { @Test public void propertyEditor() { final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); - motor.click(); - propertyEditor.setProperty("Ports", "123"); - assert propertyEditor.getProperty("Ports").equals("123"); + propertyEditor.setProperty(motor, "Ports", "123"); + assert propertyEditor.getProperty(motor, "Ports").equals("123"); } /** Move element to cell. */ @@ -107,6 +106,6 @@ public void moveElement() { @After public void stopDriver() { scene.clean(); - driver.close(); + driver.quit(); } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java similarity index 80% rename from ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/testspace/DiagramConstructingTest.java rename to ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index aa22549b..6ca6a0a7 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -1,10 +1,11 @@ -package com.qreal.wmp.uitesting.auth.testspace; +package com.qreal.wmp.uitesting.testspace; import com.codeborne.selenide.SelenideElement; import com.codeborne.selenide.WebDriverRunner; -import com.qreal.wmp.uitesting.auth.Opener; +import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.Pallete; +import com.qreal.wmp.uitesting.dia.PropertyEditor; import com.qreal.wmp.uitesting.dia.Scene; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.junit.After; @@ -34,6 +35,9 @@ public class DiagramConstructingTest { @Autowired private Scene scene; + @Autowired + private PropertyEditor propertyEditor; + private WebDriver driver; private ArrayList elements; @@ -79,6 +83,16 @@ public void moveSomeNodes() { assert allExist(); } + @Test + public void fillProperties() { + propertyEditor.setProperty(elements.get(1), "Power", "80"); + assert propertyEditor.getProperty(elements.get(1), "Power").equals("80"); + propertyEditor.setProperty(elements.get(2), "Color", "green"); + assert propertyEditor.getProperty(elements.get(2), "Color").equals("green"); + propertyEditor.setProperty(elements.get(3), "Delay", "200"); + assert propertyEditor.getProperty(elements.get(3), "Delay").equals("200"); + } + @After public void stopDriver() { scene.clean();