Skip to content

Commit

Permalink
Make focus works by JavaScriptExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
artbez committed Feb 26, 2017
1 parent 2441162 commit ffcae07
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 103 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ before_install:
- sudo rm /dev/random
- sudo mknod /dev/random c 1 9
# for gui tests
- export DBUS_SESSION_BUS_ADDRESS=/dev/null
- export CHROME_BIN=/usr/bin/google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
Expand Down
2 changes: 1 addition & 1 deletion ui-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>1.4.10</version>
<version>1.6.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public boolean exist(SceneElement element) {
@Override
public void remove(SceneElement element) throws ElementNotOnTheSceneException {
if (element instanceof Link) {
removeSceneElement(((Link) element).getSource());
removeSceneElement(((Link) element).getTarget());
} else {
removeSceneElement(element);
}
Expand Down Expand Up @@ -147,17 +147,15 @@ private static String createDiv(String divName) {
private void removeSceneElement(SceneElement sceneElement) throws ElementNotOnTheSceneException {
sceneWindow.focus(sceneElement.getCoordinateOnScene());
logger.info("Remove element {} form scene", sceneElement.getInnerSeleniumElement().toString());
new Actions(webDriver).contextClick(sceneElement.getInnerSeleniumElement()).build().perform();
new Actions(webDriver).contextClick(sceneElement.getInnerSeleniumElement()).perform();
try {
Thread.sleep(1000);
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
SelenideElement contextMenu = $(By.id("scene-context-menu"));
if (!contextMenu.is(Condition.visible)) {
logger.info("Context menu is not visible. Try to focus again.");
$(By.cssSelector(SELECTOR)).click();

logger.info("Context menu " + contextMenu + " is not visible. Try to focus again. " );
removeSceneElement(sceneElement);
} else {
contextMenu.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@
import com.qreal.wmp.uitesting.dia.scene.Coordinate;
import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException;
import org.openqa.selenium.By;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.codeborne.selenide.Selenide.$;

public class Link extends SceneElementImpl {

public static final String CLASS_NAME = "link";
private static final Logger logger = LoggerFactory.getLogger(Link.class);

private static final String SOURCE_POINT_CLASSNAME = "marker-source";
public static final String CLASS_NAME = "link";

private static final String TARGET_POINT_CLASSNAME = "marker-target";
private static final String ARROWHEAD = "marker-arrowheads";

private final String name;

private final SceneElement source;

private final SceneElement target;

/** Describes link between two blocks. */
public Link(String name, SelenideElement innerSeleniumObject) {
super(innerSeleniumObject);
this.name = name;
this.source = new SceneElementImpl($(innerSeleniumObject.find(By.className(SOURCE_POINT_CLASSNAME))));
this.target = new SceneElementImpl($(innerSeleniumObject.find(By.className(TARGET_POINT_CLASSNAME))));
try {
Thread.sleep(100);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
this.source = new SceneElementImpl($(innerSeleniumObject
.find(By.className(ARROWHEAD))).find(By.cssSelector(":nth-child(1)"))
);
this.target = new SceneElementImpl($(innerSeleniumObject
.find(By.className(ARROWHEAD))).find(By.cssSelector(":nth-child(2)"))
);
}

public String getName() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class SceneWindowImpl implements SceneWindow, PageInfoUpdator {

private final String selector;

private final FocusHelper focusHelper;

private final MoveHelper moveHelper;

private int stepVert = 40;
Expand All @@ -38,7 +36,6 @@ public class SceneWindowImpl implements SceneWindow, PageInfoUpdator {
private SceneWindowImpl(final Scene scene, final WebDriver driver, String selector) {
this.driver = driver;
this.selector = selector;
focusHelper = FocusHelper.getFocusHelper(this);
moveHelper = MoveHelper.getMoveHelper(scene, driver);
updateSteps();
}
Expand Down Expand Up @@ -78,9 +75,28 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn

@Override
public void focus(final Coordinate coordinate) {
int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue();
int sizeVer = Double.valueOf($(By.id("SceneWindowVerSize")).innerHtml()).intValue();

logger.info("Focus to " + coordinate.getXAbsolute() + " " + coordinate.getYAbsolute());
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript("var canvas = " +
"document.getElementsByClassName(\"scene-wrapper\")[0]; " +
"var BB=canvas.getBoundingClientRect();" +
"canvas.scrollLeft = " + Math.max(0, (coordinate.getXAbsolute() - sizeHor / 2)) + "; " +
"canvas.scrollTop = " + Math.max(0, (coordinate.getYAbsolute() - sizeVer / 2)) + ";"
);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}

/*
focusHelper.horizontalWindowMovement(coordinate.getXAbsolute());
focusHelper.verticalWindowMovement(coordinate.getYAbsolute());
*/
}

@Contract("_, _, _ -> !null")
Expand Down
1 change: 1 addition & 0 deletions ui-testing/ui-testing.iml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: io.github.bonigarcia:webdrivermanager:1.4.10" level="project" />
<orderEntry type="library" name="Maven: io.github.bonigarcia:webdrivermanager:1.6.0" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.12" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
Expand Down

0 comments on commit ffcae07

Please sign in to comment.