Skip to content

Commit

Permalink
Fix bug with property checkbox
Browse files Browse the repository at this point in the history
1. Make checkbox property working
2. Add fillProperty test
3. Removed unused package
  • Loading branch information
artbez committed Nov 25, 2016
1 parent a55e457 commit be0e395
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ script:

- cd ../ui-testing
- mvn test -P travis &
- sleep 150
- sleep 180

notifications:
slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SelenideElement> 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) > *" ));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SelenideElement> 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<SelenideElement> 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<SelenideElement> elements, int step, int current) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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. */
Expand All @@ -107,6 +106,6 @@ public void moveElement() {
@After
public void stopDriver() {
scene.clean();
driver.close();
driver.quit();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,6 +35,9 @@ public class DiagramConstructingTest {
@Autowired
private Scene scene;

@Autowired
private PropertyEditor propertyEditor;

private WebDriver driver;

private ArrayList<SelenideElement> elements;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit be0e395

Please sign in to comment.