From 9bbb9a6b1c05c940c74bfb7251bd34d951d901a1 Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Thu, 3 Nov 2016 02:58:45 +0300 Subject: [PATCH 01/40] Prepare for diagram constructing 1. Add spring framework support 2. Add Opener and Auther services 3. Add PropertySourcesPlaceholderConfigurer 4. Add some auth and open page tests --- UI-testing/UI-testing.iml | 95 +++++++++------- UI-testing/pom.xml | 37 ++++++ .../com/qreal/wmp/uitesting/auth/Auther.java | 39 +++++++ .../com/qreal/wmp/uitesting/auth/Opener.java | 52 +++++++++ .../qreal/wmp/uitesting/config/AppInit.java | 16 +++ .../qreal/wmp/uitesting/config/DevConfig.java | 19 ++++ .../com/qreal/wmp/uitesting/dia/Scene.java | 5 + .../src/main/resources/pages.properties | 3 + .../src/main/resources/services.properties | 1 - .../wmp/uitesting/auth/AuthDashboardTest.java | 90 --------------- .../qreal/wmp/uitesting/auth/AuthTest.java | 107 ++++++++++++++++++ 11 files changed, 333 insertions(+), 131 deletions(-) create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java create mode 100644 UI-testing/src/main/resources/pages.properties delete mode 100644 UI-testing/src/main/resources/services.properties delete mode 100644 UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthDashboardTest.java create mode 100644 UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java diff --git a/UI-testing/UI-testing.iml b/UI-testing/UI-testing.iml index df5de807..220b7095 100644 --- a/UI-testing/UI-testing.iml +++ b/UI-testing/UI-testing.iml @@ -1,5 +1,10 @@ + + + + + @@ -11,48 +16,42 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -62,6 +61,22 @@ + + + + + + + + + + + + + + + + diff --git a/UI-testing/pom.xml b/UI-testing/pom.xml index 0aade41d..bd90c7d1 100644 --- a/UI-testing/pom.xml +++ b/UI-testing/pom.xml @@ -59,6 +59,43 @@ webdrivermanager 1.4.10 + + com.codeborne + selenide + 4.0 + + + + + org.springframework + spring-beans + ${springframework.version} + + + org.springframework + spring-context + ${springframework.version} + + + org.springframework + spring-webmvc + ${springframework.version} + + + org.springframework + spring-tx + ${springframework.version} + + + org.springframework.security + spring-security-taglibs + ${springframework.security.version} + + + org.springframework + spring-test + ${springframework.version} + \ No newline at end of file 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/auth/Auther.java new file mode 100644 index 00000000..b0030836 --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java @@ -0,0 +1,39 @@ +package com.qreal.wmp.uitesting.auth; + +import org.openqa.selenium.By; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.open; + +/** Used for authentication in current browser session. */ +@Service +public class Auther { + + private static final Logger logger = LoggerFactory.getLogger(Auther.class); + + /** Use properties from pages.properies file. */ + @Autowired + private Environment env; + + /** Realizes authentication to the wmp. + * + * @param username login + * @param password password + * */ + public void auth(String username, String password) { + open(env.getProperty("auth")); + $(By.name("username")).setValue(username); + $(By.name("password")).setValue(password); + $("[type=\"submit\"]").click(); + logger.info("Authentication with login: {} and password: {}", username, password); + } + + public void auth() { + auth("123", "123"); + } +} 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/auth/Opener.java new file mode 100644 index 00000000..1978a5ff --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java @@ -0,0 +1,52 @@ +package com.qreal.wmp.uitesting.auth; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; + +import static com.codeborne.selenide.Selectors.byText; +import static com.codeborne.selenide.Selenide.$; + +/** + * Used for open needed page from wmp in current browser session. + * Allows you to access as an authorized user and not. + */ +@Service +public class Opener { + + private static final Logger logger = LoggerFactory.getLogger(Opener.class); + + /** Uses properties from pages.properies file. */ + @Autowired + private Environment env; + + @Autowired + private Auther auther; + + /** + * Opens page from wmp with authentication. + * + * @param page must be one of the keys from pages.property. + */ + public void open(String page) { + com.codeborne.selenide.Selenide.open(env.getProperty(page)); + if ($(byText("Sign in to continue to Auth")).exists()) { + logger.info("Fail with open page {}. Try to login.", env.getProperty(page)); + auther.auth(); + open(page); + } + logger.info("Open page {}", env.getProperty(page)); + } + + /** + * Opens page from wmp without authentication. + * + * @param page must be one of the keys from pages.property. + */ + public void cleanOpen(String page) { + com.codeborne.selenide.Selenide.open(env.getProperty(page)); + logger.info("Open page {}", env.getProperty(page)); + } +} diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java new file mode 100644 index 00000000..ddcf83dd --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java @@ -0,0 +1,16 @@ +package com.qreal.wmp.uitesting.config; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; + +@ComponentScan("com.qreal.wmp.uitesting") +public class AppInit { + + /** Main function creates context. */ + public static void main(String[] args) { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.scan("com.qreal.wmp.uitesting"); + context.register(AppInit.class); + context.refresh(); + } +} diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java new file mode 100644 index 00000000..2faab5c2 --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -0,0 +1,19 @@ +package com.qreal.wmp.uitesting.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; + +/** Creates beans for Spring needs. **/ +@Configuration +@PropertySource("classpath:pages.properties") +public class DevConfig { + + /** Processor for Environment linked to property files.*/ + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + +} 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 new file mode 100644 index 00000000..d1b01961 --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java @@ -0,0 +1,5 @@ +package com.qreal.wmp.uitesting.dia; + +public class Scene { + +} diff --git a/UI-testing/src/main/resources/pages.properties b/UI-testing/src/main/resources/pages.properties new file mode 100644 index 00000000..fd2d42ec --- /dev/null +++ b/UI-testing/src/main/resources/pages.properties @@ -0,0 +1,3 @@ +auth=http://localhost:${port.auth}${path.auth} +dashboard=http://localhost:${port.dashboard}${path.dashboard} +editor=http://localhost:${port.editor}${path.editor} \ No newline at end of file diff --git a/UI-testing/src/main/resources/services.properties b/UI-testing/src/main/resources/services.properties deleted file mode 100644 index 1382b546..00000000 --- a/UI-testing/src/main/resources/services.properties +++ /dev/null @@ -1 +0,0 @@ -accessDashboardUri=http://localhost:${port.dashboard}${path.dashboard} \ No newline at end of file diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthDashboardTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthDashboardTest.java deleted file mode 100644 index b05f4547..00000000 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthDashboardTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.qreal.wmp.uitesting.auth; - -import com.codeborne.selenide.WebDriverRunner; -import io.github.bonigarcia.wdm.ChromeDriverManager; -import org.apache.commons.lang3.RandomStringUtils; -import org.junit.*; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import static com.codeborne.selenide.Condition.appear; -import static com.codeborne.selenide.Condition.exist; -import static com.codeborne.selenide.Selectors.byText; -import static com.codeborne.selenide.Selenide.$; -import static com.codeborne.selenide.Selenide.open; - -public class AuthDashboardTest { - - private static String dashboardUrl; - - private static WebDriver driver; - - /** - * Setup ChromeDriverManager and load correct urls from .properties file. - */ - @BeforeClass - public static void setUpClass() { - ChromeDriverManager.getInstance().setup(); - final String resourceName = "services.properties"; - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - Properties props = new Properties(); - try (InputStream resourceStream = loader.getResourceAsStream(resourceName)) { - props.load(resourceStream); - } catch (IOException e) { - e.printStackTrace(); - } - dashboardUrl = props.getProperty("accessDashboardUri"); - } - - /** - * Try to open dashboard page. - * Should be redirected to auth page. - */ - @Before - public void openAuthPage() { - driver = new ChromeDriver(); - WebDriverRunner.setWebDriver(driver); - open(dashboardUrl); - $(byText("Sign in to continue to Auth")).shouldBe(exist); - $(byText("Dashboard")).shouldNotBe(exist); - } - - /** - * Try to login with correct username and password. - * Should access and redirect to dashboard - */ - @Test - public void userCanLoginByUsername() { - $(By.name("username")).setValue("123"); - $(By.name("password")).setValue("123"); - $("[type=\"submit\"]").click(); - $(byText("Dashboard")).waitUntil(appear, 50000); - } - - /** - * Try to login with random username and password. - * An error must be shown - */ - @Test - public void userWrongAuth() { - $(byText("Password or login wrong")).shouldNotBe(exist); - char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); - String wrongLogin = RandomStringUtils.random(20, alphabet); - String wrongPassword = RandomStringUtils.random(20, alphabet); - $(By.name("username")).setValue(wrongLogin); - $(By.name("password")).setValue(wrongPassword); - $("[type=\"submit\"]").click(); - $(byText("Password or login wrong")).shouldBe(exist); - } - - @After - public void logout() { - driver.close(); - } - -} diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java new file mode 100644 index 00000000..44d57a26 --- /dev/null +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java @@ -0,0 +1,107 @@ +package com.qreal.wmp.uitesting.auth; + +import com.codeborne.selenide.WebDriverRunner; +import com.qreal.wmp.uitesting.config.AppInit; +import io.github.bonigarcia.wdm.ChromeDriverManager; +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import static com.codeborne.selenide.Condition.appear; +import static com.codeborne.selenide.Condition.exist; +import static com.codeborne.selenide.Selectors.byText; +import static com.codeborne.selenide.Selenide.$; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) +public class AuthTest { + + @Autowired + private Auther auther; + + @Autowired + private Opener opener; + + private WebDriver driver; + + /** Setup ChromeDriverManager. */ + @BeforeClass + public static void init() { + ChromeDriverManager.getInstance().setup(); + } + + /** Setup browser. */ + @Before + public void runDriver() { + driver = new ChromeDriver(); + WebDriverRunner.setWebDriver(driver); + } + + /** + * Try to login with correct username and password. + * Should redirect to OAuth page. + */ + @Test + public void authTest() { + opener.cleanOpen("auth"); + $(byText("Sign in to continue to Auth")).shouldBe(exist); + auther.auth(); + $(byText("OAuth Server")).waitUntil(appear, 5000); + } + + /** + * Try to login with random username and password. + * An error must be shown. + */ + @Test + public void authWrongTest() { + opener.cleanOpen("auth"); + $(byText("Sign in to continue to Auth")).shouldBe(exist); + char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); + String wrongLogin = RandomStringUtils.random(20, alphabet); + String wrongPassword = RandomStringUtils.random(20, alphabet); + auther.auth(wrongLogin, wrongPassword); + $(byText("Password or login wrong")).waitUntil(appear, 5000); + } + + /** + * Try to open dashboard page without authentication. + * Should be redirected to auth page. + * Try to open dashboard page with correct login and password. + */ + @Test + public void dashboardTest() { + opener.cleanOpen("dashboard"); + $(byText("Sign in to continue to Auth")).shouldBe(exist); + opener.open("dashboard"); + $(byText("Dashboard")).waitUntil(appear, 5000); + } + + /** + * Try to open editor page without authentication. + * Should be redirected to auth page. + * Try to open editor page with correct login and password. + */ + @Test + public void editorTest() { + opener.cleanOpen("editor"); + $(byText("Sign in to continue to Auth")).shouldBe(exist); + opener.open("editor"); + $(byText("Property Editor")).waitUntil(appear, 5000); + } + + /** Close the browser. */ + @After + public void stopDriver() { + driver.close(); + } +} From 13eb1ef0fa4975aef47f2c79fba93ef358023b58 Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Thu, 3 Nov 2016 19:17:42 +0300 Subject: [PATCH 02/40] Create Scene and Pallete services 1. Create Scene service 2. Create Pallete service 3. Add dragAndDrop test --- .../com/qreal/wmp/uitesting/auth/Opener.java | 2 +- .../com/qreal/wmp/uitesting/dia/Pallete.java | 17 ++++++ .../com/qreal/wmp/uitesting/dia/Scene.java | 9 +++ .../com/qreal/wmp/uitesting/auth/DiaTest.java | 60 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java create mode 100644 UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java 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/auth/Opener.java index 1978a5ff..71a98941 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java @@ -35,8 +35,8 @@ public void open(String page) { if ($(byText("Sign in to continue to Auth")).exists()) { logger.info("Fail with open page {}. Try to login.", env.getProperty(page)); auther.auth(); - open(page); } + com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); } diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java new file mode 100644 index 00000000..3e5610e2 --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java @@ -0,0 +1,17 @@ +package com.qreal.wmp.uitesting.dia; + +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.By; +import org.springframework.stereotype.Service; + +import static com.codeborne.selenide.Selenide.$; + +@Service +public class Pallete { + + private final String selector = "#palette-tab-content"; + + public SelenideElement getElement(String elementName) { + return $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); + } +} 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 d1b01961..6ccd1cbb 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 @@ -1,5 +1,14 @@ package com.qreal.wmp.uitesting.dia; +import com.codeborne.selenide.SelenideElement; +import org.springframework.stereotype.Service; + +@Service public class Scene { + private final String selector = ".scene-wrapper"; + + public void dragAndDrop(SelenideElement element) { + element.dragAndDropTo(selector); + }; } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java new file mode 100644 index 00000000..76299260 --- /dev/null +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -0,0 +1,60 @@ +package com.qreal.wmp.uitesting.auth; + +import com.codeborne.selenide.SelenideElement; +import com.codeborne.selenide.WebDriverRunner; +import com.qreal.wmp.uitesting.config.AppInit; +import com.qreal.wmp.uitesting.dia.Pallete; +import com.qreal.wmp.uitesting.dia.Scene; +import io.github.bonigarcia.wdm.ChromeDriverManager; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) +public class DiaTest { + + @Autowired + private Opener opener; + + @Autowired + private Pallete pallete; + + @Autowired + private Scene scene; + + private WebDriver driver; + + /** Setup ChromeDriverManager. */ + @BeforeClass + public static void init() { + ChromeDriverManager.getInstance().setup(); + } + + /** Setup browser. */ + @Before + public void runDriver() { + driver = new ChromeDriver(); + WebDriverRunner.setWebDriver(driver); + opener.open("editor"); + } + + @Test + public void dragAndDrop() { + SelenideElement palleteElement = pallete.getElement("InitialNode"); + scene.dragAndDrop(palleteElement); + } + /** Close the browser. */ + @After + public void stopDriver() { + /* driver.close(); */ + } +} From f88ade92c9d0525c3823ab2c5ceb00adbd4c30f0 Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Thu, 3 Nov 2016 20:43:00 +0300 Subject: [PATCH 03/40] Add exist method to Scene --- .../com/qreal/wmp/uitesting/dia/Scene.java | 20 ++++++++++++++++++- .../com/qreal/wmp/uitesting/auth/DiaTest.java | 6 ++++-- 2 files changed, 23 insertions(+), 3 deletions(-) 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 6ccd1cbb..7e51163d 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 @@ -1,14 +1,32 @@ package com.qreal.wmp.uitesting.dia; import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.By; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + +import static com.codeborne.selenide.Selenide.$$; + @Service public class Scene { private final String selector = ".scene-wrapper"; - public void dragAndDrop(SelenideElement element) { + private List elements = new ArrayList<>(); + + public SelenideElement dragAndDrop(SelenideElement element) { + List all = $$(By.cssSelector(selector + " #v_7 > *")); element.dragAndDropTo(selector); + SelenideElement newEl = all.stream().filter(x -> !elements.stream() + .anyMatch(y -> x.attr("id").equals(y.attr("id")))).findFirst().get(); + elements.add(newEl); + return newEl; }; + + public boolean exist(SelenideElement selenideElement) { + return elements.stream().anyMatch(x -> x.equals(selenideElement)); + } + } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java index 76299260..53c2b232 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -50,11 +50,13 @@ public void runDriver() { @Test public void dragAndDrop() { SelenideElement palleteElement = pallete.getElement("InitialNode"); - scene.dragAndDrop(palleteElement); + SelenideElement sceneElement = scene.dragAndDrop(palleteElement); + assert (scene.exist(sceneElement)); } + /** Close the browser. */ @After public void stopDriver() { - /* driver.close(); */ + driver.close(); } } From 218c5fff94c27ea32045283e863eeafffc81756e Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Fri, 4 Nov 2016 02:48:02 +0300 Subject: [PATCH 04/40] Add remove and move methods 1. Add remove method 2. Add move method 3. Test them 4. Add getPosition method 5. Add JavaDoc --- .travis.yml | 2 +- UI-testing/UI-testing.iml | 2 +- UI-testing/pom.xml | 6 ++ .../com/qreal/wmp/uitesting/dia/Pallete.java | 10 +++ .../com/qreal/wmp/uitesting/dia/Scene.java | 68 +++++++++++++++++-- .../com/qreal/wmp/uitesting/auth/DiaTest.java | 23 ++++++- 6 files changed, 103 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10fd0aca..5e80274f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -84,7 +84,7 @@ script: - cd ../UI-testing - mvn test -P travis & - - sleep 30 + - sleep 60 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/UI-testing/UI-testing.iml b/UI-testing/UI-testing.iml index 220b7095..5809944c 100644 --- a/UI-testing/UI-testing.iml +++ b/UI-testing/UI-testing.iml @@ -57,10 +57,10 @@ - + diff --git a/UI-testing/pom.xml b/UI-testing/pom.xml index bd90c7d1..14429e55 100644 --- a/UI-testing/pom.xml +++ b/UI-testing/pom.xml @@ -65,6 +65,12 @@ 4.0 + + org.apache.commons + commons-lang3 + 3.5 + + org.springframework diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java index 3e5610e2..91ec135e 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java @@ -6,11 +6,21 @@ import static com.codeborne.selenide.Selenide.$; +/** + * Describes Pallete. + * For any manipulating with it. + */ @Service public class Pallete { private final String selector = "#palette-tab-content"; + /** + * Chose element from Pallete. + * + * @param elementName name of block + * @return block + */ public SelenideElement getElement(String elementName) { return $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); } 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 7e51163d..00bc474f 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 @@ -1,32 +1,90 @@ package com.qreal.wmp.uitesting.dia; import com.codeborne.selenide.SelenideElement; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.interactions.Actions; import org.springframework.stereotype.Service; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; +/** + * Describes Scene of Editor. + * Can add rm and manipulate with objects on that area. + */ @Service public class Scene { private final String selector = ".scene-wrapper"; - private List elements = new ArrayList<>(); + private Set elements = new HashSet<>(); + private WebDriver driver; + + /** For actions such as mouse move we need driver of current page. */ + public void updateWebdriver(WebDriver webDriver) { + driver = webDriver; + } + + /** + * Drag element from scene or pallete and put it on the center of scene. + * + * @param element chosen web element + * @return element from scene + */ public SelenideElement dragAndDrop(SelenideElement element) { List all = $$(By.cssSelector(selector + " #v_7 > *")); element.dragAndDropTo(selector); - SelenideElement newEl = all.stream().filter(x -> !elements.stream() - .anyMatch(y -> x.attr("id").equals(y.attr("id")))).findFirst().get(); + SelenideElement newEl = all.stream().filter(x -> + !elements.stream().anyMatch(y -> x.attr("id").equals(y.attr("id")))).findFirst().orElse(element); elements.add(newEl); return newEl; - }; + } + + /** + * Move element on the Scene by offsets. + * + * @param element chosen web element + * @param offset_x offset of x coordinate + * @param offset_y offset of y coordinate + */ + public void moveElement(SelenideElement element, int offset_x, int offset_y) { + assert exist(element); + new Actions(driver).dragAndDropBy(element, offset_x, offset_y).build().perform(); + } + /** Check if element exist on the scene. */ public boolean exist(SelenideElement selenideElement) { return elements.stream().anyMatch(x -> x.equals(selenideElement)); } + public Pair getPosition(SelenideElement selenideElement) { + String position = selenideElement.attr("transform"); + String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); + return new ImmutablePair(Integer.valueOf(pairStr[0]), Integer.valueOf(pairStr[1])); + } + + /** Remove element from the scene. */ + public void remove(SelenideElement selenideElement) { + elements.remove(selenideElement); + new Actions(driver).contextClick(selenideElement).build().perform(); + $(By.id("scene-context-menu")).click(); + } + + /** Remove all elements from the scene. */ + public void clean() { + elements.forEach(x -> { + new Actions(driver).contextClick(x).build().perform(); + $(By.id("scene-context-menu")).click(); + }); + elements.clear(); + } + } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java index 53c2b232..6a9c6537 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -6,6 +6,7 @@ import com.qreal.wmp.uitesting.dia.Pallete; import com.qreal.wmp.uitesting.dia.Scene; import io.github.bonigarcia.wdm.ChromeDriverManager; +import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -45,18 +46,38 @@ public void runDriver() { driver = new ChromeDriver(); WebDriverRunner.setWebDriver(driver); opener.open("editor"); + scene.updateWebdriver(driver); } @Test public void dragAndDrop() { SelenideElement palleteElement = pallete.getElement("InitialNode"); SelenideElement sceneElement = scene.dragAndDrop(palleteElement); - assert (scene.exist(sceneElement)); + assert scene.exist(sceneElement); + } + + @Test + public void remove() { + SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); + assert scene.exist(sceneElement); + scene.remove(sceneElement); + assert !scene.exist(sceneElement); + } + + @Test + public void move() { + SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); + Pair oldPosition = scene.getPosition(sceneElement); + scene.moveElement(sceneElement, 100, 100); + Pair newPosition = scene.getPosition(sceneElement); + assert ((Integer) oldPosition.getLeft() + 100 == (Integer) newPosition.getLeft()) + && ((Integer) oldPosition.getRight() + 100 == (Integer) newPosition.getRight()); } /** Close the browser. */ @After public void stopDriver() { + scene.clean(); driver.close(); } } From 3a55d67bfed02969131c490f67d2310cb6a4bd70 Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Fri, 4 Nov 2016 03:27:13 +0300 Subject: [PATCH 05/40] Add logging 1. Add logging to Scene 2. Add logging to Pallete --- .../main/java/com/qreal/wmp/uitesting/dia/Pallete.java | 8 +++++++- .../src/main/java/com/qreal/wmp/uitesting/dia/Scene.java | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java index 91ec135e..97c95cde 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java @@ -2,6 +2,8 @@ import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import static com.codeborne.selenide.Selenide.$; @@ -15,6 +17,8 @@ public class Pallete { private final String selector = "#palette-tab-content"; + private static final Logger logger = LoggerFactory.getLogger(Pallete.class); + /** * Chose element from Pallete. * @@ -22,6 +26,8 @@ public class Pallete { * @return block */ public SelenideElement getElement(String elementName) { - return $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); + SelenideElement element = $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); + logger.info("Get element {} from Palette", element); + return element; } } 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 00bc474f..b6b90233 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 @@ -6,6 +6,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.util.HashSet; @@ -28,6 +30,8 @@ public class Scene { private WebDriver driver; + private static final Logger logger = LoggerFactory.getLogger(Pallete.class); + /** For actions such as mouse move we need driver of current page. */ public void updateWebdriver(WebDriver webDriver) { driver = webDriver; @@ -45,6 +49,7 @@ public SelenideElement dragAndDrop(SelenideElement element) { SelenideElement newEl = all.stream().filter(x -> !elements.stream().anyMatch(y -> x.attr("id").equals(y.attr("id")))).findFirst().orElse(element); elements.add(newEl); + logger.info("Add element {} to scene", newEl); return newEl; } @@ -57,6 +62,7 @@ public SelenideElement dragAndDrop(SelenideElement element) { */ public void moveElement(SelenideElement element, int offset_x, int offset_y) { assert exist(element); + logger.info("Move element {} with offsets {} and {}", element, offset_x, offset_y); new Actions(driver).dragAndDropBy(element, offset_x, offset_y).build().perform(); } @@ -73,6 +79,7 @@ public Pair getPosition(SelenideElement selenideElement) { /** Remove element from the scene. */ public void remove(SelenideElement selenideElement) { + logger.info("Remove element {} form scene", selenideElement); elements.remove(selenideElement); new Actions(driver).contextClick(selenideElement).build().perform(); $(By.id("scene-context-menu")).click(); @@ -85,6 +92,7 @@ public void clean() { $(By.id("scene-context-menu")).click(); }); elements.clear(); + logger.info("Clean scene"); } } From d4e6d8b4dccb68709bafe60cc735e0bb0be1be96 Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Fri, 4 Nov 2016 22:21:08 +0300 Subject: [PATCH 06/40] Add addLink method 1. Now scene can link two elements 2. Add test for it 3. Add JavaDoc --- .../com/qreal/wmp/uitesting/dia/Scene.java | 27 ++++++++++++++++--- .../com/qreal/wmp/uitesting/auth/DiaTest.java | 12 +++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) 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 b6b90233..0462a95a 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 @@ -12,6 +12,7 @@ import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import static com.codeborne.selenide.Selenide.$; @@ -44,10 +45,8 @@ public void updateWebdriver(WebDriver webDriver) { * @return element from scene */ public SelenideElement dragAndDrop(SelenideElement element) { - List all = $$(By.cssSelector(selector + " #v_7 > *")); element.dragAndDropTo(selector); - SelenideElement newEl = all.stream().filter(x -> - !elements.stream().anyMatch(y -> x.attr("id").equals(y.attr("id")))).findFirst().orElse(element); + SelenideElement newEl = updateScene().get(); elements.add(newEl); logger.info("Add element {} to scene", newEl); return newEl; @@ -79,6 +78,7 @@ public Pair getPosition(SelenideElement selenideElement) { /** Remove element from the scene. */ public void remove(SelenideElement selenideElement) { + assert selenideElement != null; logger.info("Remove element {} form scene", selenideElement); elements.remove(selenideElement); new Actions(driver).contextClick(selenideElement).build().perform(); @@ -87,7 +87,7 @@ public void remove(SelenideElement selenideElement) { /** Remove all elements from the scene. */ public void clean() { - elements.forEach(x -> { + elements.stream().filter(x -> x != null).forEach(x -> { new Actions(driver).contextClick(x).build().perform(); $(By.id("scene-context-menu")).click(); }); @@ -95,4 +95,23 @@ public void clean() { logger.info("Clean scene"); } + /** Add link between two elements. */ + public SelenideElement addLink(SelenideElement source, SelenideElement target) { + SelenideElement begin = $(By.cssSelector(selector + " #" + source.attr("id") + " .outPorts")); + logger.info("Begin element {}", begin); + new Actions(driver).dragAndDrop(begin, target).build().perform(); + SelenideElement newEl = updateScene().get(); + logger.info("Add link {}", newEl); + elements.add(newEl); + return newEl; + } + + /** Return new element of the scene. */ + private Optional updateScene() { + List allElements = $$(By.cssSelector(selector + " #v_7 > *")); + return allElements.stream().filter(x -> + !elements.stream().anyMatch(y -> x.attr("id").equals(y.attr("id")))).findFirst(); + + } + } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java index 6a9c6537..ba7856b7 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -49,6 +49,7 @@ public void runDriver() { scene.updateWebdriver(driver); } + /** Drag element from pallete and drop on the scene. */ @Test public void dragAndDrop() { SelenideElement palleteElement = pallete.getElement("InitialNode"); @@ -56,6 +57,7 @@ public void dragAndDrop() { assert scene.exist(sceneElement); } + /** Remove element from scene. */ @Test public void remove() { SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); @@ -64,6 +66,7 @@ public void remove() { assert !scene.exist(sceneElement); } + /** Move element on the scene by offsets. */ @Test public void move() { SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); @@ -74,6 +77,15 @@ public void move() { && ((Integer) oldPosition.getRight() + 100 == (Integer) newPosition.getRight()); } + /** Add two elements and link them. */ + @Test + public void addLink() { + SelenideElement initNode = scene.dragAndDrop(pallete.getElement("InitialNode")); + scene.moveElement(initNode, 100, 100); + SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("FinalNode")); + scene.addLink(initNode, finalNode); + } + /** Close the browser. */ @After public void stopDriver() { From 00ccd7068634e525dcd878ab15da9c5418deb9fe Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Fri, 4 Nov 2016 23:30:21 +0300 Subject: [PATCH 07/40] Codacy --- .../com/qreal/wmp/uitesting/auth/Auther.java | 6 +-- .../com/qreal/wmp/uitesting/auth/Opener.java | 8 ++-- .../qreal/wmp/uitesting/config/AppInit.java | 4 +- .../com/qreal/wmp/uitesting/dia/Pallete.java | 6 +-- .../wmp/uitesting/dia/PropertyEditor.java | 4 ++ .../com/qreal/wmp/uitesting/dia/Scene.java | 41 +++++++++---------- .../qreal/wmp/uitesting/auth/AuthTest.java | 19 +++++---- .../com/qreal/wmp/uitesting/auth/DiaTest.java | 19 +++++---- 8 files changed, 57 insertions(+), 50 deletions(-) create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java 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/auth/Auther.java index b0030836..ca498c74 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java @@ -14,18 +14,18 @@ @Service public class Auther { - private static final Logger logger = LoggerFactory.getLogger(Auther.class); - /** Use properties from pages.properies file. */ @Autowired private Environment env; + private static final Logger logger = LoggerFactory.getLogger(Auther.class); + /** Realizes authentication to the wmp. * * @param username login * @param password password * */ - public void auth(String username, String password) { + public void auth(final String username, final String password) { open(env.getProperty("auth")); $(By.name("username")).setValue(username); $(By.name("password")).setValue(password); 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/auth/Opener.java index 71a98941..bd4a210c 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java @@ -16,8 +16,6 @@ @Service public class Opener { - private static final Logger logger = LoggerFactory.getLogger(Opener.class); - /** Uses properties from pages.properies file. */ @Autowired private Environment env; @@ -25,12 +23,14 @@ public class Opener { @Autowired private Auther auther; + private static final Logger logger = LoggerFactory.getLogger(Opener.class); + /** * Opens page from wmp with authentication. * * @param page must be one of the keys from pages.property. */ - public void open(String page) { + public void open(final String page) { com.codeborne.selenide.Selenide.open(env.getProperty(page)); if ($(byText("Sign in to continue to Auth")).exists()) { logger.info("Fail with open page {}. Try to login.", env.getProperty(page)); @@ -45,7 +45,7 @@ public void open(String page) { * * @param page must be one of the keys from pages.property. */ - public void cleanOpen(String page) { + public void cleanOpen(final String page) { com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); } diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java index ddcf83dd..5a0e46c5 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java @@ -7,8 +7,8 @@ public class AppInit { /** Main function creates context. */ - public static void main(String[] args) { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + public static void main(final String... args) { + final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.scan("com.qreal.wmp.uitesting"); context.register(AppInit.class); context.refresh(); diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java index 97c95cde..f89e13a8 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java @@ -15,7 +15,7 @@ @Service public class Pallete { - private final String selector = "#palette-tab-content"; + private static final String selector = "#palette-tab-content"; private static final Logger logger = LoggerFactory.getLogger(Pallete.class); @@ -25,8 +25,8 @@ public class Pallete { * @param elementName name of block * @return block */ - public SelenideElement getElement(String elementName) { - SelenideElement element = $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); + public SelenideElement getElement(final String elementName) { + final SelenideElement element = $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); logger.info("Get element {} from Palette", element); return element; } 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 new file mode 100644 index 00000000..85ce6c82 --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java @@ -0,0 +1,4 @@ +package com.qreal.wmp.uitesting.dia; + +public class PropertyEditor { +} 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 0462a95a..78f5398b 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 @@ -25,16 +25,16 @@ @Service public class Scene { - private final String selector = ".scene-wrapper"; + private static final String selector = ".scene-wrapper"; - private Set elements = new HashSet<>(); + private static final Logger logger = LoggerFactory.getLogger(Pallete.class); - private WebDriver driver; + private final Set elements = new HashSet<>(); - private static final Logger logger = LoggerFactory.getLogger(Pallete.class); + private WebDriver driver; /** For actions such as mouse move we need driver of current page. */ - public void updateWebdriver(WebDriver webDriver) { + public void updateWebdriver(final WebDriver webDriver) { driver = webDriver; } @@ -44,9 +44,9 @@ public void updateWebdriver(WebDriver webDriver) { * @param element chosen web element * @return element from scene */ - public SelenideElement dragAndDrop(SelenideElement element) { + public SelenideElement dragAndDrop(final SelenideElement element) { element.dragAndDropTo(selector); - SelenideElement newEl = updateScene().get(); + final SelenideElement newEl = updateScene().get(); elements.add(newEl); logger.info("Add element {} to scene", newEl); return newEl; @@ -59,7 +59,7 @@ public SelenideElement dragAndDrop(SelenideElement element) { * @param offset_x offset of x coordinate * @param offset_y offset of y coordinate */ - public void moveElement(SelenideElement element, int offset_x, int offset_y) { + public void moveElement(final SelenideElement element, final int offset_x, final int offset_y) { assert exist(element); logger.info("Move element {} with offsets {} and {}", element, offset_x, offset_y); new Actions(driver).dragAndDropBy(element, offset_x, offset_y).build().perform(); @@ -67,17 +67,17 @@ public void moveElement(SelenideElement element, int offset_x, int offset_y) { /** Check if element exist on the scene. */ public boolean exist(SelenideElement selenideElement) { - return elements.stream().anyMatch(x -> x.equals(selenideElement)); + return elements.stream().anyMatch(element -> element.equals(selenideElement)); } - public Pair getPosition(SelenideElement selenideElement) { - String position = selenideElement.attr("transform"); - String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); + public Pair getPosition(final SelenideElement selenideElement) { + final String position = selenideElement.attr("transform"); + final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); return new ImmutablePair(Integer.valueOf(pairStr[0]), Integer.valueOf(pairStr[1])); } /** Remove element from the scene. */ - public void remove(SelenideElement selenideElement) { + public void remove(final SelenideElement selenideElement) { assert selenideElement != null; logger.info("Remove element {} form scene", selenideElement); elements.remove(selenideElement); @@ -87,17 +87,14 @@ public void remove(SelenideElement selenideElement) { /** Remove all elements from the scene. */ public void clean() { - elements.stream().filter(x -> x != null).forEach(x -> { - new Actions(driver).contextClick(x).build().perform(); - $(By.id("scene-context-menu")).click(); - }); + $$(By.cssSelector(selector + " #v_7 > *")).forEach(element -> remove(element)); elements.clear(); logger.info("Clean scene"); } /** Add link between two elements. */ - public SelenideElement addLink(SelenideElement source, SelenideElement target) { - SelenideElement begin = $(By.cssSelector(selector + " #" + source.attr("id") + " .outPorts")); + public SelenideElement addLink(final SelenideElement source, final SelenideElement target) { + final SelenideElement begin = $(By.cssSelector(selector + " #" + source.attr("id") + " .outPorts")); logger.info("Begin element {}", begin); new Actions(driver).dragAndDrop(begin, target).build().perform(); SelenideElement newEl = updateScene().get(); @@ -108,9 +105,9 @@ public SelenideElement addLink(SelenideElement source, SelenideElement target) { /** Return new element of the scene. */ private Optional updateScene() { - List allElements = $$(By.cssSelector(selector + " #v_7 > *")); - return allElements.stream().filter(x -> - !elements.stream().anyMatch(y -> x.attr("id").equals(y.attr("id")))).findFirst(); + final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); + return allElements.stream().filter(htmlElement -> !elements.stream().anyMatch(selenideElement -> + htmlElement.attr("id").equals(selenideElement.attr("id")))).findFirst(); } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java index 44d57a26..a7f40f19 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java @@ -53,7 +53,7 @@ public void runDriver() { @Test public void authTest() { opener.cleanOpen("auth"); - $(byText("Sign in to continue to Auth")).shouldBe(exist); + assert inAuthPage(); auther.auth(); $(byText("OAuth Server")).waitUntil(appear, 5000); } @@ -65,10 +65,10 @@ public void authTest() { @Test public void authWrongTest() { opener.cleanOpen("auth"); - $(byText("Sign in to continue to Auth")).shouldBe(exist); - char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); - String wrongLogin = RandomStringUtils.random(20, alphabet); - String wrongPassword = RandomStringUtils.random(20, alphabet); + assert inAuthPage(); + final char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); + final String wrongLogin = RandomStringUtils.random(20, alphabet); + final String wrongPassword = RandomStringUtils.random(20, alphabet); auther.auth(wrongLogin, wrongPassword); $(byText("Password or login wrong")).waitUntil(appear, 5000); } @@ -81,7 +81,7 @@ public void authWrongTest() { @Test public void dashboardTest() { opener.cleanOpen("dashboard"); - $(byText("Sign in to continue to Auth")).shouldBe(exist); + assert inAuthPage(); opener.open("dashboard"); $(byText("Dashboard")).waitUntil(appear, 5000); } @@ -94,7 +94,7 @@ public void dashboardTest() { @Test public void editorTest() { opener.cleanOpen("editor"); - $(byText("Sign in to continue to Auth")).shouldBe(exist); + assert inAuthPage(); opener.open("editor"); $(byText("Property Editor")).waitUntil(appear, 5000); } @@ -104,4 +104,9 @@ public void editorTest() { public void stopDriver() { driver.close(); } + + /** Current page is Auth page */ + private boolean inAuthPage() { + return $(byText("Sign in to continue to Auth")).exists(); + } } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java index ba7856b7..17fda266 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -52,15 +52,15 @@ public void runDriver() { /** Drag element from pallete and drop on the scene. */ @Test public void dragAndDrop() { - SelenideElement palleteElement = pallete.getElement("InitialNode"); - SelenideElement sceneElement = scene.dragAndDrop(palleteElement); + final SelenideElement palleteElement = pallete.getElement("InitialNode"); + final SelenideElement sceneElement = scene.dragAndDrop(palleteElement); assert scene.exist(sceneElement); } /** Remove element from scene. */ @Test public void remove() { - SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); + final SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); assert scene.exist(sceneElement); scene.remove(sceneElement); assert !scene.exist(sceneElement); @@ -69,10 +69,10 @@ public void remove() { /** Move element on the scene by offsets. */ @Test public void move() { - SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); - Pair oldPosition = scene.getPosition(sceneElement); + final SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); + final Pair oldPosition = scene.getPosition(sceneElement); scene.moveElement(sceneElement, 100, 100); - Pair newPosition = scene.getPosition(sceneElement); + final Pair newPosition = scene.getPosition(sceneElement); assert ((Integer) oldPosition.getLeft() + 100 == (Integer) newPosition.getLeft()) && ((Integer) oldPosition.getRight() + 100 == (Integer) newPosition.getRight()); } @@ -80,10 +80,11 @@ public void move() { /** Add two elements and link them. */ @Test public void addLink() { - SelenideElement initNode = scene.dragAndDrop(pallete.getElement("InitialNode")); + final SelenideElement initNode = scene.dragAndDrop(pallete.getElement("InitialNode")); scene.moveElement(initNode, 100, 100); - SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("FinalNode")); - scene.addLink(initNode, finalNode); + final SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("FinalNode")); + SelenideElement link = scene.addLink(initNode, finalNode); + assert scene.exist(link); } /** Close the browser. */ From 69b61d0ecad2c4c15a1e41e401d33ff20034310a Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Sat, 5 Nov 2016 01:26:27 +0300 Subject: [PATCH 08/40] Add PropertyEditor service 1. Add setProperty 2. Add getProperty 3. Add test of them --- .../wmp/uitesting/dia/PropertyEditor.java | 35 +++++++++++++++++++ .../qreal/wmp/uitesting/auth/AuthTest.java | 7 ++-- .../com/qreal/wmp/uitesting/auth/DiaTest.java | 13 +++++++ 3 files changed, 53 insertions(+), 2 deletions(-) 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 85ce6c82..5883321b 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 @@ -1,4 +1,39 @@ package com.qreal.wmp.uitesting.dia; +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.By; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.OptionalInt; +import java.util.stream.IntStream; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; + +/** Describe Property Editor. */ +@Service public class PropertyEditor { + + private static final String selector = "#property_table"; + + /** Set property of element which on the focus. */ + public void setProperty(final String propertyName, final String propertyValue) { + getInputOfElement(propertyName).setValue(propertyValue); + } + + /** Return the value of property by name. */ + public String getProperty(final String propertyName) { + return getInputOfElement(propertyName).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(); + assert indexOfNeeded.isPresent(); + return $(By.cssSelector(selector + " tbody > * > *:nth-of-type(" + + (indexOfNeeded.getAsInt() + 2) + ") > * > *" )); + } } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java index a7f40f19..1b1a039d 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java @@ -17,7 +17,6 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; import static com.codeborne.selenide.Condition.appear; -import static com.codeborne.selenide.Condition.exist; import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; @@ -105,7 +104,11 @@ public void stopDriver() { driver.close(); } - /** Current page is Auth page */ + /** + * Check that current page is Auth page. + * + * @return true if it is + */ private boolean inAuthPage() { return $(byText("Sign in to continue to Auth")).exists(); } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java index 17fda266..0ee1e79e 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -4,6 +4,7 @@ import com.codeborne.selenide.WebDriverRunner; 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.apache.commons.lang3.tuple.Pair; @@ -32,6 +33,9 @@ public class DiaTest { @Autowired private Scene scene; + @Autowired + private PropertyEditor propertyEditor; + private WebDriver driver; /** Setup ChromeDriverManager. */ @@ -87,6 +91,15 @@ public void addLink() { assert scene.exist(link); } + /** Set property 'Ports' of motor forward item to '123' and checks that all is correct. */ + @Test + public void propertyEditor() { + final SelenideElement motor = scene.dragAndDrop(pallete.getElement("TrikV6EnginesForward")); + motor.click(); + propertyEditor.setProperty("Ports", "123"); + assert propertyEditor.getProperty("Ports").equals("123"); + } + /** Close the browser. */ @After public void stopDriver() { From ec6feba1f74eb34390b689f4800cf41274ffce8c Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Mon, 14 Nov 2016 20:25:51 +0300 Subject: [PATCH 09/40] Add possibility to move element to any point in the scene 1. Add SceneWindow class which describes part of the scene that user see 2. Add moveElement test --- .../com/qreal/wmp/uitesting/dia/Scene.java | 7 +- .../qreal/wmp/uitesting/dia/SceneWindow.java | 95 +++++++++++++++++++ .../com/qreal/wmp/uitesting/auth/DiaTest.java | 27 +++++- 3 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java 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 78f5398b..b8c6b015 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 @@ -1,9 +1,8 @@ package com.qreal.wmp.uitesting.dia; import com.codeborne.selenide.SelenideElement; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; @@ -70,10 +69,10 @@ public boolean exist(SelenideElement selenideElement) { return elements.stream().anyMatch(element -> element.equals(selenideElement)); } - public Pair getPosition(final SelenideElement selenideElement) { + public Dimension getPosition(final SelenideElement selenideElement) { final String position = selenideElement.attr("transform"); final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); - return new ImmutablePair(Integer.valueOf(pairStr[0]), Integer.valueOf(pairStr[1])); + return new Dimension(Integer.valueOf(pairStr[0]), Integer.valueOf(pairStr[1])); } /** Remove element from the scene. */ 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 new file mode 100644 index 00000000..7372663b --- /dev/null +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java @@ -0,0 +1,95 @@ +package com.qreal.wmp.uitesting.dia; + +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.interactions.Actions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.function.IntPredicate; +import java.util.function.Supplier; +import java.util.stream.IntStream; + +import static com.codeborne.selenide.Selenide.$; + +@Service +public class SceneWindow { + + @Autowired + private Scene scene; + + private Dimension size; + + private static final String selector = ".scene-wrapper"; + + private WebDriver driver; + + /** For actions such as mouse move we need driver of current page. */ + public void updateWebdriver(final WebDriver webDriver) { + driver = webDriver; + } + + public void move(SelenideElement element, Dimension dist, WebDriver driver) { + Dimension src = scene.getPosition(element); + SelenideElement sceneWrapper = $(By.cssSelector(".scene-wrapper")); + int step = sceneWrapper.getSize().getWidth() / 9; + size = sceneWrapper.getSize(); + focus(src, driver); + + if (src.getWidth() < dist.getWidth()) + stepsWithActions(src.getWidth(), x -> x < dist.getWidth() + 0.75 * src.getWidth(), step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_RIGHT) + .clickAndHold(element).moveByOffset(step, 0)); + else + stepsWithActions(src.getWidth(), x -> x > dist.getWidth() + 0.27 * src.getWidth(), -step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_LEFT) + .clickAndHold(element).moveByOffset(-step, 0)); + + if (src.getHeight() < dist.getHeight()) + stepsWithActions(src.getHeight(), x -> x < dist.getHeight() + 0.75 * src.getHeight(), step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_DOWN) + .clickAndHold(element).moveByOffset(step, 0)); + else + stepsWithActions(src.getHeight(), x -> x > dist.getHeight() + 0.75 * src.getHeight(), -step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_UP) + .clickAndHold(element).moveByOffset(-step, 0)); + + + Dimension currentPosition = scene.getPosition(element); + new Actions(driver).release().clickAndHold(element).moveByOffset(dist.getWidth() - currentPosition.getWidth(), + dist.getHeight() - currentPosition.getHeight()).release().build().perform(); + + System.out.println("Position: " + scene.getPosition(element)); + } + + public void focus(Dimension position, WebDriver driver) { + SelenideElement sceneWrapper = $(By.cssSelector(selector)); + size = sceneWrapper.getSize(); + int step = size.getWidth() / 9; + + stepsWithActions(0, constructPredicate(0, 2000, 0), step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_LEFT)); + stepsWithActions(0, constructPredicate(0, 2000, 0), step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_UP)); + + stepsWithActions(size.getWidth(), x -> x < position.getWidth() + 0.75 * size.getWidth(), step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_RIGHT)); + stepsWithActions(size.getHeight(), x -> x < position.getHeight() + 0.75 * size.getHeight(), step, + () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_DOWN)); + new Actions(driver).build().perform(); + } + + public IntPredicate constructPredicate(final int srcValue, final int distValue, final int half) { + return srcValue < distValue ? x -> x < distValue + 1.5 * half: x -> x > srcValue + 1.5 * half; + } + + public void stepsWithActions(int begin, IntPredicate border, int step, Supplier... actionses) { + IntStream.iterate(begin, i -> i + step).peek(newValue -> { + Arrays.stream(actionses).forEach(actions -> actions.get().perform()); + }).allMatch(border); + } +} diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java index 0ee1e79e..e39fae8f 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -6,6 +6,7 @@ import com.qreal.wmp.uitesting.dia.Pallete; import com.qreal.wmp.uitesting.dia.PropertyEditor; import com.qreal.wmp.uitesting.dia.Scene; +import com.qreal.wmp.uitesting.dia.SceneWindow; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.apache.commons.lang3.tuple.Pair; import org.junit.After; @@ -13,6 +14,8 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; @@ -36,6 +39,9 @@ public class DiaTest { @Autowired private PropertyEditor propertyEditor; + @Autowired + private SceneWindow scw; + private WebDriver driver; /** Setup ChromeDriverManager. */ @@ -74,11 +80,11 @@ public void remove() { @Test public void move() { final SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); - final Pair oldPosition = scene.getPosition(sceneElement); - scene.moveElement(sceneElement, 100, 100); - final Pair newPosition = scene.getPosition(sceneElement); - assert ((Integer) oldPosition.getLeft() + 100 == (Integer) newPosition.getLeft()) - && ((Integer) oldPosition.getRight() + 100 == (Integer) newPosition.getRight()); + final Dimension oldPosition = scene.getPosition(sceneElement); + scene.moveElement(sceneElement, 500, 100); + final Dimension newPosition = scene.getPosition(sceneElement); + assert (oldPosition.getWidth() + 500 == newPosition.getWidth()) + && (oldPosition.getHeight() + 100 == newPosition.getHeight()); } /** Add two elements and link them. */ @@ -100,6 +106,17 @@ public void propertyEditor() { assert propertyEditor.getProperty("Ports").equals("123"); } + @Test + public void sceneWindow() { + final SelenideElement motor = scene.dragAndDrop(pallete.getElement("TrikV6EnginesForward")); + scw.move(motor, new Dimension(1000, 1000), driver); + assert scene.getPosition(motor).getWidth() == 1000 && scene.getPosition(motor).getHeight() == 1000; + scw.move(motor, new Dimension(1800, 1600), driver); + assert scene.getPosition(motor).getWidth() == 1800 && scene.getPosition(motor).getHeight() == 1600; + scw.move(motor, new Dimension(1000, 1000), driver); + assert scene.getPosition(motor).getWidth() == 1000 && scene.getPosition(motor).getHeight() == 1000; + } + /** Close the browser. */ @After public void stopDriver() { From a026b524958f299f4f9100523630fad7bacb7d67 Mon Sep 17 00:00:00 2001 From: Artemii Bezguzikov Date: Tue, 15 Nov 2016 18:10:37 +0300 Subject: [PATCH 10/40] Code refactor of SceneWindow 1. Code refactor 2. Add moveToCell method in Scene 3. Add focus method in Scene 4. Add tests --- .travis.yml | 2 +- .../com/qreal/wmp/uitesting/dia/Scene.java | 36 ++++- .../qreal/wmp/uitesting/dia/SceneWindow.java | 135 ++++++++++-------- .../com/qreal/wmp/uitesting/auth/DiaTest.java | 44 ++---- 4 files changed, 117 insertions(+), 100 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5e80274f..de958540 100644 --- a/.travis.yml +++ b/.travis.yml @@ -84,7 +84,7 @@ script: - cd ../UI-testing - mvn test -P travis & - - sleep 60 + - sleep 90 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E 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 b8c6b015..a51f1371 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 @@ -52,16 +52,37 @@ public SelenideElement dragAndDrop(final SelenideElement element) { } /** - * Move element on the Scene by offsets. + * element from scene or pallete and put it in cell of the scene. * * @param element chosen web element - * @param offset_x offset of x coordinate - * @param offset_y offset of y coordinate + * @param cell_x x-coordinate of cell + * @param cell_y y-coordinate of cell + * @return element from scene */ - public void moveElement(final SelenideElement element, final int offset_x, final int offset_y) { - assert exist(element); - logger.info("Move element {} with offsets {} and {}", element, offset_x, offset_y); - new Actions(driver).dragAndDropBy(element, offset_x, offset_y).build().perform(); + public SelenideElement dragAndDrop(final SelenideElement element, int cell_x, int cell_y) { + SelenideElement newEl = dragAndDrop(element); + moveToCell(newEl, cell_x, cell_y); + return newEl; + } + + /** Move element to cell. */ + public void moveToCell(final SelenideElement element, final int cell_x, final int cell_y) { + SceneWindow sceneWindow = new SceneWindow(this, driver); + logger.info("Move element {} to cell ({}, {})", element, cell_x, cell_y); + sceneWindow.move(element, new Dimension(cell_x * 25, cell_y * 25)); + } + + /** Focus the element. */ + public void focus(final SelenideElement element) { + SceneWindow sceneWindow = new SceneWindow(this, driver); + logger.info("Focus on the element {}", element); + sceneWindow.focus(getPosition(element)); + } + + /** Return the cell where element hold. */ + public Dimension getCell(SelenideElement element) { + Dimension result = getPosition(element); + return new Dimension(result.getWidth() / 25, result.getHeight() / 25); } /** Check if element exist on the scene. */ @@ -69,6 +90,7 @@ public boolean exist(SelenideElement selenideElement) { return elements.stream().anyMatch(element -> element.equals(selenideElement)); } + /** Return the position of element in coordinates. */ public Dimension getPosition(final SelenideElement selenideElement) { final String position = selenideElement.attr("transform"); final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); 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 7372663b..748acbe8 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 @@ -6,90 +6,99 @@ import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.function.IntPredicate; -import java.util.function.Supplier; -import java.util.stream.IntStream; import static com.codeborne.selenide.Selenide.$; -@Service +/** + * Describes part of the scene, which is shown on browser. + */ public class SceneWindow { - @Autowired - private Scene scene; + /** Link to full scene. */ + private final Scene scene; + + private final int stepVert; - private Dimension size; + private final int stepHor; - private static final String selector = ".scene-wrapper"; + private final WebDriver driver; - private WebDriver driver; + /** Web element of the Scene. */ + private final SelenideElement sceneWrapper; - /** For actions such as mouse move we need driver of current page. */ - public void updateWebdriver(final WebDriver webDriver) { - driver = webDriver; + /** Constructor takes links to current scene and current driver. */ + public SceneWindow(final Scene scene, final WebDriver driver) { + this.scene = scene; + this.driver = driver; + sceneWrapper = $(By.cssSelector(".scene-wrapper")); + stepVert = sceneWrapper.getSize().getHeight() / 12; + stepHor = sceneWrapper.getSize().getWidth() / 12; } - public void move(SelenideElement element, Dimension dist, WebDriver driver) { + /** + * Moves element to the requested position. + * + * @param element element to move + * @param dist position to move + */ + public void move(final SelenideElement element, final Dimension dist) { Dimension src = scene.getPosition(element); - SelenideElement sceneWrapper = $(By.cssSelector(".scene-wrapper")); - int step = sceneWrapper.getSize().getWidth() / 9; - size = sceneWrapper.getSize(); - focus(src, driver); - - if (src.getWidth() < dist.getWidth()) - stepsWithActions(src.getWidth(), x -> x < dist.getWidth() + 0.75 * src.getWidth(), step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_RIGHT) - .clickAndHold(element).moveByOffset(step, 0)); - else - stepsWithActions(src.getWidth(), x -> x > dist.getWidth() + 0.27 * src.getWidth(), -step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_LEFT) - .clickAndHold(element).moveByOffset(-step, 0)); - - if (src.getHeight() < dist.getHeight()) - stepsWithActions(src.getHeight(), x -> x < dist.getHeight() + 0.75 * src.getHeight(), step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_DOWN) - .clickAndHold(element).moveByOffset(step, 0)); - else - stepsWithActions(src.getHeight(), x -> x > dist.getHeight() + 0.75 * src.getHeight(), -step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_UP) - .clickAndHold(element).moveByOffset(-step, 0)); - + focus(src); + + if (src.getWidth() < dist.getWidth()) { + callDragAndDropByX(src.getWidth(), dist.getWidth(), stepHor, + new Actions(driver), Keys.ARROW_RIGHT, element).perform(); + } else { + callDragAndDropByX(src.getWidth(), dist.getWidth(), -stepHor, + new Actions(driver), Keys.ARROW_LEFT, element).perform(); + } + + if (src.getHeight() < dist.getHeight()) { + callDragAndDropByY(src.getHeight(), dist.getHeight(), stepVert, + new Actions(driver), Keys.ARROW_DOWN, element).perform(); + } else { + callDragAndDropByY(src.getHeight(), dist.getHeight(), -stepVert, + new Actions(driver), Keys.ARROW_UP, element).perform(); + } Dimension currentPosition = scene.getPosition(element); new Actions(driver).release().clickAndHold(element).moveByOffset(dist.getWidth() - currentPosition.getWidth(), - dist.getHeight() - currentPosition.getHeight()).release().build().perform(); + dist.getHeight() - currentPosition.getHeight()).release().perform(); + currentPosition = scene.getPosition(element); + if (!currentPosition.equals(dist)) { + move(element, dist); + } + } - System.out.println("Position: " + scene.getPosition(element)); + /** + * Move the screen to requested position. + * + * @param position position to move + */ + public void focus(final Dimension position) { + final Dimension size = sceneWrapper.getSize(); + callMovementAction(0, 2000, stepHor, new Actions(driver), Keys.ARROW_LEFT); + callMovementAction(0, 2000, stepVert, new Actions(driver), Keys.ARROW_UP); + + callMovementAction(size.getWidth(), position.getWidth(), stepHor, + new Actions(driver), Keys.ARROW_RIGHT).release().perform(); + callMovementAction(size.getHeight(), position.getHeight(), stepVert, + new Actions(driver), Keys.ARROW_DOWN).release().perform(); } - public void focus(Dimension position, WebDriver driver) { - SelenideElement sceneWrapper = $(By.cssSelector(selector)); - size = sceneWrapper.getSize(); - int step = size.getWidth() / 9; - - stepsWithActions(0, constructPredicate(0, 2000, 0), step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_LEFT)); - stepsWithActions(0, constructPredicate(0, 2000, 0), step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_UP)); - - stepsWithActions(size.getWidth(), x -> x < position.getWidth() + 0.75 * size.getWidth(), step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_RIGHT)); - stepsWithActions(size.getHeight(), x -> x < position.getHeight() + 0.75 * size.getHeight(), step, - () -> new Actions(driver).click(sceneWrapper).sendKeys(Keys.ARROW_DOWN)); - new Actions(driver).build().perform(); + private Actions callMovementAction(int src, int dst, int step, Actions actions, Keys key) { + return src < dst ? callMovementAction(src + step, dst, step, actions.sendKeys(key), key) : actions; } - public IntPredicate constructPredicate(final int srcValue, final int distValue, final int half) { - return srcValue < distValue ? x -> x < distValue + 1.5 * half: x -> x > srcValue + 1.5 * half; + private Actions callDragAndDropByX(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { + return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByX(src + step, dst, step, + actions.sendKeys(key).clickAndHold(element).moveByOffset(step * 2, 0), key, element) + : actions.sendKeys(key, key); } - public void stepsWithActions(int begin, IntPredicate border, int step, Supplier... actionses) { - IntStream.iterate(begin, i -> i + step).peek(newValue -> { - Arrays.stream(actionses).forEach(actions -> actions.get().perform()); - }).allMatch(border); + private Actions callDragAndDropByY(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { + return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByY(src + step, dst, step, + actions.sendKeys(key).clickAndHold(element).moveByOffset(0, step * 2), key, element) + : actions.sendKeys(key, key); } } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java index e39fae8f..085efada 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java @@ -6,16 +6,12 @@ import com.qreal.wmp.uitesting.dia.Pallete; import com.qreal.wmp.uitesting.dia.PropertyEditor; import com.qreal.wmp.uitesting.dia.Scene; -import com.qreal.wmp.uitesting.dia.SceneWindow; import io.github.bonigarcia.wdm.ChromeDriverManager; -import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; @@ -39,9 +35,6 @@ public class DiaTest { @Autowired private PropertyEditor propertyEditor; - @Autowired - private SceneWindow scw; - private WebDriver driver; /** Setup ChromeDriverManager. */ @@ -76,25 +69,17 @@ public void remove() { assert !scene.exist(sceneElement); } - /** Move element on the scene by offsets. */ - @Test - public void move() { - final SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); - final Dimension oldPosition = scene.getPosition(sceneElement); - scene.moveElement(sceneElement, 500, 100); - final Dimension newPosition = scene.getPosition(sceneElement); - assert (oldPosition.getWidth() + 500 == newPosition.getWidth()) - && (oldPosition.getHeight() + 100 == newPosition.getHeight()); - } - /** Add two elements and link them. */ @Test public void addLink() { - final SelenideElement initNode = scene.dragAndDrop(pallete.getElement("InitialNode")); - scene.moveElement(initNode, 100, 100); - final SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("FinalNode")); - SelenideElement link = scene.addLink(initNode, finalNode); + final SelenideElement initNode = scene.dragAndDrop(pallete.getElement("InitialNode"), 4, 4); + final SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("FinalNode"), 4, 70); + final SelenideElement motor = scene.dragAndDrop(pallete.getElement("TrikV6EnginesForward"), 4, 7); + SelenideElement link = scene.addLink(initNode, motor); + SelenideElement link2 = scene.addLink(motor, finalNode); + scene.moveToCell(motor, 72, 64); assert scene.exist(link); + assert scene.exist(link2); } /** Set property 'Ports' of motor forward item to '123' and checks that all is correct. */ @@ -106,15 +91,16 @@ public void propertyEditor() { assert propertyEditor.getProperty("Ports").equals("123"); } + /** Move element to cell. */ @Test - public void sceneWindow() { + public void moveElement() { final SelenideElement motor = scene.dragAndDrop(pallete.getElement("TrikV6EnginesForward")); - scw.move(motor, new Dimension(1000, 1000), driver); - assert scene.getPosition(motor).getWidth() == 1000 && scene.getPosition(motor).getHeight() == 1000; - scw.move(motor, new Dimension(1800, 1600), driver); - assert scene.getPosition(motor).getWidth() == 1800 && scene.getPosition(motor).getHeight() == 1600; - scw.move(motor, new Dimension(1000, 1000), driver); - assert scene.getPosition(motor).getWidth() == 1000 && scene.getPosition(motor).getHeight() == 1000; + scene.moveToCell(motor, 40, 40); + assert scene.getCell(motor).getWidth() == 40 && scene.getCell(motor).getHeight() == 40; + scene.moveToCell(motor, 72, 64); + assert scene.getCell(motor).getWidth() == 72 && scene.getCell(motor).getHeight() == 64; + scene.moveToCell(motor, 0, 0); + assert scene.getCell(motor).getWidth() == 0 && scene.getCell(motor).getHeight() == 0; } /** Close the browser. */ From 3fb78a30bbc883e30be88e2d1a9d465310f69412 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Tue, 22 Nov 2016 20:28:07 +0300 Subject: [PATCH 11/40] Create testspace for tasting 1. Add test with 3 nodes and 2 links 2. Add Exception for authorization --- .../com/qreal/wmp/uitesting/auth/Auther.java | 10 ++- .../com/qreal/wmp/uitesting/auth/Opener.java | 22 ++++-- .../com/qreal/wmp/uitesting/dia/Pallete.java | 3 +- .../exceptions/WrongAuthException.java | 8 +++ .../uitesting/auth/innertests}/AuthTest.java | 23 ++++-- .../uitesting/auth/innertests}/DiaTest.java | 12 ++-- .../testspace/DiagramConstructingTest.java | 70 +++++++++++++++++++ 7 files changed, 129 insertions(+), 19 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java rename {UI-testing/src/test/java/com/qreal/wmp/uitesting/auth => ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests}/AuthTest.java (83%) rename {UI-testing/src/test/java/com/qreal/wmp/uitesting/auth => ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests}/DiaTest.java (91%) create mode 100644 ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/testspace/DiagramConstructingTest.java 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/auth/Auther.java index ca498c74..f2730e16 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java @@ -1,5 +1,6 @@ package com.qreal.wmp.uitesting.auth; +import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import org.openqa.selenium.By; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,8 +8,10 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; +import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.open; +import static com.sun.tools.doclint.Entity.exist; /** Used for authentication in current browser session. */ @Service @@ -25,15 +28,18 @@ public class Auther { * @param username login * @param password password * */ - public void auth(final String username, final String password) { + public void auth(final String username, final String password) throws WrongAuthException { open(env.getProperty("auth")); $(By.name("username")).setValue(username); $(By.name("password")).setValue(password); $("[type=\"submit\"]").click(); + if ($(byText("Password or login wrong")).exists()) { + throw new WrongAuthException(username, password); + } logger.info("Authentication with login: {} and password: {}", username, password); } - public void auth() { + public void auth() throws WrongAuthException { auth("123", "123"); } } 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/auth/Opener.java index bd4a210c..dadcc1b2 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java @@ -1,5 +1,6 @@ package com.qreal.wmp.uitesting.auth; +import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -31,12 +32,17 @@ public class Opener { * @param page must be one of the keys from pages.property. */ public void open(final String page) { - com.codeborne.selenide.Selenide.open(env.getProperty(page)); - if ($(byText("Sign in to continue to Auth")).exists()) { - logger.info("Fail with open page {}. Try to login.", env.getProperty(page)); - auther.auth(); + try { + cleanOpen(page); + if ($(byText("Sign in to continue to Auth")).exists()) { + logger.info("Fail with open page {}. Try to login.", env.getProperty(page)); + auther.auth(); + } + cleanOpen(page); + } catch (WrongAuthException e) { + logger.error("Opener fails: " + e.getMessage()); + throw new RuntimeException(e.getMessage()); } - com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); } @@ -46,7 +52,11 @@ public void open(final String page) { * @param page must be one of the keys from pages.property. */ public void cleanOpen(final String page) { - com.codeborne.selenide.Selenide.open(env.getProperty(page)); + try { + com.codeborne.selenide.Selenide.open(env.getProperty(page)); + } catch (NullPointerException e) { + throw new NullPointerException(page + " is not linked with a url"); + } logger.info("Open page {}", env.getProperty(page)); } } diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java index f89e13a8..77de4679 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java @@ -2,6 +2,7 @@ import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -25,7 +26,7 @@ public class Pallete { * @param elementName name of block * @return block */ - public SelenideElement getElement(final String elementName) { + public SelenideElement getElement(final String elementName) throws NoSuchElementException { final SelenideElement element = $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); logger.info("Get element {} from Palette", element); return element; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java new file mode 100644 index 00000000..b1b51d7e --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java @@ -0,0 +1,8 @@ +package com.qreal.wmp.uitesting.exceptions; + +public class WrongAuthException extends Exception { + + public WrongAuthException(String login, String password) { + super("Unable to authorize with login: " + login + " and password: " + password); + } +} diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/AuthTest.java similarity index 83% rename from UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java rename to ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/AuthTest.java index 1b1a039d..807a3897 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/AuthTest.java @@ -1,7 +1,10 @@ -package com.qreal.wmp.uitesting.auth; +package com.qreal.wmp.uitesting.auth.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.config.AppInit; +import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; @@ -51,10 +54,14 @@ public void runDriver() { */ @Test public void authTest() { - opener.cleanOpen("auth"); - assert inAuthPage(); - auther.auth(); - $(byText("OAuth Server")).waitUntil(appear, 5000); + try { + opener.cleanOpen("auth"); + assert inAuthPage(); + auther.auth(); + assert $(byText("OAuth Server")).waitUntil(appear, 5000).exists(); + } catch (WrongAuthException e) { + System.err.println(e.getMessage()); + } } /** @@ -68,7 +75,11 @@ public void authWrongTest() { final char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); final String wrongLogin = RandomStringUtils.random(20, alphabet); final String wrongPassword = RandomStringUtils.random(20, alphabet); - auther.auth(wrongLogin, wrongPassword); + try { + auther.auth(wrongLogin, wrongPassword); + } catch (WrongAuthException e) { + e.printStackTrace(); + } $(byText("Password or login wrong")).waitUntil(appear, 5000); } diff --git a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/DiaTest.java similarity index 91% rename from UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java rename to ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/DiaTest.java index 085efada..ddd6457a 100644 --- a/UI-testing/src/test/java/com/qreal/wmp/uitesting/auth/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/innertests/DiaTest.java @@ -1,7 +1,8 @@ -package com.qreal.wmp.uitesting.auth; +package com.qreal.wmp.uitesting.auth.innertests; import com.codeborne.selenide.SelenideElement; import com.codeborne.selenide.WebDriverRunner; +import com.qreal.wmp.uitesting.auth.Opener; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.Pallete; import com.qreal.wmp.uitesting.dia.PropertyEditor; @@ -12,13 +13,17 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.interactions.Actions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; +import static com.codeborne.selenide.Selenide.$; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) public class DiaTest { @@ -55,9 +60,8 @@ public void runDriver() { /** Drag element from pallete and drop on the scene. */ @Test public void dragAndDrop() { - final SelenideElement palleteElement = pallete.getElement("InitialNode"); - final SelenideElement sceneElement = scene.dragAndDrop(palleteElement); - assert scene.exist(sceneElement); + final SelenideElement initialNode = scene.dragAndDrop(pallete.getElement("InitialNode")); + assert scene.exist(initialNode); } /** Remove element from scene. */ 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/auth/testspace/DiagramConstructingTest.java new file mode 100644 index 00000000..7a75f0dd --- /dev/null +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/auth/testspace/DiagramConstructingTest.java @@ -0,0 +1,70 @@ +package com.qreal.wmp.uitesting.auth.testspace; + +import com.codeborne.selenide.SelenideElement; +import com.codeborne.selenide.WebDriverRunner; +import com.qreal.wmp.uitesting.auth.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; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) +public class DiagramConstructingTest { + + @Autowired + private Opener opener; + + @Autowired + private Pallete pallete; + + @Autowired + private Scene scene; + + @Autowired + private PropertyEditor propertyEditor; + + private WebDriver driver; + + /** Setup ChromeDriverManager. */ + @BeforeClass + public static void init() { + ChromeDriverManager.getInstance().setup(); + } + + @Before + public void runDriver() { + driver = new ChromeDriver(); + WebDriverRunner.setWebDriver(driver); + opener.open("editor"); + scene.updateWebdriver(driver); + } + + @Test + public void diagramThreeNodesTwoLinks() { + final SelenideElement node1 = scene.dragAndDrop(pallete.getElement("InitialNode"), 4, 4); + final SelenideElement node2 = scene.dragAndDrop(pallete.getElement("InitialNode"), 10, 4); + final SelenideElement node3 = scene.dragAndDrop(pallete.getElement("InitialNode"), 16, 4); + scene.addLink(node1, node2); + scene.addLink(node2, node3); + } + + @After + public void stopDriver() { + scene.clean(); + driver.close(); + } + +} From d44c0953eca86978a3d808c3031acb53e15c622e Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Wed, 23 Nov 2016 03:07:38 +0300 Subject: [PATCH 12/40] Fix movement bug 1. Fix movement bug 2. Fix remove element bug --- .travis.yml | 2 +- .../com/qreal/wmp/uitesting/auth/Auther.java | 1 - .../com/qreal/wmp/uitesting/dia/Pallete.java | 4 ++- .../com/qreal/wmp/uitesting/dia/Scene.java | 29 +++++++++++++------ .../qreal/wmp/uitesting/dia/SceneWindow.java | 17 +++++++++-- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56352655..4351b809 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,7 +70,7 @@ script: - cd ../ui-testing - mvn test -P travis & - - sleep 90 + - sleep 150 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/auth/Auther.java index f2730e16..f66a3a09 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java @@ -11,7 +11,6 @@ import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.open; -import static com.sun.tools.doclint.Entity.exist; /** Used for authentication in current browser session. */ @Service diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java index 77de4679..fafa9316 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java +++ b/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import static com.codeborne.selenide.Selectors.withText; import static com.codeborne.selenide.Selenide.$; /** @@ -27,8 +28,9 @@ public class Pallete { * @return block */ public SelenideElement getElement(final String elementName) throws NoSuchElementException { - final SelenideElement element = $(By.cssSelector(selector + " div[data-type=\"" + elementName + "\"]")); + final SelenideElement element = $(By.cssSelector(selector)).find(withText(elementName)); logger.info("Get element {} from Palette", element); return element; } + } 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 a51f1371..871ba2f9 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 @@ -9,10 +9,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; @@ -28,7 +25,7 @@ public class Scene { private static final Logger logger = LoggerFactory.getLogger(Pallete.class); - private final Set elements = new HashSet<>(); + private Set elements = new HashSet<>(); private WebDriver driver; @@ -104,19 +101,26 @@ public void remove(final SelenideElement selenideElement) { elements.remove(selenideElement); new Actions(driver).contextClick(selenideElement).build().perform(); $(By.id("scene-context-menu")).click(); + Set newSet = new HashSet<>(); + $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(x -> x != null).forEach(newSet::add); + elements = newSet; + } /** Remove all elements from the scene. */ public void clean() { - $$(By.cssSelector(selector + " #v_7 > *")).forEach(element -> remove(element)); - elements.clear(); - logger.info("Clean scene"); + if (!elements.isEmpty()) { + remove(elements.stream().findFirst().get()); + clean(); + } else { + logger.info("Clean scene"); + } } /** Add link between two elements. */ public SelenideElement addLink(final SelenideElement source, final SelenideElement target) { final SelenideElement begin = $(By.cssSelector(selector + " #" + source.attr("id") + " .outPorts")); - logger.info("Begin element {}", begin); + logger.info("Begin element {}, end element {} ", begin, target); new Actions(driver).dragAndDrop(begin, target).build().perform(); SelenideElement newEl = updateScene().get(); logger.info("Add link {}", newEl); @@ -124,6 +128,13 @@ public SelenideElement addLink(final SelenideElement source, final SelenideEleme return newEl; } + /** Return all blocks. */ + public List getAllBlocks() { + List result = new ArrayList<>(); + elements.stream().filter(x -> !x.attr("class").equals("link")).forEach(result::add); + return result; + } + /** Return new element of the scene. */ private Optional updateScene() { final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); 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 748acbe8..cf88c6e9 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 @@ -7,6 +7,8 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; +import java.util.List; + import static com.codeborne.selenide.Selenide.$; /** @@ -91,14 +93,25 @@ 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(step * 2, 0), key, element) + actions.sendKeys(key).clickAndHold(element).moveByOffset(jump(elements, 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, step * 2), key, element) + actions.sendKeys(key).clickAndHold(element).moveByOffset(0, jump(elements, step, src)), key, element) : actions.sendKeys(key, key); } + + private int jump(final List elements, int step, int current) { + if (elements.stream().filter(x -> Math.abs(current - scene.getPosition(x).getWidth()) + < Math.abs(2 * step)).findFirst().isPresent()) { + return step + jump(elements, step, step + current); + } else { + return step; + } + } } From a55e457c5695d3501c36d9e82c0f81eb790eb60b Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Wed, 23 Nov 2016 11:27:54 +0300 Subject: [PATCH 13/40] Change namespace of nodes 1. Change names of nodes to string values, which are shown in browser 2. Add moveSomeNodes test --- .travis.yml | 2 +- ui-testing/pom.xml | 1 + .../com/qreal/wmp/uitesting/auth/Auther.java | 0 .../com/qreal/wmp/uitesting/auth/Opener.java | 5 ++- .../qreal/wmp/uitesting/config/AppInit.java | 0 .../qreal/wmp/uitesting/config/DevConfig.java | 0 .../com/qreal/wmp/uitesting/dia/Pallete.java | 0 .../wmp/uitesting/dia/PropertyEditor.java | 15 +++++-- .../com/qreal/wmp/uitesting/dia/Scene.java | 0 .../qreal/wmp/uitesting/dia/SceneWindow.java | 0 .../exceptions/WrongAuthException.java | 3 +- .../src/main/resources/pages.properties | 0 .../uitesting/auth/innertests/AuthTest.java | 2 +- .../uitesting/auth/innertests/DiaTest.java | 18 ++++---- .../testspace/DiagramConstructingTest.java | 42 ++++++++++++++----- 15 files changed, 59 insertions(+), 29 deletions(-) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/auth/Auther.java (100%) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java (89%) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java (100%) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java (100%) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java (100%) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java (68%) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java (100%) rename {UI-testing => ui-testing}/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java (100%) rename {UI-testing => ui-testing}/src/main/resources/pages.properties (100%) diff --git a/.travis.yml b/.travis.yml index 4351b809..96a7a826 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ install: #install and run tests and run style checking - mvn install -P travis - cd ui-testing - - mvn install -DskipTests + - mvn clean install -DskipTests - cd .. script: diff --git a/ui-testing/pom.xml b/ui-testing/pom.xml index 1fd6d673..ac451c60 100644 --- a/ui-testing/pom.xml +++ b/ui-testing/pom.xml @@ -52,6 +52,7 @@ exec-maven-plugin org.codehaus.mojo + 1.5.0 Check services 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/auth/Auther.java similarity index 100% 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/auth/Auther.java 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/auth/Opener.java similarity index 89% 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/auth/Opener.java index dadcc1b2..4ec5f676 100644 --- a/UI-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/auth/Opener.java @@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; +import org.springframework.security.access.AccessDeniedException; import org.springframework.stereotype.Service; import static com.codeborne.selenide.Selectors.byText; @@ -41,7 +42,7 @@ public void open(final String page) { cleanOpen(page); } catch (WrongAuthException e) { logger.error("Opener fails: " + e.getMessage()); - throw new RuntimeException(e.getMessage()); + throw new AccessDeniedException(e.getMessage()); } logger.info("Open page {}", env.getProperty(page)); } @@ -55,7 +56,7 @@ public void cleanOpen(final String page) { try { com.codeborne.selenide.Selenide.open(env.getProperty(page)); } catch (NullPointerException e) { - throw new NullPointerException(page + " is not linked with a url"); + throw new IllegalArgumentException(page + " is not linked with a url"); } logger.info("Open page {}", env.getProperty(page)); } diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java similarity index 100% rename from UI-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java similarity index 100% rename from UI-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java diff --git a/UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java similarity index 100% rename from UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java 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 similarity index 68% rename from UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java index 5883321b..12fd9ae3 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 @@ -2,6 +2,9 @@ import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.util.List; @@ -17,13 +20,17 @@ public class PropertyEditor { private static final String selector = "#property_table"; + 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) { + public void setProperty(final String propertyName, final String propertyValue) throws NoSuchElementException { getInputOfElement(propertyName).setValue(propertyValue); + logger.info("Set property {} to {}", propertyName, propertyValue); } /** Return the value of property by name. */ - public String getProperty(final String propertyName) { + public String getProperty(final String propertyName) throws NoSuchElementException { + logger.info("Get value of preperty {}", propertyName); return getInputOfElement(propertyName).getValue(); } @@ -32,7 +39,9 @@ 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(); - assert indexOfNeeded.isPresent(); + if (!indexOfNeeded.isPresent()) { + throw new NoSuchElementException("There is no property with name " + propertyName); + } return $(By.cssSelector(selector + " tbody > * > *:nth-of-type(" + (indexOfNeeded.getAsInt() + 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 similarity index 100% rename from UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java 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 similarity index 100% rename from UI-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java index b1b51d7e..ec2aa1d1 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/WrongAuthException.java @@ -1,8 +1,9 @@ package com.qreal.wmp.uitesting.exceptions; +/** Throw if we cannot authorize. */ public class WrongAuthException extends Exception { - public WrongAuthException(String login, String password) { + public WrongAuthException(final String login, final String password) { super("Unable to authorize with login: " + login + " and password: " + password); } } diff --git a/UI-testing/src/main/resources/pages.properties b/ui-testing/src/main/resources/pages.properties similarity index 100% rename from UI-testing/src/main/resources/pages.properties rename to ui-testing/src/main/resources/pages.properties 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/auth/innertests/AuthTest.java index 807a3897..897750ed 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/auth/innertests/AuthTest.java @@ -78,7 +78,7 @@ public void authWrongTest() { try { auther.auth(wrongLogin, wrongPassword); } catch (WrongAuthException e) { - e.printStackTrace(); + System.err.println(e.getMessage()); } $(byText("Password or login wrong")).waitUntil(appear, 5000); } 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/auth/innertests/DiaTest.java index ddd6457a..07e446d3 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/auth/innertests/DiaTest.java @@ -13,17 +13,13 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.interactions.Actions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import static com.codeborne.selenide.Selenide.$; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) public class DiaTest { @@ -60,14 +56,14 @@ public void runDriver() { /** Drag element from pallete and drop on the scene. */ @Test public void dragAndDrop() { - final SelenideElement initialNode = scene.dragAndDrop(pallete.getElement("InitialNode")); + final SelenideElement initialNode = scene.dragAndDrop(pallete.getElement("Initial Node")); assert scene.exist(initialNode); } /** Remove element from scene. */ @Test public void remove() { - final SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("InitialNode")); + final SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("Initial Node")); assert scene.exist(sceneElement); scene.remove(sceneElement); assert !scene.exist(sceneElement); @@ -76,9 +72,9 @@ public void remove() { /** Add two elements and link them. */ @Test public void addLink() { - final SelenideElement initNode = scene.dragAndDrop(pallete.getElement("InitialNode"), 4, 4); - final SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("FinalNode"), 4, 70); - final SelenideElement motor = scene.dragAndDrop(pallete.getElement("TrikV6EnginesForward"), 4, 7); + final SelenideElement initNode = scene.dragAndDrop(pallete.getElement("Initial Node"), 4, 4); + final SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("Final Node"), 4, 70); + final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward"), 4, 7); SelenideElement link = scene.addLink(initNode, motor); SelenideElement link2 = scene.addLink(motor, finalNode); scene.moveToCell(motor, 72, 64); @@ -89,7 +85,7 @@ public void addLink() { /** Set property 'Ports' of motor forward item to '123' and checks that all is correct. */ @Test public void propertyEditor() { - final SelenideElement motor = scene.dragAndDrop(pallete.getElement("TrikV6EnginesForward")); + final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); motor.click(); propertyEditor.setProperty("Ports", "123"); assert propertyEditor.getProperty("Ports").equals("123"); @@ -98,7 +94,7 @@ public void propertyEditor() { /** Move element to cell. */ @Test public void moveElement() { - final SelenideElement motor = scene.dragAndDrop(pallete.getElement("TrikV6EnginesForward")); + final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); scene.moveToCell(motor, 40, 40); assert scene.getCell(motor).getWidth() == 40 && scene.getCell(motor).getHeight() == 40; scene.moveToCell(motor, 72, 64); 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/auth/testspace/DiagramConstructingTest.java index 7a75f0dd..aa22549b 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/auth/testspace/DiagramConstructingTest.java @@ -5,7 +5,6 @@ import com.qreal.wmp.uitesting.auth.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; @@ -20,6 +19,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; +import java.util.ArrayList; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) public class DiagramConstructingTest { @@ -33,11 +34,11 @@ public class DiagramConstructingTest { @Autowired private Scene scene; - @Autowired - private PropertyEditor propertyEditor; - private WebDriver driver; + private ArrayList elements; + private ArrayList links; + /** Setup ChromeDriverManager. */ @BeforeClass public static void init() { @@ -50,15 +51,32 @@ public void runDriver() { WebDriverRunner.setWebDriver(driver); opener.open("editor"); scene.updateWebdriver(driver); + + elements = new ArrayList<>(); + links = new ArrayList<>(); + + elements.add(scene.dragAndDrop(pallete.getElement("Initial Node"), 4, 4)); + elements.add(scene.dragAndDrop(pallete.getElement("Motors Forward"), 10, 4)); + links.add(scene.addLink(elements.get(0), elements.get(1))); + elements.add(scene.dragAndDrop(pallete.getElement("Painter Color"), 16, 4)); + links.add(scene.addLink(elements.get(1), elements.get(2))); + elements.add(scene.dragAndDrop(pallete.getElement("Timer"), 22, 4)); + links.add(scene.addLink(elements.get(2), elements.get(3))); + elements.add(scene.dragAndDrop(pallete.getElement("Final Node"), 28, 4)); + links.add(scene.addLink(elements.get(3), elements.get(4))); } @Test - public void diagramThreeNodesTwoLinks() { - final SelenideElement node1 = scene.dragAndDrop(pallete.getElement("InitialNode"), 4, 4); - final SelenideElement node2 = scene.dragAndDrop(pallete.getElement("InitialNode"), 10, 4); - final SelenideElement node3 = scene.dragAndDrop(pallete.getElement("InitialNode"), 16, 4); - scene.addLink(node1, node2); - scene.addLink(node2, node3); + public void digramFiveNodes() { + assert allExist(); + } + + @Test + public void moveSomeNodes() { + scene.moveToCell(elements.get(1), 20, 20); + scene.moveToCell(elements.get(0), 20, 10); + scene.moveToCell(elements.get(1), 0, 20); + assert allExist(); } @After @@ -67,4 +85,8 @@ public void stopDriver() { driver.close(); } + private boolean allExist() { + return elements.stream().allMatch(scene::exist) && links.stream().anyMatch(scene::exist); + } + } From 60a30c63afb549c358fba35c4a29614b323427c0 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 25 Nov 2016 01:46:35 +0300 Subject: [PATCH 14/40] 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 | 8 ++---- .../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, 54 insertions(+), 31 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 (87%) 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 87% 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..a7bfe32c 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; @@ -53,11 +53,7 @@ public void open(final String page) { * @param page must be one of the keys from pages.property. */ public void cleanOpen(final String page) { - try { - com.codeborne.selenide.Selenide.open(env.getProperty(page)); - } catch (NullPointerException e) { - throw new IllegalArgumentException(page + " is not linked with a url"); - } + com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); } } 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(); From 8e6c356c269fb1a01aad954a7f3fcdab6f04754f Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 15 Jan 2017 17:45:20 +0300 Subject: [PATCH 15/40] Add Block and Coordinate classes --- .../qreal/wmp/uitesting/dia/model/Block.java | 37 +++++++++++++++++++ .../wmp/uitesting/dia/model/Coordinate.java | 31 ++++++++++++++++ .../dia/{ => model}/SceneWindow.java | 3 +- .../uitesting/dia/{ => services}/Pallete.java | 2 +- .../dia/{ => services}/PropertyEditor.java | 2 +- .../uitesting/dia/{ => services}/Scene.java | 3 +- .../ElementNotInTheSceneException.java | 9 +++++ .../wmp/uitesting/innertests/DiaTest.java | 22 +++++++++-- .../testspace/DiagramConstructingTest.java | 6 +-- 9 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{ => model}/SceneWindow.java (98%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{ => services}/Pallete.java (95%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{ => services}/PropertyEditor.java (98%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{ => services}/Scene.java (98%) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java new file mode 100644 index 00000000..dd8ac8e3 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java @@ -0,0 +1,37 @@ +package com.qreal.wmp.uitesting.dia.model; + +import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.exceptions.ElementNotInTheSceneException; + +public class Block { + + private final String name; + private final SelenideElement innerSeleniumObject; + private final String type; + + private final Coordinate coordinateOnScene; + + public Block(SelenideElement innerSeleniumObject, String name, String type) throws ElementNotInTheSceneException { + this.name = name; + this.innerSeleniumObject = innerSeleniumObject; + coordinateOnScene = Coordinate.getCoordinateFromSeleniumObject(innerSeleniumObject) + .orElseThrow(ElementNotInTheSceneException::new); + this.type = type; + } + + public SelenideElement getInnerSeleniumObject() { + return innerSeleniumObject; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public Coordinate getCoordinateOnScene() { + return coordinateOnScene; + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java new file mode 100644 index 00000000..ad8ef978 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java @@ -0,0 +1,31 @@ +package com.qreal.wmp.uitesting.dia.model; + + +import com.codeborne.selenide.SelenideElement; + +import java.util.Optional; + +public class Coordinate { + + public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { + final String position = element.attr("transform"); + final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); + return Optional.of(new Coordinate(Integer.valueOf(pairStr[0]) / 25, Integer.valueOf(pairStr[1]) / 25)); + } + + private final int xCell; + private final int yCell; + + public Coordinate(int xCell, int yCell) { + this.xCell = xCell; + this.yCell = yCell; + } + + public int getXCell() { + return xCell; + } + + public int getYCell() { + return yCell; + } +} 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/model/SceneWindow.java similarity index 98% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/SceneWindow.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index b79d4f5b..816c5546 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/model/SceneWindow.java @@ -1,6 +1,7 @@ -package com.qreal.wmp.uitesting.dia; +package com.qreal.wmp.uitesting.dia.model; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.services.Scene; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.Keys; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java similarity index 95% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java index fafa9316..939248b4 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.dia; +package com.qreal.wmp.uitesting.dia.services; import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; 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/services/PropertyEditor.java similarity index 98% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/PropertyEditor.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java index 9c4374f7..84260fbc 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/services/PropertyEditor.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.dia; +package com.qreal.wmp.uitesting.dia.services; import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; 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/services/Scene.java similarity index 98% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/Scene.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index 3f9dfc98..d698fab5 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/services/Scene.java @@ -1,6 +1,7 @@ -package com.qreal.wmp.uitesting.dia; +package com.qreal.wmp.uitesting.dia.services; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.model.SceneWindow; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java new file mode 100644 index 00000000..d007f29a --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java @@ -0,0 +1,9 @@ +package com.qreal.wmp.uitesting.exceptions; + +public class ElementNotInTheSceneException extends Exception { + + public ElementNotInTheSceneException() { + super("It is impossible to get Coordinate of element, which is not on the Scene"); + } + +} diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 0bb80dec..54ef2794 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -4,9 +4,9 @@ import com.codeborne.selenide.WebDriverRunner; 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 com.qreal.wmp.uitesting.dia.services.Pallete; +import com.qreal.wmp.uitesting.dia.services.PropertyEditor; +import com.qreal.wmp.uitesting.dia.services.Scene; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.junit.After; import org.junit.Before; @@ -101,6 +101,22 @@ public void moveElement() { scene.moveToCell(motor, 0, 0); assert scene.getCell(motor).getWidth() == 0 && scene.getCell(motor).getHeight() == 0; } + + /* + @Test + public void test() { + final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); + scene.moveToCell(motor, 30, 40); + + if (driver instanceof JavascriptExecutor) { + ((JavascriptExecutor) driver) + .executeScript("var canvas = document.getElementsByClassName(\"scene-wrapper\")[0]; " + + "var BB=canvas.getBoundingClientRect();" + + "alert(canvas.scrollLeft)"); + // driver.switchTo().alert().accept(); + } + } +*/ /** Close the browser. */ @After diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 6ca6a0a7..2e12672d 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -4,9 +4,9 @@ import com.codeborne.selenide.WebDriverRunner; 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 com.qreal.wmp.uitesting.dia.services.Pallete; +import com.qreal.wmp.uitesting.dia.services.PropertyEditor; +import com.qreal.wmp.uitesting.dia.services.Scene; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.junit.After; import org.junit.Before; From 970860c29579f92b29b7a584ddeeb58eb4b5e464 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Wed, 18 Jan 2017 15:16:24 +0300 Subject: [PATCH 16/40] Add Link and change SelenideElement to links and blocks in scene service --- .../qreal/wmp/uitesting/dia/model/Block.java | 56 ++++---- .../wmp/uitesting/dia/model/Coordinate.java | 58 +++++--- .../qreal/wmp/uitesting/dia/model/Link.java | 38 +++++ .../wmp/uitesting/dia/model/SceneElement.java | 32 +++++ .../wmp/uitesting/dia/model/SceneWindow.java | 61 +++++--- .../wmp/uitesting/dia/services/Scene.java | 134 ++++++++++-------- .../ElementNotInTheSceneException.java | 9 -- .../ElementNotOnTheSceneException.java | 9 ++ .../wmp/uitesting/innertests/DiaTest.java | 42 +++--- .../testspace/DiagramConstructingTest.java | 18 +-- 10 files changed, 285 insertions(+), 172 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java index dd8ac8e3..1feaf33f 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java @@ -1,37 +1,31 @@ package com.qreal.wmp.uitesting.dia.model; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.exceptions.ElementNotInTheSceneException; +import org.openqa.selenium.By; -public class Block { +import static com.codeborne.selenide.Selenide.$; - private final String name; - private final SelenideElement innerSeleniumObject; - private final String type; - - private final Coordinate coordinateOnScene; - - public Block(SelenideElement innerSeleniumObject, String name, String type) throws ElementNotInTheSceneException { - this.name = name; - this.innerSeleniumObject = innerSeleniumObject; - coordinateOnScene = Coordinate.getCoordinateFromSeleniumObject(innerSeleniumObject) - .orElseThrow(ElementNotInTheSceneException::new); - this.type = type; - } - - public SelenideElement getInnerSeleniumObject() { - return innerSeleniumObject; - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public Coordinate getCoordinateOnScene() { - return coordinateOnScene; - } +public class Block extends SceneElement { + + public static final String className = "element devs ImageWithPorts"; + + private final static String portClassName = "port0"; + + private final String name; + + private final SceneElement port; + + public Block(String name, SelenideElement innerSeleniumObject) { + super(innerSeleniumObject); + this.name = name; + this.port = new SceneElement($(innerSeleniumObject.find(By.className(portClassName)))); + } + + public String getName() { + return name; + } + + public SceneElement getPort() { + return port; + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java index ad8ef978..4aee51ff 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java @@ -1,31 +1,43 @@ package com.qreal.wmp.uitesting.dia.model; - import com.codeborne.selenide.SelenideElement; import java.util.Optional; public class Coordinate { - - public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { - final String position = element.attr("transform"); - final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); - return Optional.of(new Coordinate(Integer.valueOf(pairStr[0]) / 25, Integer.valueOf(pairStr[1]) / 25)); - } - - private final int xCell; - private final int yCell; - - public Coordinate(int xCell, int yCell) { - this.xCell = xCell; - this.yCell = yCell; - } - - public int getXCell() { - return xCell; - } - - public int getYCell() { - return yCell; - } + + public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { + final String position = element.attr("transform"); + final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); + return Optional.of(new Coordinate(Integer.valueOf(pairStr[0]), Integer.valueOf(pairStr[1]))); + } + + private final int xAbsolute; + + private final int yAbsolute; + + public Coordinate(int xAbsolute, int yAbsolute) { + this.xAbsolute = xAbsolute; + this.yAbsolute = yAbsolute; + } + + public int getXCell() { + return xAbsolute / 25; + } + + public int getYCell() { + return yAbsolute / 25; + } + + public int getXAbsolute() { + return xAbsolute; + } + + public int getYAbsolute() { + return yAbsolute; + } + + public boolean equals(final Coordinate other) { + return xAbsolute == other.getXAbsolute() && yAbsolute == other.getYAbsolute(); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java new file mode 100644 index 00000000..e15507a2 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java @@ -0,0 +1,38 @@ +package com.qreal.wmp.uitesting.dia.model; + +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.By; + +import static com.codeborne.selenide.Selenide.$; + +public class Link extends SceneElement { + + private static final String sourcePointClassName = "marker-source"; + + private static final String targetPointClassName = "marker-target"; + + private final String name; + + private final SceneElement source; + + private final SceneElement target; + + public Link(String name, SelenideElement innerSeleniumObject) { + super(innerSeleniumObject); + this.name = name; + this.source = new SceneElement($(innerSeleniumObject.find(By.className(sourcePointClassName)))); + this.target = new SceneElement($(innerSeleniumObject.find(By.className(targetPointClassName)))); + } + + public String getName() { + return name; + } + + public SceneElement getSource() { + return source; + } + + public SceneElement getTarget() { + return target; + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java new file mode 100644 index 00000000..e08bcc5a --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java @@ -0,0 +1,32 @@ +package com.qreal.wmp.uitesting.dia.model; + +import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; + +public class SceneElement { + + private final SelenideElement innerSeleniumElement; + + private String type; + + /** + * Describes any element on the Scene. + * */ + public SceneElement(SelenideElement innerSeleniumObject) { + this.innerSeleniumElement = innerSeleniumObject; + this.type = innerSeleniumObject.attr("class"); + } + + public SelenideElement getInnerSeleniumElement() { + return innerSeleniumElement; + } + + public Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException { + return Coordinate.getCoordinateFromSeleniumObject( + innerSeleniumElement).orElseThrow(ElementNotOnTheSceneException::new); + } + + public String getType() { + return type; + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index 816c5546..3f567868 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -2,6 +2,7 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.services.Scene; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.Keys; @@ -44,31 +45,27 @@ public SceneWindow(final Scene scene, final WebDriver driver) { * @param element element to move * @param dist position to move */ - public void move(final SelenideElement element, final Dimension dist) { - Dimension src = scene.getPosition(element); - focus(src); + public void move(final Block element, final Coordinate dist) throws ElementNotOnTheSceneException { + Coordinate src = element.getCoordinateOnScene(); + //focus(src); - if (src.getWidth() < dist.getWidth()) { - callDragAndDropByX(src.getWidth(), dist.getWidth(), stepHor, - new Actions(driver), Keys.ARROW_RIGHT, element).perform(); + if (src.getXAbsolute() < dist.getXAbsolute()) { + callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), stepHor, + new Actions(driver), Keys.ARROW_RIGHT, element.getInnerSeleniumElement()).perform(); } else { - callDragAndDropByX(src.getWidth(), dist.getWidth(), -stepHor, - new Actions(driver), Keys.ARROW_LEFT, element).perform(); + callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), -stepHor, + new Actions(driver), Keys.ARROW_LEFT, element.getInnerSeleniumElement()).perform(); } - if (src.getHeight() < dist.getHeight()) { - callDragAndDropByY(src.getHeight(), dist.getHeight(), stepVert, - new Actions(driver), Keys.ARROW_DOWN, element).perform(); + if (src.getYAbsolute() < dist.getYAbsolute()) { + callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), stepVert, + new Actions(driver), Keys.ARROW_DOWN, element.getInnerSeleniumElement()).perform(); } else { - callDragAndDropByY(src.getHeight(), dist.getHeight(), -stepVert, - new Actions(driver), Keys.ARROW_UP, element).perform(); + callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), -stepVert, + new Actions(driver), Keys.ARROW_UP, element.getInnerSeleniumElement()).perform(); } - Dimension currentPosition = scene.getPosition(element); - new Actions(driver).release().clickAndHold(element).moveByOffset(dist.getWidth() - currentPosition.getWidth(), - dist.getHeight() - currentPosition.getHeight()).release().perform(); - currentPosition = scene.getPosition(element); - if (!currentPosition.equals(dist)) { + if (!finalJump(element, dist).equals(dist)) { move(element, dist); } } @@ -94,25 +91,43 @@ 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(); + final List elements = scene.getBlocks(); return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByX(src + step, dst, step, 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(); + final List elements = scene.getBlocks(); return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByY(src + step, dst, step, 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) { - if (elements.stream().filter(x -> Math.abs(current - scene.getPosition(x).getWidth()) - < Math.abs(2 * step)).findFirst().isPresent()) { + private int jump(final List elements, int step, int current) { + if (elements.stream().filter(x -> { + try { + return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) + < Math.abs(2 * step); + } catch (ElementNotOnTheSceneException e) { + e.printStackTrace(); + } + return false; + }).findFirst().isPresent()) { return step + jump(elements, step, step + current); } else { return step; } } + + private Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTheSceneException { + + Coordinate currentPosition = block.getCoordinateOnScene(); + + new Actions(driver).release().clickAndHold(block.getInnerSeleniumElement()).moveByOffset( + dist.getXAbsolute() - currentPosition.getXAbsolute(), + dist.getYAbsolute() - currentPosition.getYAbsolute()).release().perform(); + + return block.getCoordinateOnScene(); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index d698fab5..743cabcb 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java @@ -1,9 +1,10 @@ package com.qreal.wmp.uitesting.dia.services; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.model.SceneWindow; +import com.qreal.wmp.uitesting.dia.model.*; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; +import org.openqa.selenium.NotFoundException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; @@ -11,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.*; +import java.util.stream.Collectors; import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; @@ -26,7 +28,9 @@ public class Scene { private static final Logger logger = LoggerFactory.getLogger(Pallete.class); - private Set elements = new HashSet<>(); + private Set blocks = new HashSet<>(); + + private Set links = new HashSet<>(); private WebDriver driver; @@ -41,12 +45,13 @@ public void updateWebdriver(final WebDriver webDriver) { * @param element chosen web element * @return element from scene */ - public SelenideElement dragAndDrop(final SelenideElement element) { + public Block dragAndDrop(final SelenideElement element) { element.dragAndDropTo(selector); - final SelenideElement newEl = updateScene().get(); - elements.add(newEl); + final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); + Block newBlock = new Block("name", newEl); + blocks.add(newBlock); logger.info("Add element {} to scene", newEl); - return newEl; + return newBlock; } /** @@ -57,91 +62,98 @@ public SelenideElement dragAndDrop(final SelenideElement element) { * @param cell_y y-coordinate of cell * @return element from scene */ - public SelenideElement dragAndDrop(final SelenideElement element, int cell_x, int cell_y) { - SelenideElement newEl = dragAndDrop(element); - moveToCell(newEl, cell_x, cell_y); - return newEl; + public Block dragAndDrop(final SelenideElement element, int cell_x, int cell_y) { + Block newBlock = dragAndDrop(element); + moveToCell(newBlock, cell_x, cell_y); + return newBlock; } /** Move element to cell. */ - public void moveToCell(final SelenideElement element, final int cell_x, final int cell_y) { + public void moveToCell(final Block block, final int cell_x, final int cell_y) { SceneWindow sceneWindow = new SceneWindow(this, driver); - logger.info("Move element {} to cell ({}, {})", element, cell_x, cell_y); - sceneWindow.move(element, new Dimension(cell_x * 25, cell_y * 25)); + logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); + try { + sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); + } catch (ElementNotOnTheSceneException e) { + e.printStackTrace(); + } } - /** Focus the element. */ - public void focus(final SelenideElement element) { + /** Focus the element. + public void focus(final SceneElement element) { SceneWindow sceneWindow = new SceneWindow(this, driver); logger.info("Focus on the element {}", element); - sceneWindow.focus(getPosition(element)); - } - - /** Return the cell where element hold. */ - public Dimension getCell(SelenideElement element) { - Dimension result = getPosition(element); - return new Dimension(result.getWidth() / 25, result.getHeight() / 25); - } + sceneWindow.focus(new Dimension(element.getCoordinateOnScene().getXAbsolute(), + element.getCoordinateOnScene().getYAbsolute())); + }*/ /** Check if element exist on the scene. */ - public boolean exist(SelenideElement selenideElement) { - return elements.stream().anyMatch(element -> element.equals(selenideElement)); - } - - /** Return the position of element in coordinates. */ - public Dimension getPosition(final SelenideElement selenideElement) { - final String position = selenideElement.attr("transform"); - final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); - return new Dimension(Integer.valueOf(pairStr[0]), Integer.valueOf(pairStr[1])); + public boolean exist(SceneElement element) { + return blocks.stream().anyMatch(element::equals) || links.stream().anyMatch(element::equals); } - + /** Remove element from the scene. */ - public void remove(final SelenideElement selenideElement) { - assert selenideElement != null; - logger.info("Remove element {} form scene", selenideElement); - elements.remove(selenideElement); - new Actions(driver).contextClick(selenideElement).build().perform(); + public void remove(final SceneElement sceneElement) { + assert sceneElement != null; + logger.info("Remove element {} form scene", sceneElement); + //elements.remove(selenideElement); + new Actions(driver).contextClick(sceneElement.getInnerSeleniumElement()).build().perform(); $(By.id("scene-context-menu")).click(); - Set newSet = new HashSet<>(); - $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(x -> x != null).forEach(newSet::add); - elements = newSet; - + blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(Block.className::equals).map(x -> + new Block("name", x)).collect(Collectors.toSet()); + links = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(Block.className::equals).map(x -> + new Link("name", x)).collect(Collectors.toSet()); + } /** Remove all elements from the scene. */ public void clean() { - if (!elements.isEmpty()) { - remove(elements.stream().findFirst().get()); + if (!links.isEmpty()) { + remove(links.stream().findFirst().get()); clean(); } else { - logger.info("Clean scene"); + if (!blocks.isEmpty()) { + remove(blocks.stream().findFirst().get()); + clean(); + } else { + logger.info("Clean scene"); + } } } /** Add link between two elements. */ - public SelenideElement addLink(final SelenideElement source, final SelenideElement target) { - final SelenideElement begin = $(By.cssSelector(selector + " #" + source.attr("id") + " .outPorts")); + public Link addLink(final Block source, final Block target) { + final SelenideElement begin = $(By.cssSelector(selector + " #" + + source.getInnerSeleniumElement().attr("id") + " .outPorts")); logger.info("Begin element {}, end element {} ", begin, target); - new Actions(driver).dragAndDrop(begin, target).build().perform(); - SelenideElement newEl = updateScene().get(); + new Actions(driver).dragAndDrop(source.getPort().getInnerSeleniumElement(), + target.getInnerSeleniumElement()).build().perform(); + SelenideElement newEl = updateLinks().get(); logger.info("Add link {}", newEl); - elements.add(newEl); - return newEl; + Link res = new Link("link", newEl); + links.add(res); + return res; } /** Return all blocks. */ - public List getAllBlocks() { - List result = new ArrayList<>(); - elements.stream().filter(x -> !x.attr("class").equals("link")).forEach(result::add); - return result; + public List getBlocks() { + return blocks.stream().collect(Collectors.toList()); } - + /** Return new element of the scene. */ - private Optional updateScene() { + private Optional updateBlocks() { final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); - return allElements.stream().filter(htmlElement -> !elements.stream().anyMatch(selenideElement -> - htmlElement.attr("id").equals(selenideElement.attr("id")))).findFirst(); - + return allElements.stream().filter(htmlElement -> + htmlElement.attr("class").contains("element devs ImageWithPorts") && + !blocks.stream().anyMatch(block -> + block.getInnerSeleniumElement().attr("id").equals(htmlElement.attr("id")))).findFirst(); + } + + private Optional updateLinks() { + final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); + return allElements.stream().filter(htmlElement -> htmlElement.attr("class").contains("link") && + !links.stream().anyMatch(link -> + htmlElement.attr("id").equals(link.getInnerSeleniumElement().attr("id")))).findFirst(); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java deleted file mode 100644 index d007f29a..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotInTheSceneException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.qreal.wmp.uitesting.exceptions; - -public class ElementNotInTheSceneException extends Exception { - - public ElementNotInTheSceneException() { - super("It is impossible to get Coordinate of element, which is not on the Scene"); - } - -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java new file mode 100644 index 00000000..c264ebbc --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java @@ -0,0 +1,9 @@ +package com.qreal.wmp.uitesting.exceptions; + +public class ElementNotOnTheSceneException extends Exception { + + public ElementNotOnTheSceneException() { + super("It is impossible to get Coordinate of element, which is not on the Scene"); + } + +} diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 54ef2794..9e4ff5ef 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -4,9 +4,12 @@ import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; +import com.qreal.wmp.uitesting.dia.model.Block; +import com.qreal.wmp.uitesting.dia.model.Link; import com.qreal.wmp.uitesting.dia.services.Pallete; import com.qreal.wmp.uitesting.dia.services.PropertyEditor; import com.qreal.wmp.uitesting.dia.services.Scene; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.junit.After; import org.junit.Before; @@ -16,6 +19,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -56,14 +60,14 @@ public void runDriver() { /** Drag element from pallete and drop on the scene. */ @Test public void dragAndDrop() { - final SelenideElement initialNode = scene.dragAndDrop(pallete.getElement("Initial Node")); + final Block initialNode = scene.dragAndDrop(pallete.getElement("Initial Node")); assert scene.exist(initialNode); } /** Remove element from scene. */ @Test public void remove() { - final SelenideElement sceneElement = scene.dragAndDrop(pallete.getElement("Initial Node")); + final Block sceneElement = scene.dragAndDrop(pallete.getElement("Initial Node")); assert scene.exist(sceneElement); scene.remove(sceneElement); assert !scene.exist(sceneElement); @@ -72,11 +76,11 @@ public void remove() { /** Add two elements and link them. */ @Test public void addLink() { - final SelenideElement initNode = scene.dragAndDrop(pallete.getElement("Initial Node"), 4, 4); - final SelenideElement finalNode = scene.dragAndDrop(pallete.getElement("Final Node"), 4, 70); - final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward"), 4, 7); - SelenideElement link = scene.addLink(initNode, motor); - SelenideElement link2 = scene.addLink(motor, finalNode); + final Block initNode = scene.dragAndDrop(pallete.getElement("Initial Node"), 4, 4); + final Block finalNode = scene.dragAndDrop(pallete.getElement("Final Node"), 4, 70); + final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward"), 4, 7); + Link link = scene.addLink(initNode, motor); + Link link2 = scene.addLink(motor, finalNode); scene.moveToCell(motor, 72, 64); assert scene.exist(link); assert scene.exist(link2); @@ -85,21 +89,25 @@ public void addLink() { /** Set property 'Ports' of motor forward item to '123' and checks that all is correct. */ @Test public void propertyEditor() { - final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); - propertyEditor.setProperty(motor, "Ports", "123"); - assert propertyEditor.getProperty(motor, "Ports").equals("123"); + final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); + propertyEditor.setProperty(motor.getInnerSeleniumElement(), "Ports", "123"); + assert propertyEditor.getProperty(motor.getInnerSeleniumElement(), "Ports").equals("123"); } /** Move element to cell. */ @Test public void moveElement() { - final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); - scene.moveToCell(motor, 40, 40); - assert scene.getCell(motor).getWidth() == 40 && scene.getCell(motor).getHeight() == 40; - scene.moveToCell(motor, 72, 64); - assert scene.getCell(motor).getWidth() == 72 && scene.getCell(motor).getHeight() == 64; - scene.moveToCell(motor, 0, 0); - assert scene.getCell(motor).getWidth() == 0 && scene.getCell(motor).getHeight() == 0; + final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); + try { + scene.moveToCell(motor, 40, 40); + assert motor.getCoordinateOnScene().getXCell() == 40 && motor.getCoordinateOnScene().getYCell() == 40; + scene.moveToCell(motor, 72, 64); + assert motor.getCoordinateOnScene().getXCell() == 72 && motor.getCoordinateOnScene().getYCell() == 64; + scene.moveToCell(motor, 0, 0); + assert motor.getCoordinateOnScene().getXCell() == 0 && motor.getCoordinateOnScene().getYCell() == 0; + } catch (ElementNotOnTheSceneException e) { + e.printStackTrace(); + } } /* diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 2e12672d..55cb2dd5 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -4,6 +4,8 @@ import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; +import com.qreal.wmp.uitesting.dia.model.Block; +import com.qreal.wmp.uitesting.dia.model.Link; import com.qreal.wmp.uitesting.dia.services.Pallete; import com.qreal.wmp.uitesting.dia.services.PropertyEditor; import com.qreal.wmp.uitesting.dia.services.Scene; @@ -40,8 +42,8 @@ public class DiagramConstructingTest { private WebDriver driver; - private ArrayList elements; - private ArrayList links; + private ArrayList elements; + private ArrayList links; /** Setup ChromeDriverManager. */ @BeforeClass @@ -85,12 +87,12 @@ public void moveSomeNodes() { @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"); + propertyEditor.setProperty(elements.get(1).getInnerSeleniumElement(), "Power", "80"); + assert propertyEditor.getProperty(elements.get(1).getInnerSeleniumElement(), "Power").equals("80"); + propertyEditor.setProperty(elements.get(2).getInnerSeleniumElement(), "Color", "green"); + assert propertyEditor.getProperty(elements.get(2).getInnerSeleniumElement(), "Color").equals("green"); + propertyEditor.setProperty(elements.get(3).getInnerSeleniumElement(), "Delay", "200"); + assert propertyEditor.getProperty(elements.get(3).getInnerSeleniumElement(), "Delay").equals("200"); } @After From 1ddddf88158abbd71629f60e59dd6ca0811192c7 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 12 Feb 2017 12:35:29 +0300 Subject: [PATCH 17/40] Code refactor --- .../qreal/wmp/uitesting/dia/model/SceneWindow.java | 4 ++-- .../com/qreal/wmp/uitesting/dia/services/Scene.java | 13 ++++++++----- .../testspace/DiagramConstructingTest.java | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index 3f567868..498cee38 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -105,7 +105,7 @@ private Actions callDragAndDropByY(int src, int dst, int step, Actions actions, } private int jump(final List elements, int step, int current) { - if (elements.stream().filter(x -> { + if (elements.stream().anyMatch(x -> { try { return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) < Math.abs(2 * step); @@ -113,7 +113,7 @@ private int jump(final List elements, int step, int current) { e.printStackTrace(); } return false; - }).findFirst().isPresent()) { + })) { return step + jump(elements, step, step + current); } else { return step; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index 743cabcb..84023d6b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java @@ -11,7 +11,10 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import static com.codeborne.selenide.Selenide.$; @@ -109,11 +112,11 @@ public void remove(final SceneElement sceneElement) { /** Remove all elements from the scene. */ public void clean() { if (!links.isEmpty()) { - remove(links.stream().findFirst().get()); + remove(links.stream().collect(Collectors.toList()).get(0)); clean(); } else { if (!blocks.isEmpty()) { - remove(blocks.stream().findFirst().get()); + remove(blocks.stream().collect(Collectors.toList()).get(0)); clean(); } else { logger.info("Clean scene"); @@ -145,14 +148,14 @@ private Optional updateBlocks() { final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); return allElements.stream().filter(htmlElement -> htmlElement.attr("class").contains("element devs ImageWithPorts") && - !blocks.stream().anyMatch(block -> + blocks.stream().noneMatch(block -> block.getInnerSeleniumElement().attr("id").equals(htmlElement.attr("id")))).findFirst(); } private Optional updateLinks() { final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); return allElements.stream().filter(htmlElement -> htmlElement.attr("class").contains("link") && - !links.stream().anyMatch(link -> + links.stream().noneMatch(link -> htmlElement.attr("id").equals(link.getInnerSeleniumElement().attr("id")))).findFirst(); } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 55cb2dd5..ab9aa14c 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -1,6 +1,5 @@ package com.qreal.wmp.uitesting.testspace; -import com.codeborne.selenide.SelenideElement; import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; From af4b4be0e56d0c0c83c1ae8e60df8db06c4ae979 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Wed, 15 Feb 2017 01:17:32 +0300 Subject: [PATCH 18/40] Fix focus --- .../wmp/uitesting/dia/model/SceneWindow.java | 99 +++++++++++++++---- .../wmp/uitesting/dia/services/Scene.java | 17 +++- .../wmp/uitesting/innertests/DiaTest.java | 18 ---- 3 files changed, 91 insertions(+), 43 deletions(-) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index 498cee38..1a26caa9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -3,11 +3,11 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.services.Scene; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; +import org.openqa.selenium.*; import org.openqa.selenium.interactions.Actions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import sun.jvm.hotspot.runtime.Threads; import java.util.List; @@ -21,22 +21,26 @@ public class SceneWindow { /** Link to full scene. */ private final Scene scene; - private final int stepVert; + private int stepVert; - private final int stepHor; + private int stepHor; private final WebDriver driver; /** Web element of the Scene. */ private final SelenideElement sceneWrapper; - + + private static final Logger logger = LoggerFactory.getLogger(SceneWindow.class); + + /** Constructor takes links to current scene and current driver. */ public SceneWindow(final Scene scene, final WebDriver driver) { this.scene = scene; this.driver = driver; sceneWrapper = $(By.cssSelector(".scene-wrapper")); - stepVert = sceneWrapper.getSize().getHeight() / 12; - stepHor = sceneWrapper.getSize().getWidth() / 12; + stepHor = 40; + stepVert = 40; + updateCanvasInfo(driver); } /** @@ -73,17 +77,54 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn /** * Move the screen to requested position. * - * @param position position to move + * @param coordinate coordinate to move */ - public void focus(final Dimension position) { - final Dimension size = sceneWrapper.getSize(); - callMovementAction(0, 2000, stepHor, new Actions(driver), Keys.ARROW_LEFT); - callMovementAction(0, 2000, stepVert, new Actions(driver), Keys.ARROW_UP); - - callMovementAction(size.getWidth(), position.getWidth(), stepHor, - new Actions(driver), Keys.ARROW_RIGHT).release().perform(); - callMovementAction(size.getHeight(), position.getHeight(), stepVert, - new Actions(driver), Keys.ARROW_DOWN).release().perform(); + public void focus(final Coordinate coordinate) { + logger.info("Focus to " + coordinate.getXAbsolute() + " " + coordinate.getYAbsolute()); + horizontalWindowMovement(coordinate.getXAbsolute()); + verticalWindowMovement(coordinate.getYAbsolute()); + } + + private void horizontalWindowMovement(int horizontal) { + int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); + int left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); + logger.info("focus horizontal " + left + " " + sizeHor); + + if (left + sizeHor * 3 / 4 < horizontal) { + new Actions(driver).sendKeys(Keys.RIGHT).perform(); + updateCanvasInfo(driver); + if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { + horizontalWindowMovement(horizontal); + } + } + if (left + sizeHor / 4 > horizontal) { + new Actions(driver).sendKeys(Keys.LEFT).perform(); + updateCanvasInfo(driver); + if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { + horizontalWindowMovement(horizontal); + } + } + } + + private void verticalWindowMovement(int vertical) { + int sizeVer = Double.valueOf($(By.id("SceneWindowVerSize")).innerHtml()).intValue(); + int top = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); + logger.info("focus vertical " + top + " " + sizeVer); + + if (top + sizeVer * 3 / 4 < vertical) { + new Actions(driver).sendKeys(Keys.DOWN).perform(); + updateCanvasInfo(driver); + if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { + verticalWindowMovement(vertical); + } + } + if (top + sizeVer / 4 > vertical) { + new Actions(driver).sendKeys(Keys.UP).perform(); + updateCanvasInfo(driver); + if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { + verticalWindowMovement(vertical); + } + } } private Actions callMovementAction(int src, int dst, int step, Actions actions, Keys key) { @@ -130,4 +171,22 @@ private Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTh return block.getCoordinateOnScene(); } -} + + private void updateCanvasInfo(WebDriver driver) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (driver instanceof JavascriptExecutor) { + ((JavascriptExecutor) driver).executeScript("var canvas = " + + "document.getElementsByClassName(\"scene-wrapper\")[0]; " + + "var BB=canvas.getBoundingClientRect();" + + "$('#SceneWindowLeft').html(canvas.scrollLeft);" + + "$('#SceneWindowTop').html(canvas.scrollTop);" + + "$('#SceneWindowHorSize').html(BB.right - BB.left);" + + "$('#SceneWindowVerSize').html(BB.bottom - BB.top);" + ); + } + } +} \ No newline at end of file diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index 84023d6b..e4b61eea 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java @@ -3,9 +3,7 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.model.*; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -import org.openqa.selenium.By; -import org.openqa.selenium.NotFoundException; -import org.openqa.selenium.WebDriver; +import org.openqa.selenium.*; import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,10 +34,16 @@ public class Scene { private Set links = new HashSet<>(); private WebDriver driver; - + /** For actions such as mouse move we need driver of current page. */ public void updateWebdriver(final WebDriver webDriver) { driver = webDriver; + if (driver instanceof JavascriptExecutor) { + ((JavascriptExecutor) driver).executeScript( + createDiv("SceneWindowLeft") + createDiv("SceneWindowTop") + + createDiv("SceneWindowHorSize") + createDiv("SceneWindowVerSize") + ); + } } /** @@ -158,5 +162,8 @@ private Optional updateLinks() { links.stream().noneMatch(link -> htmlElement.attr("id").equals(link.getInnerSeleniumElement().attr("id")))).findFirst(); } - + + private static String createDiv(String divName) { + return "$('body').append('');"; + } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 9e4ff5ef..9442ce7c 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -1,6 +1,5 @@ package com.qreal.wmp.uitesting.innertests; -import com.codeborne.selenide.SelenideElement; import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; @@ -19,7 +18,6 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -109,22 +107,6 @@ public void moveElement() { e.printStackTrace(); } } - - /* - @Test - public void test() { - final SelenideElement motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); - scene.moveToCell(motor, 30, 40); - - if (driver instanceof JavascriptExecutor) { - ((JavascriptExecutor) driver) - .executeScript("var canvas = document.getElementsByClassName(\"scene-wrapper\")[0]; " + - "var BB=canvas.getBoundingClientRect();" + - "alert(canvas.scrollLeft)"); - // driver.switchTo().alert().accept(); - } - } -*/ /** Close the browser. */ @After From 0b62cb291284aa874ac7b36a3303d47eabdbde22 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 00:25:58 +0300 Subject: [PATCH 19/40] Fix clean scene --- .../java/com/qreal/wmp/uitesting/Opener.java | 18 +++-- .../qreal/wmp/uitesting/config/AppInit.java | 2 + .../qreal/wmp/uitesting/config/DevConfig.java | 17 +++++ .../wmp/uitesting/dia/model/Coordinate.java | 2 +- .../qreal/wmp/uitesting/dia/model/Link.java | 11 +++ .../wmp/uitesting/dia/model/SceneWindow.java | 41 +++++------ .../wmp/uitesting/dia/services/Scene.java | 68 ++++++++++++------- .../wmp/uitesting/innertests/AuthTest.java | 4 +- .../wmp/uitesting/innertests/DiaTest.java | 16 +++-- .../testspace/DiagramConstructingTest.java | 2 +- 10 files changed, 121 insertions(+), 60 deletions(-) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java index a7bfe32c..26b70578 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java @@ -1,5 +1,6 @@ package com.qreal.wmp.uitesting; +import com.qreal.wmp.uitesting.dia.services.Scene; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,9 +25,14 @@ public class Opener { @Autowired private Auther auther; - + + @Autowired + private Scene scene; + private static final Logger logger = LoggerFactory.getLogger(Opener.class); - + + private boolean inited = false; + /** * Opens page from wmp with authentication. * @@ -34,17 +40,20 @@ public class Opener { */ public void open(final String page) { try { - cleanOpen(page); + com.codeborne.selenide.Selenide.open(env.getProperty(page)); + logger.info("Open page {}", env.getProperty(page)); if ($(byText("Sign in to continue to Auth")).exists()) { logger.info("Fail with open page {}. Try to login.", env.getProperty(page)); auther.auth(); } - cleanOpen(page); + com.codeborne.selenide.Selenide.open(env.getProperty(page)); + logger.info("Open page {}", env.getProperty(page)); } catch (WrongAuthException e) { logger.error("Opener fails: " + e.getMessage()); throw new AccessDeniedException(e.getMessage()); } logger.info("Open page {}", env.getProperty(page)); + scene.init(); } /** @@ -55,5 +64,6 @@ public void open(final String page) { public void cleanOpen(final String page) { com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); + scene.init(); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java index 5a0e46c5..179b4bda 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/AppInit.java @@ -1,5 +1,6 @@ package com.qreal.wmp.uitesting.config; +import io.github.bonigarcia.wdm.ChromeDriverManager; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; @@ -8,6 +9,7 @@ public class AppInit { /** Main function creates context. */ public static void main(final String... args) { + ChromeDriverManager.getInstance().setup(); final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.scan("com.qreal.wmp.uitesting"); context.register(AppInit.class); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index 2faab5c2..30b7e7e9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -1,5 +1,10 @@ package com.qreal.wmp.uitesting.config; +import com.codeborne.selenide.WebDriverRunner; +import com.qreal.wmp.uitesting.dia.services.Scene; +import io.github.bonigarcia.wdm.ChromeDriverManager; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @@ -15,5 +20,17 @@ public class DevConfig { public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } + + @Bean + public WebDriver webDriver() { + ChromeDriverManager.getInstance().setup(); + WebDriver driver = new ChromeDriver(); + WebDriverRunner.setWebDriver(driver); + return driver; + } + @Bean + public Scene scene() { + return new Scene(webDriver()); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java index 4aee51ff..cc378a5e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java @@ -9,7 +9,7 @@ public class Coordinate { public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { final String position = element.attr("transform"); final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); - return Optional.of(new Coordinate(Integer.valueOf(pairStr[0]), Integer.valueOf(pairStr[1]))); + return Optional.of(new Coordinate(Double.valueOf(pairStr[0]).intValue(), Double.valueOf(pairStr[1]).intValue())); } private final int xAbsolute; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java index e15507a2..20500f6b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java @@ -1,12 +1,15 @@ package com.qreal.wmp.uitesting.dia.model; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.$; public class Link extends SceneElement { + public static final String className = "link"; + private static final String sourcePointClassName = "marker-source"; private static final String targetPointClassName = "marker-target"; @@ -35,4 +38,12 @@ public SceneElement getSource() { public SceneElement getTarget() { return target; } + + @Override + public Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException { + return new Coordinate( + (source.getCoordinateOnScene().getXAbsolute() + target.getCoordinateOnScene().getXAbsolute()) / 2, + (source.getCoordinateOnScene().getYAbsolute() + target.getCoordinateOnScene().getYAbsolute()) / 2 + ); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index 1a26caa9..9f3d1292 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -7,7 +7,6 @@ import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import sun.jvm.hotspot.runtime.Threads; import java.util.List; @@ -26,9 +25,6 @@ public class SceneWindow { private int stepHor; private final WebDriver driver; - - /** Web element of the Scene. */ - private final SelenideElement sceneWrapper; private static final Logger logger = LoggerFactory.getLogger(SceneWindow.class); @@ -37,7 +33,6 @@ public class SceneWindow { public SceneWindow(final Scene scene, final WebDriver driver) { this.scene = scene; this.driver = driver; - sceneWrapper = $(By.cssSelector(".scene-wrapper")); stepHor = 40; stepVert = 40; updateCanvasInfo(driver); @@ -51,7 +46,7 @@ public SceneWindow(final Scene scene, final WebDriver driver) { */ public void move(final Block element, final Coordinate dist) throws ElementNotOnTheSceneException { Coordinate src = element.getCoordinateOnScene(); - //focus(src); + focus(src); if (src.getXAbsolute() < dist.getXAbsolute()) { callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), stepHor, @@ -90,15 +85,15 @@ private void horizontalWindowMovement(int horizontal) { int left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); logger.info("focus horizontal " + left + " " + sizeHor); - if (left + sizeHor * 3 / 4 < horizontal) { - new Actions(driver).sendKeys(Keys.RIGHT).perform(); + if (left + sizeHor * 2 / 3 < horizontal) { + sendKey(Keys.RIGHT); updateCanvasInfo(driver); if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { horizontalWindowMovement(horizontal); } } - if (left + sizeHor / 4 > horizontal) { - new Actions(driver).sendKeys(Keys.LEFT).perform(); + if (left + sizeHor / 3 > horizontal) { + sendKey(Keys.LEFT); updateCanvasInfo(driver); if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { horizontalWindowMovement(horizontal); @@ -111,15 +106,15 @@ private void verticalWindowMovement(int vertical) { int top = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); logger.info("focus vertical " + top + " " + sizeVer); - if (top + sizeVer * 3 / 4 < vertical) { - new Actions(driver).sendKeys(Keys.DOWN).perform(); + if (top + sizeVer * 2 / 3 < vertical) { + sendKey(Keys.DOWN); updateCanvasInfo(driver); if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { verticalWindowMovement(vertical); } } - if (top + sizeVer / 4 > vertical) { - new Actions(driver).sendKeys(Keys.UP).perform(); + if (top + sizeVer / 3 > vertical) { + sendKey(Keys.UP); updateCanvasInfo(driver); if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { verticalWindowMovement(vertical); @@ -127,10 +122,6 @@ private void verticalWindowMovement(int vertical) { } } - private Actions callMovementAction(int src, int dst, int step, Actions actions, Keys key) { - return src < dst ? callMovementAction(src + step, dst, step, actions.sendKeys(key), key) : actions; - } - private Actions callDragAndDropByX(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { final List elements = scene.getBlocks(); return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByX(src + step, dst, step, @@ -173,11 +164,6 @@ private Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTh } private void updateCanvasInfo(WebDriver driver) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - e.printStackTrace(); - } if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("var canvas = " + "document.getElementsByClassName(\"scene-wrapper\")[0]; " + @@ -189,4 +175,13 @@ private void updateCanvasInfo(WebDriver driver) { ); } } + + private void sendKey(Keys key) { + new Actions(driver).sendKeys(key).perform(); + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index e4b61eea..96c1a859 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java @@ -1,12 +1,16 @@ package com.qreal.wmp.uitesting.dia.services; import com.codeborne.selenide.SelenideElement; +import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.dia.model.*; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.*; +import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.util.HashSet; @@ -22,7 +26,6 @@ * Describes Scene of Editor. * Can add rm and manipulate with objects on that area. */ -@Service public class Scene { public static final String selector = ".scene-wrapper"; @@ -33,13 +36,16 @@ public class Scene { private Set links = new HashSet<>(); - private WebDriver driver; + private WebDriver webDriver; /** For actions such as mouse move we need driver of current page. */ - public void updateWebdriver(final WebDriver webDriver) { - driver = webDriver; - if (driver instanceof JavascriptExecutor) { - ((JavascriptExecutor) driver).executeScript( + public Scene(WebDriver webDriver) { + this.webDriver = webDriver; + } + + public void init() { + if (webDriver instanceof JavascriptExecutor) { + ((JavascriptExecutor) webDriver).executeScript( createDiv("SceneWindowLeft") + createDiv("SceneWindowTop") + createDiv("SceneWindowHorSize") + createDiv("SceneWindowVerSize") ); @@ -77,7 +83,7 @@ public Block dragAndDrop(final SelenideElement element, int cell_x, int cell_y) /** Move element to cell. */ public void moveToCell(final Block block, final int cell_x, final int cell_y) { - SceneWindow sceneWindow = new SceneWindow(this, driver); + SceneWindow sceneWindow = new SceneWindow(this, webDriver); logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); try { sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); @@ -86,13 +92,16 @@ public void moveToCell(final Block block, final int cell_x, final int cell_y) { } } - /** Focus the element. + /** Focus the element. */ public void focus(final SceneElement element) { - SceneWindow sceneWindow = new SceneWindow(this, driver); + SceneWindow sceneWindow = new SceneWindow(this, webDriver); logger.info("Focus on the element {}", element); - sceneWindow.focus(new Dimension(element.getCoordinateOnScene().getXAbsolute(), - element.getCoordinateOnScene().getYAbsolute())); - }*/ + try { + sceneWindow.focus(element.getCoordinateOnScene()); + } catch (ElementNotOnTheSceneException e) { + e.printStackTrace(); + } + } /** Check if element exist on the scene. */ public boolean exist(SceneElement element) { @@ -100,17 +109,12 @@ public boolean exist(SceneElement element) { } /** Remove element from the scene. */ - public void remove(final SceneElement sceneElement) { - assert sceneElement != null; - logger.info("Remove element {} form scene", sceneElement); - //elements.remove(selenideElement); - new Actions(driver).contextClick(sceneElement.getInnerSeleniumElement()).build().perform(); - $(By.id("scene-context-menu")).click(); - blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(Block.className::equals).map(x -> - new Block("name", x)).collect(Collectors.toSet()); - links = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(Block.className::equals).map(x -> - new Link("name", x)).collect(Collectors.toSet()); + public void remove(Block block) { + removeSceneElement(block); + } + public void remove(Link link) { + removeSceneElement(link.getSource()); } /** Remove all elements from the scene. */ @@ -133,7 +137,7 @@ public Link addLink(final Block source, final Block target) { final SelenideElement begin = $(By.cssSelector(selector + " #" + source.getInnerSeleniumElement().attr("id") + " .outPorts")); logger.info("Begin element {}, end element {} ", begin, target); - new Actions(driver).dragAndDrop(source.getPort().getInnerSeleniumElement(), + new Actions(webDriver).dragAndDrop(source.getPort().getInnerSeleniumElement(), target.getInnerSeleniumElement()).build().perform(); SelenideElement newEl = updateLinks().get(); logger.info("Add link {}", newEl); @@ -166,4 +170,22 @@ private Optional updateLinks() { private static String createDiv(String divName) { return "$('body').append('');"; } + + private void removeSceneElement(SceneElement sceneElement) { + focus(sceneElement); + assert sceneElement != null; + logger.info("Remove element {} form scene", sceneElement.getInnerSeleniumElement().toString()); + new Actions(webDriver).contextClick(sceneElement.getInnerSeleniumElement()).build().perform(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + $(By.id("scene-context-menu")).click(); + $$(By.cssSelector(selector + " #v_7 > *")).stream().forEach(System.out::println); + blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(x -> x.attr("class").equals(Block.className)).map(x -> + new Block("name", x)).collect(Collectors.toSet()); + links = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(x -> x.attr("class").equals(Link.className)).map(x -> + new Link("name", x)).collect(Collectors.toSet()); + } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java index c89ba493..8d67e752 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java @@ -15,6 +15,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -25,6 +26,7 @@ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class AuthTest { @Autowired @@ -33,6 +35,7 @@ public class AuthTest { @Autowired private Opener opener; + @Autowired private WebDriver driver; /** Setup ChromeDriverManager. */ @@ -44,7 +47,6 @@ public static void init() { /** Setup browser. */ @Before public void runDriver() { - driver = new ChromeDriver(); WebDriverRunner.setWebDriver(driver); } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 9442ce7c..8a910280 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -18,12 +18,14 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class DiaTest { @Autowired @@ -38,21 +40,21 @@ public class DiaTest { @Autowired private PropertyEditor propertyEditor; + @Autowired private WebDriver driver; /** Setup ChromeDriverManager. */ - @BeforeClass - public static void init() { - ChromeDriverManager.getInstance().setup(); - } + // @BeforeClass + // public static void init() { + // ChromeDriverManager.getInstance().setup(); + // } /** Setup browser. */ @Before public void runDriver() { - driver = new ChromeDriver(); - WebDriverRunner.setWebDriver(driver); + // WebDriverRunner.setWebDriver(driver); + // updateWebdriver(driver); opener.open("editor"); - scene.updateWebdriver(driver); } /** Drag element from pallete and drop on the scene. */ diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index ab9aa14c..fc174ff4 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -55,7 +55,7 @@ public void runDriver() { driver = new ChromeDriver(); WebDriverRunner.setWebDriver(driver); opener.open("editor"); - scene.updateWebdriver(driver); + // scene.updateWebdriver(driver); elements = new ArrayList<>(); links = new ArrayList<>(); From 70e67bfb892a1916f2afd34f8608faf1748ee631 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 01:29:46 +0300 Subject: [PATCH 20/40] Make SceneWindow steps calculated automatically --- .../wmp/uitesting/dia/model/SceneWindow.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index 9f3d1292..170c9ab6 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -33,11 +33,9 @@ public class SceneWindow { public SceneWindow(final Scene scene, final WebDriver driver) { this.scene = scene; this.driver = driver; - stepHor = 40; - stepVert = 40; - updateCanvasInfo(driver); + updateSteps(); } - + /** * Moves element to the requested position. * @@ -87,14 +85,14 @@ private void horizontalWindowMovement(int horizontal) { if (left + sizeHor * 2 / 3 < horizontal) { sendKey(Keys.RIGHT); - updateCanvasInfo(driver); + updateCanvasInfo(); if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { horizontalWindowMovement(horizontal); } } if (left + sizeHor / 3 > horizontal) { sendKey(Keys.LEFT); - updateCanvasInfo(driver); + updateCanvasInfo(); if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { horizontalWindowMovement(horizontal); } @@ -108,14 +106,14 @@ private void verticalWindowMovement(int vertical) { if (top + sizeVer * 2 / 3 < vertical) { sendKey(Keys.DOWN); - updateCanvasInfo(driver); + updateCanvasInfo(); if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { verticalWindowMovement(vertical); } } if (top + sizeVer / 3 > vertical) { sendKey(Keys.UP); - updateCanvasInfo(driver); + updateCanvasInfo(); if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { verticalWindowMovement(vertical); } @@ -163,7 +161,7 @@ private Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTh return block.getCoordinateOnScene(); } - private void updateCanvasInfo(WebDriver driver) { + private void updateCanvasInfo() { if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("var canvas = " + "document.getElementsByClassName(\"scene-wrapper\")[0]; " + @@ -184,4 +182,16 @@ private void sendKey(Keys key) { e.printStackTrace(); } } + + private void updateSteps() { + updateCanvasInfo(); + $(Scene.selector).click(); + focus(new Coordinate(0, 0)); + updateCanvasInfo(); + sendKey(Keys.DOWN); + sendKey(Keys.RIGHT); + updateCanvasInfo(); + stepHor = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); + stepVert = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); + } } \ No newline at end of file From 64e8b53ff587351057bc45b1c931325b9c51d609 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 15:07:41 +0300 Subject: [PATCH 21/40] Code refactor --- Travis/checkstyle/checkstyle.xml | 45 ++++++++++--------- Travis/pmd/pmd-ruleset.xml | 4 +- .../java/com/qreal/wmp/uitesting/Opener.java | 2 - .../wmp/uitesting/dia/model/Coordinate.java | 10 ++++- .../wmp/uitesting/dia/model/SceneWindow.java | 12 ++--- .../wmp/uitesting/dia/services/Scene.java | 25 ++++++----- .../wmp/uitesting/innertests/DiaTest.java | 14 +----- .../testspace/DiagramConstructingTest.java | 16 ++----- 8 files changed, 61 insertions(+), 67 deletions(-) diff --git a/Travis/checkstyle/checkstyle.xml b/Travis/checkstyle/checkstyle.xml index e51a03d2..d4fa676d 100644 --- a/Travis/checkstyle/checkstyle.xml +++ b/Travis/checkstyle/checkstyle.xml @@ -29,7 +29,9 @@ - + + + @@ -68,9 +70,9 @@ - + value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/> + @@ -90,60 +92,60 @@ + value="Package name ''{0}'' must match pattern ''{1}''."/> + value="Type name ''{0}'' must match pattern ''{1}''."/> + value="Member name ''{0}'' must match pattern ''{1}''."/> + value="Parameter name ''{0}'' must match pattern ''{1}''."/> + value="Local variable name ''{0}'' must match pattern ''{1}''."/> + value="Class type name ''{0}'' must match pattern ''{1}''."/> + value="Method type name ''{0}'' must match pattern ''{1}''."/> + value="Interface type name ''{0}'' must match pattern ''{1}''."/> + value="Method name ''{0}'' must match pattern ''{1}''."/> - - - + value="GenericWhitespace ''{0}'' is followed by whitespace."/> + + + @@ -170,7 +172,7 @@ - + @@ -187,5 +189,6 @@ + diff --git a/Travis/pmd/pmd-ruleset.xml b/Travis/pmd/pmd-ruleset.xml index bef3725e..7e3a7df8 100644 --- a/Travis/pmd/pmd-ruleset.xml +++ b/Travis/pmd/pmd-ruleset.xml @@ -11,7 +11,9 @@ - + + + diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java index 26b70578..bf7f4138 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java @@ -31,8 +31,6 @@ public class Opener { private static final Logger logger = LoggerFactory.getLogger(Opener.class); - private boolean inited = false; - /** * Opens page from wmp with authentication. * diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java index cc378a5e..3cda2787 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java @@ -1,15 +1,23 @@ package com.qreal.wmp.uitesting.dia.model; import com.codeborne.selenide.SelenideElement; +import org.jetbrains.annotations.NotNull; import java.util.Optional; public class Coordinate { + /** Returns coordinate of object on scene. */ + @NotNull public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { final String position = element.attr("transform"); final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); - return Optional.of(new Coordinate(Double.valueOf(pairStr[0]).intValue(), Double.valueOf(pairStr[1]).intValue())); + return Optional.of( + new Coordinate( + Double.valueOf(pairStr[0]).intValue(), + Double.valueOf(pairStr[1]).intValue() + ) + ); } private final int xAbsolute; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index 170c9ab6..d85fa337 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -3,7 +3,10 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.services.Scene; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -import org.openqa.selenium.*; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +31,6 @@ public class SceneWindow { private static final Logger logger = LoggerFactory.getLogger(SceneWindow.class); - /** Constructor takes links to current scene and current driver. */ public SceneWindow(final Scene scene, final WebDriver driver) { this.scene = scene; @@ -73,7 +75,7 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn * @param coordinate coordinate to move */ public void focus(final Coordinate coordinate) { - logger.info("Focus to " + coordinate.getXAbsolute() + " " + coordinate.getYAbsolute()); + logger.debug("Focus to " + coordinate.getXAbsolute() + " " + coordinate.getYAbsolute()); horizontalWindowMovement(coordinate.getXAbsolute()); verticalWindowMovement(coordinate.getYAbsolute()); } @@ -81,7 +83,7 @@ public void focus(final Coordinate coordinate) { private void horizontalWindowMovement(int horizontal) { int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); int left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); - logger.info("focus horizontal " + left + " " + sizeHor); + logger.debug("focus horizontal " + left + " " + sizeHor); if (left + sizeHor * 2 / 3 < horizontal) { sendKey(Keys.RIGHT); @@ -151,7 +153,6 @@ private int jump(final List elements, int step, int current) { } private Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTheSceneException { - Coordinate currentPosition = block.getCoordinateOnScene(); new Actions(driver).release().clickAndHold(block.getInnerSeleniumElement()).moveByOffset( @@ -177,6 +178,7 @@ private void updateCanvasInfo() { private void sendKey(Keys key) { new Actions(driver).sendKeys(key).perform(); try { + // wait until action is completed Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index 96c1a859..75aea68e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java @@ -1,17 +1,15 @@ package com.qreal.wmp.uitesting.dia.services; import com.codeborne.selenide.SelenideElement; -import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.dia.model.*; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -import org.openqa.selenium.*; -import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.NotFoundException; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; import java.util.HashSet; import java.util.List; @@ -43,6 +41,7 @@ public Scene(WebDriver webDriver) { this.webDriver = webDriver; } + /** Creates divs for SceneWindow. */ public void init() { if (webDriver instanceof JavascriptExecutor) { ((JavascriptExecutor) webDriver).executeScript( @@ -182,10 +181,14 @@ private void removeSceneElement(SceneElement sceneElement) { e.printStackTrace(); } $(By.id("scene-context-menu")).click(); - $$(By.cssSelector(selector + " #v_7 > *")).stream().forEach(System.out::println); - blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(x -> x.attr("class").equals(Block.className)).map(x -> - new Block("name", x)).collect(Collectors.toSet()); - links = $$(By.cssSelector(selector + " #v_7 > *")).stream().filter(x -> x.attr("class").equals(Link.className)).map(x -> - new Link("name", x)).collect(Collectors.toSet()); + blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream() + .filter(x -> x.attr("class").equals(Block.className)) + .map(x -> new Block("name", x)) + .collect(Collectors.toSet()); + + links = $$(By.cssSelector(selector + " #v_7 > *")).stream() + .filter(x -> x.attr("class").equals(Link.className)) + .map(x -> new Link("name", x)) + .collect(Collectors.toSet()); } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 8a910280..8c6edbe7 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -1,6 +1,5 @@ package com.qreal.wmp.uitesting.innertests; -import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.model.Block; @@ -9,14 +8,11 @@ import com.qreal.wmp.uitesting.dia.services.PropertyEditor; import com.qreal.wmp.uitesting.dia.services.Scene; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -import io.github.bonigarcia.wdm.ChromeDriverManager; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -42,18 +38,10 @@ public class DiaTest { @Autowired private WebDriver driver; - - /** Setup ChromeDriverManager. */ - // @BeforeClass - // public static void init() { - // ChromeDriverManager.getInstance().setup(); - // } - + /** Setup browser. */ @Before public void runDriver() { - // WebDriverRunner.setWebDriver(driver); - // updateWebdriver(driver); opener.open("editor"); } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index fc174ff4..5961f679 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -17,6 +17,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -25,6 +26,7 @@ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class DiagramConstructingTest { @Autowired @@ -39,24 +41,13 @@ public class DiagramConstructingTest { @Autowired private PropertyEditor propertyEditor; - private WebDriver driver; - private ArrayList elements; private ArrayList links; - /** Setup ChromeDriverManager. */ - @BeforeClass - public static void init() { - ChromeDriverManager.getInstance().setup(); - } - @Before public void runDriver() { - driver = new ChromeDriver(); - WebDriverRunner.setWebDriver(driver); opener.open("editor"); - // scene.updateWebdriver(driver); - + elements = new ArrayList<>(); links = new ArrayList<>(); @@ -97,7 +88,6 @@ public void fillProperties() { @After public void stopDriver() { scene.clean(); - driver.close(); } private boolean allExist() { From 6124f7abc4cc568e9a9c032f0f5f6645cb14c99f Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 19:30:35 +0300 Subject: [PATCH 22/40] Code refactor --- .../java/com/qreal/wmp/uitesting/Auther.java | 9 ++-- .../java/com/qreal/wmp/uitesting/Opener.java | 13 +++-- .../qreal/wmp/uitesting/config/DevConfig.java | 29 +++++++++++ .../qreal/wmp/uitesting/dia/model/Block.java | 6 +-- .../wmp/uitesting/dia/model/Coordinate.java | 6 ++- .../qreal/wmp/uitesting/dia/model/Link.java | 10 ++-- .../wmp/uitesting/dia/model/SceneElement.java | 4 +- .../wmp/uitesting/dia/model/SceneWindow.java | 33 ++++++++----- .../wmp/uitesting/dia/services/Pallete.java | 6 +-- .../dia/services/PropertyEditor.java | 17 ++++--- .../wmp/uitesting/dia/services/Scene.java | 49 ++++++++++--------- .../wmp/uitesting/innertests/DiaTest.java | 1 - ui-testing/ui-testing.iml | 6 ++- 13 files changed, 116 insertions(+), 73 deletions(-) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java index 6129e6e2..72897982 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java @@ -4,24 +4,23 @@ import org.openqa.selenium.By; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; -import org.springframework.stereotype.Service; import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.open; /** Used for authentication in current browser session. */ -@Service public class Auther { /** Use properties from pages.properies file. */ - @Autowired private Environment env; private static final Logger logger = LoggerFactory.getLogger(Auther.class); - + + public Auther(Environment env) { + this.env = env; + } /** Realizes authentication to the wmp. * * @param username login diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java index bf7f4138..d2142415 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java @@ -4,10 +4,8 @@ import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.security.access.AccessDeniedException; -import org.springframework.stereotype.Service; import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; @@ -16,21 +14,22 @@ * Used for open needed page from wmp in current browser session. * Allows you to access as an authorized user and not. */ -@Service public class Opener { /** Uses properties from pages.properies file. */ - @Autowired private Environment env; - @Autowired private Auther auther; - - @Autowired private Scene scene; private static final Logger logger = LoggerFactory.getLogger(Opener.class); + public Opener(Environment env, Auther auther, Scene scene) { + this.env = env; + this.auther = auther; + this.scene = scene; + } + /** * Opens page from wmp with authentication. * diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index 30b7e7e9..b865dfdf 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -1,20 +1,29 @@ package com.qreal.wmp.uitesting.config; import com.codeborne.selenide.WebDriverRunner; +import com.qreal.wmp.uitesting.Auther; +import com.qreal.wmp.uitesting.Opener; +import com.qreal.wmp.uitesting.dia.services.Pallete; +import com.qreal.wmp.uitesting.dia.services.PropertyEditor; import com.qreal.wmp.uitesting.dia.services.Scene; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.env.Environment; /** Creates beans for Spring needs. **/ @Configuration @PropertySource("classpath:pages.properties") public class DevConfig { + @Autowired + Environment environment; + /** Processor for Environment linked to property files.*/ @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { @@ -33,4 +42,24 @@ public WebDriver webDriver() { public Scene scene() { return new Scene(webDriver()); } + + @Bean + public Auther auther() { + return new Auther(environment); + } + + @Bean + public Opener opener() { + return new Opener(environment, auther(), scene()); + } + + @Bean + public PropertyEditor propertyEditor() { + return new PropertyEditor(); + } + + @Bean + public Pallete pallete() { + return new Pallete(); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java index 1feaf33f..55d6ac5d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java @@ -7,9 +7,9 @@ public class Block extends SceneElement { - public static final String className = "element devs ImageWithPorts"; + public static final String CLASS_NAME = "element devs ImageWithPorts"; - private final static String portClassName = "port0"; + private static final String PORT_CLASS_NAME = "port0"; private final String name; @@ -18,7 +18,7 @@ public class Block extends SceneElement { public Block(String name, SelenideElement innerSeleniumObject) { super(innerSeleniumObject); this.name = name; - this.port = new SceneElement($(innerSeleniumObject.find(By.className(portClassName)))); + this.port = new SceneElement($(innerSeleniumObject.find(By.className(PORT_CLASS_NAME)))); } public String getName() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java index 3cda2787..300a09e6 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java @@ -7,6 +7,8 @@ public class Coordinate { + private static final int POINT_IN_CELL = 25; + /** Returns coordinate of object on scene. */ @NotNull public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { @@ -30,11 +32,11 @@ public Coordinate(int xAbsolute, int yAbsolute) { } public int getXCell() { - return xAbsolute / 25; + return xAbsolute / POINT_IN_CELL; } public int getYCell() { - return yAbsolute / 25; + return yAbsolute / POINT_IN_CELL; } public int getXAbsolute() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java index 20500f6b..b09ec41b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java @@ -8,11 +8,11 @@ public class Link extends SceneElement { - public static final String className = "link"; + public static final String CLASS_NAME = "link"; - private static final String sourcePointClassName = "marker-source"; + private static final String SOURCE_POINT_CLASSNAME = "marker-source"; - private static final String targetPointClassName = "marker-target"; + private static final String TARGET_POINT_CLASSNAME = "marker-target"; private final String name; @@ -23,8 +23,8 @@ public class Link extends SceneElement { public Link(String name, SelenideElement innerSeleniumObject) { super(innerSeleniumObject); this.name = name; - this.source = new SceneElement($(innerSeleniumObject.find(By.className(sourcePointClassName)))); - this.target = new SceneElement($(innerSeleniumObject.find(By.className(targetPointClassName)))); + this.source = new SceneElement($(innerSeleniumObject.find(By.className(SOURCE_POINT_CLASSNAME)))); + this.target = new SceneElement($(innerSeleniumObject.find(By.className(TARGET_POINT_CLASSNAME)))); } public String getName() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java index e08bcc5a..4eb80426 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java @@ -22,8 +22,8 @@ public SelenideElement getInnerSeleniumElement() { } public Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException { - return Coordinate.getCoordinateFromSeleniumObject( - innerSeleniumElement).orElseThrow(ElementNotOnTheSceneException::new); + return Coordinate.getCoordinateFromSeleniumObject(innerSeleniumElement) + .orElseThrow(ElementNotOnTheSceneException::new); } public String getType() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index d85fa337..37dd3ab2 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -49,7 +49,8 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn focus(src); if (src.getXAbsolute() < dist.getXAbsolute()) { - callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), stepHor, + callDragAndDropByX( + src.getXAbsolute(), dist.getXAbsolute(), stepHor, new Actions(driver), Keys.ARROW_RIGHT, element.getInnerSeleniumElement()).perform(); } else { callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), -stepHor, @@ -124,23 +125,28 @@ private void verticalWindowMovement(int vertical) { private Actions callDragAndDropByX(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { final List elements = scene.getBlocks(); - return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByX(src + step, dst, step, - actions.sendKeys(key).clickAndHold(element).moveByOffset(jump(elements, 2 * step, src), 0), - key, element) : actions.sendKeys(key, key); + return Math.abs(src - dst) > Math.abs(step) ? + callDragAndDropByX(src + step, dst, step, + 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.getBlocks(); - return Math.abs(src - dst) > Math.abs(step) ? callDragAndDropByY(src + step, dst, step, - actions.sendKeys(key).clickAndHold(element).moveByOffset(0, jump(elements, 2 * step, src)), - key, element) : actions.sendKeys(key, key); + return Math.abs(src - dst) > Math.abs(step) ? + callDragAndDropByY(src + step, dst, step, + 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) { if (elements.stream().anyMatch(x -> { try { - return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) - < Math.abs(2 * step); + return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) < Math.abs(2 * step); } catch (ElementNotOnTheSceneException e) { e.printStackTrace(); } @@ -155,9 +161,12 @@ private int jump(final List elements, int step, int current) { private Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTheSceneException { Coordinate currentPosition = block.getCoordinateOnScene(); - new Actions(driver).release().clickAndHold(block.getInnerSeleniumElement()).moveByOffset( - dist.getXAbsolute() - currentPosition.getXAbsolute(), - dist.getYAbsolute() - currentPosition.getYAbsolute()).release().perform(); + new Actions(driver).release() + .clickAndHold(block.getInnerSeleniumElement()) + .moveByOffset( + dist.getXAbsolute() - currentPosition.getXAbsolute(), + dist.getYAbsolute() - currentPosition.getYAbsolute() + ).release().perform(); return block.getCoordinateOnScene(); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java index 939248b4..e39846c8 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java @@ -5,7 +5,6 @@ import org.openqa.selenium.NoSuchElementException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; import static com.codeborne.selenide.Selectors.withText; import static com.codeborne.selenide.Selenide.$; @@ -14,10 +13,9 @@ * Describes Pallete. * For any manipulating with it. */ -@Service public class Pallete { - private static final String selector = "#palette-tab-content"; + private static final String SELECTOR = "#palette-tab-content"; private static final Logger logger = LoggerFactory.getLogger(Pallete.class); @@ -28,7 +26,7 @@ public class Pallete { * @return block */ public SelenideElement getElement(final String elementName) throws NoSuchElementException { - final SelenideElement element = $(By.cssSelector(selector)).find(withText(elementName)); + final SelenideElement element = $(By.cssSelector(SELECTOR)).find(withText(elementName)); logger.info("Get element {} from Palette", element); return element; } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java index 84260fbc..e2c7e10c 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java @@ -5,7 +5,6 @@ import org.openqa.selenium.NoSuchElementException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; import java.util.List; import java.util.OptionalInt; @@ -15,16 +14,16 @@ import static com.codeborne.selenide.Selenide.$$; /** Describe Property Editor. */ -@Service public class PropertyEditor { - private static final String selector = "#property_table"; + private static final String SELECTOR = "#property_table"; private static final Logger logger = LoggerFactory.getLogger(PropertyEditor.class); /** Set property of element which on the focus. */ public void setProperty(final SelenideElement element, final String propertyName, final String propertyValue) - throws NoSuchElementException { + throws NoSuchElementException + { element.click(); SelenideElement property = getInputOfElement(propertyName); if (property.attr("class").equals("input-group")) { @@ -50,13 +49,15 @@ public String getProperty(final SelenideElement element, final String propertyNa /** 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().contains(propertyName)).findFirst(); + final List allChilds = $$(By.cssSelector(SELECTOR + " tbody > * > *")); + final OptionalInt indexOfNeeded = IntStream.range(0, allChilds.size()) + .filter(index -> 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 + 1) + 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/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index 75aea68e..699ef51f 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java @@ -11,10 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static com.codeborne.selenide.Selenide.$; @@ -26,7 +23,7 @@ */ public class Scene { - public static final String selector = ".scene-wrapper"; + public static final String SELECTOR = ".scene-wrapper"; private static final Logger logger = LoggerFactory.getLogger(Pallete.class); @@ -58,7 +55,7 @@ public void init() { * @return element from scene */ public Block dragAndDrop(final SelenideElement element) { - element.dragAndDropTo(selector); + element.dragAndDropTo(SELECTOR); final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); Block newBlock = new Block("name", newEl); blocks.add(newBlock); @@ -133,12 +130,13 @@ public void clean() { /** Add link between two elements. */ public Link addLink(final Block source, final Block target) { - final SelenideElement begin = $(By.cssSelector(selector + " #" + + final SelenideElement begin = $(By.cssSelector(SELECTOR + " #" + source.getInnerSeleniumElement().attr("id") + " .outPorts")); logger.info("Begin element {}, end element {} ", begin, target); - new Actions(webDriver).dragAndDrop(source.getPort().getInnerSeleniumElement(), - target.getInnerSeleniumElement()).build().perform(); - SelenideElement newEl = updateLinks().get(); + new Actions(webDriver) + .dragAndDrop(source.getPort().getInnerSeleniumElement(), target.getInnerSeleniumElement()) + .build().perform(); + SelenideElement newEl = updateLinks().orElseThrow(() -> new NoSuchElementException("Link was not created")); logger.info("Add link {}", newEl); Link res = new Link("link", newEl); links.add(res); @@ -152,18 +150,23 @@ public List getBlocks() { /** Return new element of the scene. */ private Optional updateBlocks() { - final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); - return allElements.stream().filter(htmlElement -> - htmlElement.attr("class").contains("element devs ImageWithPorts") && - blocks.stream().noneMatch(block -> - block.getInnerSeleniumElement().attr("id").equals(htmlElement.attr("id")))).findFirst(); + final List allElements = $$(By.cssSelector(SELECTOR + " #v_7 > *")); + return allElements.stream() + .filter(htmlElement -> + htmlElement.attr("class").contains("element devs ImageWithPorts") && + blocks.stream().noneMatch(block -> block.getInnerSeleniumElement() + .attr("id").equals(htmlElement.attr("id"))) + ).findFirst(); } private Optional updateLinks() { - final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); - return allElements.stream().filter(htmlElement -> htmlElement.attr("class").contains("link") && - links.stream().noneMatch(link -> - htmlElement.attr("id").equals(link.getInnerSeleniumElement().attr("id")))).findFirst(); + final List allElements = $$(By.cssSelector(SELECTOR + " #v_7 > *")); + return allElements.stream() + .filter(htmlElement -> + htmlElement.attr("class").contains("link") && + links.stream().noneMatch(link -> htmlElement.attr("id") + .equals(link.getInnerSeleniumElement().attr("id"))) + ).findFirst(); } private static String createDiv(String divName) { @@ -181,13 +184,13 @@ private void removeSceneElement(SceneElement sceneElement) { e.printStackTrace(); } $(By.id("scene-context-menu")).click(); - blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream() - .filter(x -> x.attr("class").equals(Block.className)) + blocks = $$(By.cssSelector(SELECTOR + " #v_7 > *")).stream() + .filter(x -> x.attr("class").contains(Block.CLASS_NAME)) .map(x -> new Block("name", x)) .collect(Collectors.toSet()); - links = $$(By.cssSelector(selector + " #v_7 > *")).stream() - .filter(x -> x.attr("class").equals(Link.className)) + links = $$(By.cssSelector(SELECTOR + " #v_7 > *")).stream() + .filter(x -> x.attr("class").contains(Link.CLASS_NAME)) .map(x -> new Link("name", x)) .collect(Collectors.toSet()); } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 8c6edbe7..0e1b5d49 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -102,6 +102,5 @@ public void moveElement() { @After public void stopDriver() { scene.clean(); - driver.quit(); } } diff --git a/ui-testing/ui-testing.iml b/ui-testing/ui-testing.iml index 524ad45c..f1174f95 100644 --- a/ui-testing/ui-testing.iml +++ b/ui-testing/ui-testing.iml @@ -2,7 +2,11 @@ - + + + file://$MODULE_DIR$/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java + + From 7403a31a74fd9f5c1af708937dfb2b9d699831bb Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 20:23:49 +0300 Subject: [PATCH 23/40] Add class PalleteElement + code refactor --- .../qreal/wmp/uitesting/config/DevConfig.java | 1 + .../uitesting/dia/model/PalleteElement.java | 23 +++++++++++++++++++ .../wmp/uitesting/dia/model/SceneWindow.java | 7 +++--- .../wmp/uitesting/dia/services/Pallete.java | 5 ++-- .../dia/services/PropertyEditor.java | 2 +- .../wmp/uitesting/dia/services/Scene.java | 6 ++--- .../wmp/uitesting/innertests/AuthTest.java | 23 +------------------ .../wmp/uitesting/innertests/DiaTest.java | 7 ++---- .../testspace/DiagramConstructingTest.java | 9 ++------ 9 files changed, 40 insertions(+), 43 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/PalleteElement.java diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index b865dfdf..ed381b03 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -3,6 +3,7 @@ import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.Auther; import com.qreal.wmp.uitesting.Opener; +import com.qreal.wmp.uitesting.dia.model.SceneWindow; import com.qreal.wmp.uitesting.dia.services.Pallete; import com.qreal.wmp.uitesting.dia.services.PropertyEditor; import com.qreal.wmp.uitesting.dia.services.Scene; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/PalleteElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/PalleteElement.java new file mode 100644 index 00000000..7a2de260 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/PalleteElement.java @@ -0,0 +1,23 @@ +package com.qreal.wmp.uitesting.dia.model; + +import com.codeborne.selenide.SelenideElement; + +public class PalleteElement { + + private final SelenideElement inner; + + private final String name; + + public PalleteElement(SelenideElement inner) { + this.inner = inner; + name = inner.attr("data-type"); + } + + public SelenideElement getInner() { + return inner; + } + + public String getName() { + return name; + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java index 37dd3ab2..a32be6a0 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java @@ -184,11 +184,12 @@ private void updateCanvasInfo() { } } + // todo: make it waits real time until action is completed private void sendKey(Keys key) { new Actions(driver).sendKeys(key).perform(); try { - // wait until action is completed - Thread.sleep(50); + // wait hard coded time until action is completed + Thread.sleep(30); } catch (InterruptedException e) { e.printStackTrace(); } @@ -196,7 +197,7 @@ private void sendKey(Keys key) { private void updateSteps() { updateCanvasInfo(); - $(Scene.selector).click(); + $(Scene.SELECTOR).click(); focus(new Coordinate(0, 0)); updateCanvasInfo(); sendKey(Keys.DOWN); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java index e39846c8..bc4701c7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java @@ -1,6 +1,7 @@ package com.qreal.wmp.uitesting.dia.services; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.model.PalleteElement; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.slf4j.Logger; @@ -25,10 +26,10 @@ public class Pallete { * @param elementName name of block * @return block */ - public SelenideElement getElement(final String elementName) throws NoSuchElementException { + public PalleteElement getElement(final String elementName) throws NoSuchElementException { final SelenideElement element = $(By.cssSelector(SELECTOR)).find(withText(elementName)); logger.info("Get element {} from Palette", element); - return element; + return new PalleteElement(element); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java index e2c7e10c..ca63b70b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java @@ -36,7 +36,7 @@ public void setProperty(final SelenideElement element, final String propertyName /** Return the value of property by name. */ public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException { - $(By.cssSelector(Scene.selector)).click(); + $(By.cssSelector(Scene.SELECTOR)).click(); element.click(); SelenideElement property = getInputOfElement(propertyName); logger.info("Get value of preperty {}", propertyName); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java index 699ef51f..4a2174e7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java @@ -54,8 +54,8 @@ public void init() { * @param element chosen web element * @return element from scene */ - public Block dragAndDrop(final SelenideElement element) { - element.dragAndDropTo(SELECTOR); + public Block dragAndDrop(final PalleteElement element) { + element.getInner().dragAndDropTo(SELECTOR); final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); Block newBlock = new Block("name", newEl); blocks.add(newBlock); @@ -71,7 +71,7 @@ public Block dragAndDrop(final SelenideElement element) { * @param cell_y y-coordinate of cell * @return element from scene */ - public Block dragAndDrop(final SelenideElement element, int cell_x, int cell_y) { + public Block dragAndDrop(final PalleteElement element, int cell_x, int cell_y) { Block newBlock = dragAndDrop(element); moveToCell(newBlock, cell_x, cell_y); return newBlock; diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java index 8d67e752..14cd7711 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java @@ -35,21 +35,6 @@ public class AuthTest { @Autowired private Opener opener; - @Autowired - private WebDriver driver; - - /** Setup ChromeDriverManager. */ - @BeforeClass - public static void init() { - ChromeDriverManager.getInstance().setup(); - } - - /** Setup browser. */ - @Before - public void runDriver() { - WebDriverRunner.setWebDriver(driver); - } - /** * Try to login with correct username and password. * Should redirect to OAuth page. @@ -110,13 +95,7 @@ public void editorTest() { opener.open("editor"); $(byText("Property Editor")).waitUntil(appear, 5000); } - - /** Close the browser. */ - @After - public void stopDriver() { - driver.close(); - } - + /** * Check that current page is Auth page. * diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 0e1b5d49..ad0e0d27 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -35,13 +35,10 @@ public class DiaTest { @Autowired private PropertyEditor propertyEditor; - - @Autowired - private WebDriver driver; /** Setup browser. */ @Before - public void runDriver() { + public void openEditor() { opener.open("editor"); } @@ -100,7 +97,7 @@ public void moveElement() { /** Close the browser. */ @After - public void stopDriver() { + public void cleanScene() { scene.clean(); } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 5961f679..21d7c792 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -1,6 +1,5 @@ package com.qreal.wmp.uitesting.testspace; -import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.model.Block; @@ -8,14 +7,10 @@ import com.qreal.wmp.uitesting.dia.services.Pallete; import com.qreal.wmp.uitesting.dia.services.PropertyEditor; import com.qreal.wmp.uitesting.dia.services.Scene; -import io.github.bonigarcia.wdm.ChromeDriverManager; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -45,7 +40,7 @@ public class DiagramConstructingTest { private ArrayList links; @Before - public void runDriver() { + public void openEditor() { opener.open("editor"); elements = new ArrayList<>(); @@ -86,7 +81,7 @@ public void fillProperties() { } @After - public void stopDriver() { + public void cleanScene() { scene.clean(); } From dc0b9c229f45f345bf88a9e9f4179a48bbc5f740 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 22:21:45 +0300 Subject: [PATCH 24/40] Code refactor --- .../qreal/wmp/uitesting/config/DevConfig.java | 26 ++++--- .../wmp/uitesting/dia/pallete/Pallete.java | 18 +++++ .../{model => pallete}/PalleteElement.java | 2 +- .../Pallete.java => pallete/PalleteImpl.java} | 17 +---- .../dia/propery_editor/PropertyEditor.java | 13 ++++ .../PropertyEditorImpl.java} | 18 +++-- .../qreal/wmp/uitesting/dia/scene/Scene.java | 45 +++++++++++ .../Scene.java => scene/SceneImpl.java} | 76 ++++++++++--------- .../dia/scene/SceneWindow/SceneWindow.java | 23 ++++++ .../SceneWindow/SceneWindowImpl.java} | 21 +++-- .../dia/{model => scene/elements}/Block.java | 6 +- .../dia/{model => scene/elements}/Link.java | 9 ++- .../dia/scene/elements/SceneElement.java | 14 ++++ .../elements/SceneElementImpl.java} | 13 ++-- .../dia/{model => utils}/Coordinate.java | 2 +- .../qreal/wmp/uitesting/services/Auther.java | 17 +++++ .../qreal/wmp/uitesting/services/Opener.java | 21 +++++ .../impl/AutherImpl.java} | 16 ++-- .../impl/OpenerImpl.java} | 28 ++----- .../wmp/uitesting/innertests/AuthTest.java | 11 +-- .../wmp/uitesting/innertests/DiaTest.java | 13 ++-- .../testspace/DiagramConstructingTest.java | 12 +-- 22 files changed, 274 insertions(+), 147 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{model => pallete}/PalleteElement.java (88%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{services/Pallete.java => pallete/PalleteImpl.java} (69%) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{services/PropertyEditor.java => propery_editor/PropertyEditorImpl.java} (86%) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{services/Scene.java => scene/SceneImpl.java} (85%) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{model/SceneWindow.java => scene/SceneWindow/SceneWindowImpl.java} (94%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{model => scene/elements}/Block.java (75%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{model => scene/elements}/Link.java (77%) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{model/SceneElement.java => scene/elements/SceneElementImpl.java} (68%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{model => utils}/Coordinate.java (97%) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/{Auther.java => services/impl/AutherImpl.java} (79%) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/{Opener.java => services/impl/OpenerImpl.java} (73%) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index ed381b03..f0dcbd9a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -1,12 +1,16 @@ package com.qreal.wmp.uitesting.config; import com.codeborne.selenide.WebDriverRunner; -import com.qreal.wmp.uitesting.Auther; -import com.qreal.wmp.uitesting.Opener; -import com.qreal.wmp.uitesting.dia.model.SceneWindow; -import com.qreal.wmp.uitesting.dia.services.Pallete; -import com.qreal.wmp.uitesting.dia.services.PropertyEditor; -import com.qreal.wmp.uitesting.dia.services.Scene; +import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; +import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditor; +import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditorImpl; +import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.dia.scene.SceneImpl; +import com.qreal.wmp.uitesting.services.Auther; +import com.qreal.wmp.uitesting.services.Opener; +import com.qreal.wmp.uitesting.services.impl.AutherImpl; +import com.qreal.wmp.uitesting.services.impl.OpenerImpl; import io.github.bonigarcia.wdm.ChromeDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; @@ -41,26 +45,26 @@ public WebDriver webDriver() { @Bean public Scene scene() { - return new Scene(webDriver()); + return new SceneImpl(webDriver()); } @Bean public Auther auther() { - return new Auther(environment); + return new AutherImpl(environment); } @Bean public Opener opener() { - return new Opener(environment, auther(), scene()); + return new OpenerImpl(environment, auther(), scene()); } @Bean public PropertyEditor propertyEditor() { - return new PropertyEditor(); + return new PropertyEditorImpl(scene()); } @Bean public Pallete pallete() { - return new Pallete(); + return new PalleteImpl(); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java new file mode 100644 index 00000000..bb1e604d --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java @@ -0,0 +1,18 @@ +package com.qreal.wmp.uitesting.dia.pallete; + +import org.openqa.selenium.NoSuchElementException; + +/** + * Describes Pallete. + * For any manipulating with it. + */ +public interface Pallete { + + /** + * Chose element from Pallete. + * + * @param elementName name of block + * @return block + */ + PalleteElement getElement(String elementName) throws NoSuchElementException; +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/PalleteElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java similarity index 88% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/PalleteElement.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java index 7a2de260..4a464e36 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/PalleteElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.dia.model; +package com.qreal.wmp.uitesting.dia.pallete; import com.codeborne.selenide.SelenideElement; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java similarity index 69% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java index bc4701c7..913697f7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java @@ -1,7 +1,6 @@ -package com.qreal.wmp.uitesting.dia.services; +package com.qreal.wmp.uitesting.dia.pallete; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.model.PalleteElement; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.slf4j.Logger; @@ -10,22 +9,12 @@ import static com.codeborne.selenide.Selectors.withText; import static com.codeborne.selenide.Selenide.$; -/** - * Describes Pallete. - * For any manipulating with it. - */ -public class Pallete { +public class PalleteImpl implements Pallete { private static final String SELECTOR = "#palette-tab-content"; - private static final Logger logger = LoggerFactory.getLogger(Pallete.class); + private static final Logger logger = LoggerFactory.getLogger(PalleteImpl.class); - /** - * Chose element from Pallete. - * - * @param elementName name of block - * @return block - */ public PalleteElement getElement(final String elementName) throws NoSuchElementException { final SelenideElement element = $(By.cssSelector(SELECTOR)).find(withText(elementName)); logger.info("Get element {} from Palette", element); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java new file mode 100644 index 00000000..47fb46d0 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java @@ -0,0 +1,13 @@ +package com.qreal.wmp.uitesting.dia.propery_editor; + +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.NoSuchElementException; + +/** Describe Property Editor. */ +public interface PropertyEditor { + /** Set property of element which on the focus. */ + void setProperty(SelenideElement element, String propertyName, String propertyValue) throws NoSuchElementException; + + /** Return the value of property by name. */ + String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException; +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditorImpl.java similarity index 86% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditorImpl.java index ca63b70b..5b33f16b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/PropertyEditor.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditorImpl.java @@ -1,6 +1,7 @@ -package com.qreal.wmp.uitesting.dia.services; +package com.qreal.wmp.uitesting.dia.propery_editor; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.scene.Scene; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.slf4j.Logger; @@ -13,14 +14,18 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; -/** Describe Property Editor. */ -public class PropertyEditor { +public class PropertyEditorImpl implements PropertyEditor { private static final String SELECTOR = "#property_table"; - private static final Logger logger = LoggerFactory.getLogger(PropertyEditor.class); + private static final Logger logger = LoggerFactory.getLogger(PropertyEditorImpl.class); - /** Set property of element which on the focus. */ + private final Scene scene; + + public PropertyEditorImpl(Scene scene) { + this.scene = scene; + } + public void setProperty(final SelenideElement element, final String propertyName, final String propertyValue) throws NoSuchElementException { @@ -34,9 +39,8 @@ public void setProperty(final SelenideElement element, final String propertyName logger.info("Set property {} to {}", propertyName, propertyValue); } - /** Return the value of property by name. */ public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException { - $(By.cssSelector(Scene.SELECTOR)).click(); + $(By.cssSelector(scene.getSelector())).click(); element.click(); SelenideElement property = getInputOfElement(propertyName); logger.info("Get value of preperty {}", propertyName); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java new file mode 100644 index 00000000..3771ae3b --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -0,0 +1,45 @@ +package com.qreal.wmp.uitesting.dia.scene; + +import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.scene.elements.Link; +import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; + +import java.util.List; + +public interface Scene { + /** Init the scene */ + void init(); + + /** Return selector of Scene in html-page */ + String getSelector(); + + /** Drag element from scene or pallete and put it on the center of scene. */ + Block dragAndDrop(PalleteElement palleteElement); + + /** Drag element from scene or pallete and put it in cell of the scene. */ + Block dragAndDrop(PalleteElement element, int cell_x, int cell_y); + + void moveToCell(Block block, int cell_x, int cell_y); + + /** Focus the element. */ + void focus(SceneElement element); + + /** Check if element exist on the scene. */ + boolean exist(SceneElement element); + + /** Remove block from the scene. */ + void remove(Block block); + + /** Remove link from the scene. */ + void remove(Link link); + + /** Add link between two elements. */ + Link addLink(Block source, Block target); + + /** Return all blocks. */ + List getBlocks(); + + /** Remove all elements from the scene. */ + void clean(); +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java similarity index 85% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 4a2174e7..e3dd5999 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/services/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -1,7 +1,14 @@ -package com.qreal.wmp.uitesting.dia.services; +package com.qreal.wmp.uitesting.dia.scene; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.model.*; +import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; +import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; +import com.qreal.wmp.uitesting.dia.scene.SceneWindow.SceneWindow; +import com.qreal.wmp.uitesting.dia.scene.SceneWindow.SceneWindowImpl; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.scene.elements.Link; +import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; +import com.qreal.wmp.uitesting.dia.utils.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -21,11 +28,11 @@ * Describes Scene of Editor. * Can add rm and manipulate with objects on that area. */ -public class Scene { +public class SceneImpl implements Scene { - public static final String SELECTOR = ".scene-wrapper"; + private static final String SELECTOR = ".scene-wrapper"; - private static final Logger logger = LoggerFactory.getLogger(Pallete.class); + private static final Logger logger = LoggerFactory.getLogger(PalleteImpl.class); private Set blocks = new HashSet<>(); @@ -34,11 +41,12 @@ public class Scene { private WebDriver webDriver; /** For actions such as mouse move we need driver of current page. */ - public Scene(WebDriver webDriver) { + public SceneImpl(WebDriver webDriver) { this.webDriver = webDriver; } /** Creates divs for SceneWindow. */ + @Override public void init() { if (webDriver instanceof JavascriptExecutor) { ((JavascriptExecutor) webDriver).executeScript( @@ -47,13 +55,13 @@ public void init() { ); } } - - /** - * Drag element from scene or pallete and put it on the center of scene. - * - * @param element chosen web element - * @return element from scene - */ + + @Override + public String getSelector() { + return SELECTOR; + } + + @Override public Block dragAndDrop(final PalleteElement element) { element.getInner().dragAndDropTo(SELECTOR); final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); @@ -62,24 +70,17 @@ public Block dragAndDrop(final PalleteElement element) { logger.info("Add element {} to scene", newEl); return newBlock; } - - /** - * element from scene or pallete and put it in cell of the scene. - * - * @param element chosen web element - * @param cell_x x-coordinate of cell - * @param cell_y y-coordinate of cell - * @return element from scene - */ + + @Override public Block dragAndDrop(final PalleteElement element, int cell_x, int cell_y) { Block newBlock = dragAndDrop(element); moveToCell(newBlock, cell_x, cell_y); return newBlock; } - - /** Move element to cell. */ + + @Override public void moveToCell(final Block block, final int cell_x, final int cell_y) { - SceneWindow sceneWindow = new SceneWindow(this, webDriver); + SceneWindow sceneWindow = new SceneWindowImpl(this, webDriver); logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); try { sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); @@ -87,10 +88,10 @@ public void moveToCell(final Block block, final int cell_x, final int cell_y) { e.printStackTrace(); } } - - /** Focus the element. */ + + @Override public void focus(final SceneElement element) { - SceneWindow sceneWindow = new SceneWindow(this, webDriver); + SceneWindow sceneWindow = new SceneWindowImpl(this, webDriver); logger.info("Focus on the element {}", element); try { sceneWindow.focus(element.getCoordinateOnScene()); @@ -98,22 +99,23 @@ public void focus(final SceneElement element) { e.printStackTrace(); } } - - /** Check if element exist on the scene. */ + + @Override public boolean exist(SceneElement element) { return blocks.stream().anyMatch(element::equals) || links.stream().anyMatch(element::equals); } - /** Remove element from the scene. */ + @Override public void remove(Block block) { removeSceneElement(block); } + @Override public void remove(Link link) { removeSceneElement(link.getSource()); } - - /** Remove all elements from the scene. */ + + @Override public void clean() { if (!links.isEmpty()) { remove(links.stream().collect(Collectors.toList()).get(0)); @@ -127,8 +129,8 @@ public void clean() { } } } - - /** Add link between two elements. */ + + @Override public Link addLink(final Block source, final Block target) { final SelenideElement begin = $(By.cssSelector(SELECTOR + " #" + source.getInnerSeleniumElement().attr("id") + " .outPorts")); @@ -142,8 +144,8 @@ public Link addLink(final Block source, final Block target) { links.add(res); return res; } - - /** Return all blocks. */ + + @Override public List getBlocks() { return blocks.stream().collect(Collectors.toList()); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java new file mode 100644 index 00000000..f5de0eb7 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java @@ -0,0 +1,23 @@ +package com.qreal.wmp.uitesting.dia.scene.SceneWindow; + +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.utils.Coordinate; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; + +public interface SceneWindow { + + /** + * Moves element to the requested position. + * + * @param element element to move + * @param dist position to move + * */ + void move(final Block element, final Coordinate dist) throws ElementNotOnTheSceneException; + + /** + * Move the screen to requested position. + * + * @param coordinate coordinate to move + */ + void focus(final Coordinate coordinate); +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindowImpl.java similarity index 94% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindowImpl.java index a32be6a0..0b7f82fa 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneWindow.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindowImpl.java @@ -1,7 +1,9 @@ -package com.qreal.wmp.uitesting.dia.model; +package com.qreal.wmp.uitesting.dia.scene.SceneWindow; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.services.Scene; +import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.utils.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -18,7 +20,7 @@ /** * Describes part of the scene, which is shown on browser. */ -public class SceneWindow { +public class SceneWindowImpl implements SceneWindow { /** Link to full scene. */ private final Scene scene; @@ -29,10 +31,10 @@ public class SceneWindow { private final WebDriver driver; - private static final Logger logger = LoggerFactory.getLogger(SceneWindow.class); + private static final Logger logger = LoggerFactory.getLogger(SceneWindowImpl.class); /** Constructor takes links to current scene and current driver. */ - public SceneWindow(final Scene scene, final WebDriver driver) { + public SceneWindowImpl(final Scene scene, final WebDriver driver) { this.scene = scene; this.driver = driver; updateSteps(); @@ -44,6 +46,7 @@ public SceneWindow(final Scene scene, final WebDriver driver) { * @param element element to move * @param dist position to move */ + @Override public void move(final Block element, final Coordinate dist) throws ElementNotOnTheSceneException { Coordinate src = element.getCoordinateOnScene(); focus(src); @@ -70,11 +73,7 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn } } - /** - * Move the screen to requested position. - * - * @param coordinate coordinate to move - */ + @Override public void focus(final Coordinate coordinate) { logger.debug("Focus to " + coordinate.getXAbsolute() + " " + coordinate.getYAbsolute()); horizontalWindowMovement(coordinate.getXAbsolute()); @@ -197,7 +196,7 @@ private void sendKey(Keys key) { private void updateSteps() { updateCanvasInfo(); - $(Scene.SELECTOR).click(); + $(scene.getSelector()).click(); focus(new Coordinate(0, 0)); updateCanvasInfo(); sendKey(Keys.DOWN); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java similarity index 75% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java index 55d6ac5d..757552be 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Block.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java @@ -1,11 +1,11 @@ -package com.qreal.wmp.uitesting.dia.model; +package com.qreal.wmp.uitesting.dia.scene.elements; import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.$; -public class Block extends SceneElement { +public class Block extends SceneElementImpl { public static final String CLASS_NAME = "element devs ImageWithPorts"; @@ -18,7 +18,7 @@ public class Block extends SceneElement { public Block(String name, SelenideElement innerSeleniumObject) { super(innerSeleniumObject); this.name = name; - this.port = new SceneElement($(innerSeleniumObject.find(By.className(PORT_CLASS_NAME)))); + this.port = new SceneElementImpl($(innerSeleniumObject.find(By.className(PORT_CLASS_NAME)))); } public String getName() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java similarity index 77% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java index b09ec41b..43f2f5c9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java @@ -1,12 +1,13 @@ -package com.qreal.wmp.uitesting.dia.model; +package com.qreal.wmp.uitesting.dia.scene.elements; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.utils.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.$; -public class Link extends SceneElement { +public class Link extends SceneElementImpl { public static final String CLASS_NAME = "link"; @@ -23,8 +24,8 @@ public class Link extends SceneElement { public Link(String name, SelenideElement innerSeleniumObject) { super(innerSeleniumObject); this.name = name; - this.source = new SceneElement($(innerSeleniumObject.find(By.className(SOURCE_POINT_CLASSNAME)))); - this.target = new SceneElement($(innerSeleniumObject.find(By.className(TARGET_POINT_CLASSNAME)))); + this.source = new SceneElementImpl($(innerSeleniumObject.find(By.className(SOURCE_POINT_CLASSNAME)))); + this.target = new SceneElementImpl($(innerSeleniumObject.find(By.className(TARGET_POINT_CLASSNAME)))); } public String getName() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java new file mode 100644 index 00000000..bf722267 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java @@ -0,0 +1,14 @@ +package com.qreal.wmp.uitesting.dia.scene.elements; + +import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.utils.Coordinate; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; + +/** Describes any element on the Scene. */ +public interface SceneElement { + SelenideElement getInnerSeleniumElement(); + + Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException; + + String getType(); +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java similarity index 68% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java index 4eb80426..9f44cdc8 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/SceneElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java @@ -1,20 +1,21 @@ -package com.qreal.wmp.uitesting.dia.model; +package com.qreal.wmp.uitesting.dia.scene.elements; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.utils.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -public class SceneElement { +public class SceneElementImpl implements SceneElement { private final SelenideElement innerSeleniumElement; private String type; - /** - * Describes any element on the Scene. - * */ - public SceneElement(SelenideElement innerSeleniumObject) { + public SceneElementImpl(SelenideElement innerSeleniumObject) { this.innerSeleniumElement = innerSeleniumObject; this.type = innerSeleniumObject.attr("class"); + if (type.contains("selected")) { + type = type.substring(0, type.indexOf(" selected")); + } } public SelenideElement getInnerSeleniumElement() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/utils/Coordinate.java similarity index 97% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/utils/Coordinate.java index 300a09e6..859d48b1 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/model/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/utils/Coordinate.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.dia.model; +package com.qreal.wmp.uitesting.dia.utils; import com.codeborne.selenide.SelenideElement; import org.jetbrains.annotations.NotNull; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java new file mode 100644 index 00000000..4b7480a3 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java @@ -0,0 +1,17 @@ +package com.qreal.wmp.uitesting.services; + +import com.qreal.wmp.uitesting.exceptions.WrongAuthException; + +/** Used for authentication in current browser session. */ +public interface Auther { + + /** Realizes authentication to the wmp. + * + * @param username login + * @param password password + * */ + void auth(final String username, final String password) throws WrongAuthException; + + /** Authentication with fixed login and password */ + void auth() throws WrongAuthException; +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java new file mode 100644 index 00000000..a9606470 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java @@ -0,0 +1,21 @@ +package com.qreal.wmp.uitesting.services; + +/** + * Used for open needed page from wmp in current browser session. + * Allows you to access as an authorized user and not. + */ +public interface Opener { + /** + * Opens page from wmp with authentication. + * + * @param page must be one of the keys from pages.property. + */ + void open(final String page); + + /** + * Opens page from wmp without authentication. + * + * @param page must be one of the keys from pages.property. + */ + void cleanOpen(final String page); +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java similarity index 79% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java index 72897982..db1394e1 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Auther.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java @@ -1,6 +1,7 @@ -package com.qreal.wmp.uitesting; +package com.qreal.wmp.uitesting.services.impl; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; +import com.qreal.wmp.uitesting.services.Auther; import org.openqa.selenium.By; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,22 +11,17 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.open; -/** Used for authentication in current browser session. */ -public class Auther { +public class AutherImpl implements Auther { /** Use properties from pages.properies file. */ private Environment env; - private static final Logger logger = LoggerFactory.getLogger(Auther.class); + private static final Logger logger = LoggerFactory.getLogger(AutherImpl.class); - public Auther(Environment env) { + public AutherImpl(Environment env) { this.env = env; } - /** Realizes authentication to the wmp. - * - * @param username login - * @param password password - * */ + public void auth(final String username, final String password) throws WrongAuthException { open(env.getProperty("auth")); $(By.name("username")).setValue(username); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java similarity index 73% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java index d2142415..df31f047 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Opener.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java @@ -1,7 +1,9 @@ -package com.qreal.wmp.uitesting; +package com.qreal.wmp.uitesting.services.impl; -import com.qreal.wmp.uitesting.dia.services.Scene; +import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; +import com.qreal.wmp.uitesting.services.Auther; +import com.qreal.wmp.uitesting.services.Opener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; @@ -10,11 +12,7 @@ import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; -/** - * Used for open needed page from wmp in current browser session. - * Allows you to access as an authorized user and not. - */ -public class Opener { +public class OpenerImpl implements Opener { /** Uses properties from pages.properies file. */ private Environment env; @@ -22,19 +20,14 @@ public class Opener { private Auther auther; private Scene scene; - private static final Logger logger = LoggerFactory.getLogger(Opener.class); + private static final Logger logger = LoggerFactory.getLogger(OpenerImpl.class); - public Opener(Environment env, Auther auther, Scene scene) { + public OpenerImpl(Environment env, Auther auther, Scene scene) { this.env = env; this.auther = auther; this.scene = scene; } - /** - * Opens page from wmp with authentication. - * - * @param page must be one of the keys from pages.property. - */ public void open(final String page) { try { com.codeborne.selenide.Selenide.open(env.getProperty(page)); @@ -52,12 +45,7 @@ public void open(final String page) { logger.info("Open page {}", env.getProperty(page)); scene.init(); } - - /** - * Opens page from wmp without authentication. - * - * @param page must be one of the keys from pages.property. - */ + public void cleanOpen(final String page) { com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java index 14cd7711..f79c6b78 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java @@ -1,19 +1,12 @@ package com.qreal.wmp.uitesting.innertests; -import com.codeborne.selenide.WebDriverRunner; -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; +import com.qreal.wmp.uitesting.services.Auther; +import com.qreal.wmp.uitesting.services.Opener; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index ad0e0d27..59e9dcf1 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -1,18 +1,17 @@ package com.qreal.wmp.uitesting.innertests; -import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; -import com.qreal.wmp.uitesting.dia.model.Block; -import com.qreal.wmp.uitesting.dia.model.Link; -import com.qreal.wmp.uitesting.dia.services.Pallete; -import com.qreal.wmp.uitesting.dia.services.PropertyEditor; -import com.qreal.wmp.uitesting.dia.services.Scene; +import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditor; +import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; +import com.qreal.wmp.uitesting.services.Opener; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.openqa.selenium.WebDriver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 21d7c792..fe6c85a9 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -1,12 +1,12 @@ package com.qreal.wmp.uitesting.testspace; -import com.qreal.wmp.uitesting.Opener; import com.qreal.wmp.uitesting.config.AppInit; -import com.qreal.wmp.uitesting.dia.model.Block; -import com.qreal.wmp.uitesting.dia.model.Link; -import com.qreal.wmp.uitesting.dia.services.Pallete; -import com.qreal.wmp.uitesting.dia.services.PropertyEditor; -import com.qreal.wmp.uitesting.dia.services.Scene; +import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditor; +import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.scene.elements.Link; +import com.qreal.wmp.uitesting.services.Opener; import org.junit.After; import org.junit.Before; import org.junit.Test; From 56672d08b04c959691e71775697c85ab31f0905a Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 23:18:11 +0300 Subject: [PATCH 25/40] Code refactor --- .../wmp/uitesting/InitializedComponent.java | 8 +++ .../qreal/wmp/uitesting/config/DevConfig.java | 9 +-- .../wmp/uitesting/dia/pallete/Pallete.java | 16 ++--- .../uitesting/dia/pallete/PalleteElement.java | 32 ++++----- .../dia/property/PropertyEditor.java | 13 ++++ .../PropertyEditorImpl.java | 6 +- .../dia/propery_editor/PropertyEditor.java | 13 ---- .../dia/{utils => scene}/Coordinate.java | 2 +- .../qreal/wmp/uitesting/dia/scene/Scene.java | 65 +++++++++---------- .../wmp/uitesting/dia/scene/SceneImpl.java | 16 +++-- .../dia/scene/SceneWindow/SceneWindow.java | 23 ------- .../uitesting/dia/scene/elements/Link.java | 2 +- .../dia/scene/elements/SceneElement.java | 12 ++-- .../dia/scene/elements/SceneElementImpl.java | 3 +- .../dia/scene/window/SceneWindow.java | 23 +++++++ .../SceneWindowImpl.java | 6 +- .../qreal/wmp/uitesting/services/Auther.java | 20 +++--- .../qreal/wmp/uitesting/services/Opener.java | 26 ++++---- .../uitesting/services/impl/AutherImpl.java | 1 + .../uitesting/services/impl/OpenerImpl.java | 16 +++-- .../wmp/uitesting/innertests/DiaTest.java | 2 +- .../testspace/DiagramConstructingTest.java | 2 +- 22 files changed, 168 insertions(+), 148 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{propery_editor => property}/PropertyEditorImpl.java (96%) delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{utils => scene}/Coordinate.java (97%) delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindow.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/{SceneWindow => window}/SceneWindowImpl.java (98%) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java new file mode 100644 index 00000000..7236407b --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java @@ -0,0 +1,8 @@ +package com.qreal.wmp.uitesting; + +/** Opening some pages must initialize included components. */ +public interface InitializedComponent { + void init(); + + boolean name(String name); +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index f0dcbd9a..b607c41b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -1,10 +1,11 @@ package com.qreal.wmp.uitesting.config; import com.codeborne.selenide.WebDriverRunner; +import com.qreal.wmp.uitesting.InitializedComponent; import com.qreal.wmp.uitesting.dia.pallete.Pallete; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; -import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditor; -import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditorImpl; +import com.qreal.wmp.uitesting.dia.property.PropertyEditor; +import com.qreal.wmp.uitesting.dia.property.PropertyEditorImpl; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.SceneImpl; import com.qreal.wmp.uitesting.services.Auther; @@ -27,7 +28,7 @@ public class DevConfig { @Autowired - Environment environment; + private Environment environment; /** Processor for Environment linked to property files.*/ @Bean @@ -55,7 +56,7 @@ public Auther auther() { @Bean public Opener opener() { - return new OpenerImpl(environment, auther(), scene()); + return new OpenerImpl(environment, auther(), (InitializedComponent) scene()); } @Bean diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java index bb1e604d..b3ce553e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java @@ -7,12 +7,12 @@ * For any manipulating with it. */ public interface Pallete { - - /** - * Chose element from Pallete. - * - * @param elementName name of block - * @return block - */ - PalleteElement getElement(String elementName) throws NoSuchElementException; + + /** + * Chose element from Pallete. + * + * @param elementName name of block + * @return block + */ + PalleteElement getElement(String elementName) throws NoSuchElementException; } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java index 4a464e36..6c724a5c 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java @@ -4,20 +4,20 @@ public class PalleteElement { - private final SelenideElement inner; - - private final String name; - - public PalleteElement(SelenideElement inner) { - this.inner = inner; - name = inner.attr("data-type"); - } - - public SelenideElement getInner() { - return inner; - } - - public String getName() { - return name; - } + private final SelenideElement inner; + + private final String name; + + public PalleteElement(SelenideElement inner) { + this.inner = inner; + name = inner.attr("data-type"); + } + + public SelenideElement getInner() { + return inner; + } + + public String getName() { + return name; + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java new file mode 100644 index 00000000..ab23dbae --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java @@ -0,0 +1,13 @@ +package com.qreal.wmp.uitesting.dia.property; + +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.NoSuchElementException; + +/** Describe Property Editor. */ +public interface PropertyEditor { + /** Set property of element which on the focus. */ + void setProperty(SelenideElement element, String propertyName, String propertyValue) throws NoSuchElementException; + + /** Return the value of property by name. */ + String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException; +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditorImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java similarity index 96% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditorImpl.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java index 5b33f16b..efe5e924 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditorImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.dia.propery_editor; +package com.qreal.wmp.uitesting.dia.property; import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.scene.Scene; @@ -26,6 +26,7 @@ public PropertyEditorImpl(Scene scene) { this.scene = scene; } + /** {@inheritDoc} */ public void setProperty(final SelenideElement element, final String propertyName, final String propertyValue) throws NoSuchElementException { @@ -38,7 +39,8 @@ public void setProperty(final SelenideElement element, final String propertyName } logger.info("Set property {} to {}", propertyName, propertyValue); } - + + /** {@inheritDoc} */ public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException { $(By.cssSelector(scene.getSelector())).click(); element.click(); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java deleted file mode 100644 index 47fb46d0..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/propery_editor/PropertyEditor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.qreal.wmp.uitesting.dia.propery_editor; - -import com.codeborne.selenide.SelenideElement; -import org.openqa.selenium.NoSuchElementException; - -/** Describe Property Editor. */ -public interface PropertyEditor { - /** Set property of element which on the focus. */ - void setProperty(SelenideElement element, String propertyName, String propertyValue) throws NoSuchElementException; - - /** Return the value of property by name. */ - String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException; -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/utils/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java similarity index 97% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/utils/Coordinate.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java index 859d48b1..6380db19 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/utils/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.dia.utils; +package com.qreal.wmp.uitesting.dia.scene; import com.codeborne.selenide.SelenideElement; import org.jetbrains.annotations.NotNull; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java index 3771ae3b..22604990 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -8,38 +8,35 @@ import java.util.List; public interface Scene { - /** Init the scene */ - void init(); - - /** Return selector of Scene in html-page */ - String getSelector(); - - /** Drag element from scene or pallete and put it on the center of scene. */ - Block dragAndDrop(PalleteElement palleteElement); - - /** Drag element from scene or pallete and put it in cell of the scene. */ - Block dragAndDrop(PalleteElement element, int cell_x, int cell_y); - - void moveToCell(Block block, int cell_x, int cell_y); - - /** Focus the element. */ - void focus(SceneElement element); - - /** Check if element exist on the scene. */ - boolean exist(SceneElement element); - - /** Remove block from the scene. */ - void remove(Block block); - - /** Remove link from the scene. */ - void remove(Link link); - - /** Add link between two elements. */ - Link addLink(Block source, Block target); - - /** Return all blocks. */ - List getBlocks(); - - /** Remove all elements from the scene. */ - void clean(); + /** Return selector of Scene in html-page. */ + String getSelector(); + + /** Drag element from scene or pallete and put it on the center of scene. */ + Block dragAndDrop(PalleteElement palleteElement); + + /** Drag element from scene or pallete and put it in cell of the scene. */ + Block dragAndDrop(PalleteElement element, int cell_x, int cell_y); + + void moveToCell(Block block, int cell_x, int cell_y); + + /** Focus the element. */ + void focus(SceneElement element); + + /** Check if element exist on the scene. */ + boolean exist(SceneElement element); + + /** Remove block from the scene. */ + void remove(Block block); + + /** Remove link from the scene. */ + void remove(Link link); + + /** Add link between two elements. */ + Link addLink(Block source, Block target); + + /** Return all blocks. */ + List getBlocks(); + + /** Remove all elements from the scene. */ + void clean(); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index e3dd5999..2002753a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -1,14 +1,14 @@ package com.qreal.wmp.uitesting.dia.scene; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.InitializedComponent; import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; -import com.qreal.wmp.uitesting.dia.scene.SceneWindow.SceneWindow; -import com.qreal.wmp.uitesting.dia.scene.SceneWindow.SceneWindowImpl; +import com.qreal.wmp.uitesting.dia.scene.window.SceneWindow; +import com.qreal.wmp.uitesting.dia.scene.window.SceneWindowImpl; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; -import com.qreal.wmp.uitesting.dia.utils.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -28,7 +28,7 @@ * Describes Scene of Editor. * Can add rm and manipulate with objects on that area. */ -public class SceneImpl implements Scene { +public class SceneImpl implements Scene, InitializedComponent { private static final String SELECTOR = ".scene-wrapper"; @@ -45,9 +45,10 @@ public SceneImpl(WebDriver webDriver) { this.webDriver = webDriver; } - /** Creates divs for SceneWindow. */ + /** Creates divs for window. */ @Override public void init() { + clean(); if (webDriver instanceof JavascriptExecutor) { ((JavascriptExecutor) webDriver).executeScript( createDiv("SceneWindowLeft") + createDiv("SceneWindowTop") + @@ -56,6 +57,11 @@ public void init() { } } + @Override + public boolean name(String name) { + return name.equals("editor"); + } + @Override public String getSelector() { return SELECTOR; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java deleted file mode 100644 index f5de0eb7..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindow.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.qreal.wmp.uitesting.dia.scene.SceneWindow; - -import com.qreal.wmp.uitesting.dia.scene.elements.Block; -import com.qreal.wmp.uitesting.dia.utils.Coordinate; -import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; - -public interface SceneWindow { - - /** - * Moves element to the requested position. - * - * @param element element to move - * @param dist position to move - * */ - void move(final Block element, final Coordinate dist) throws ElementNotOnTheSceneException; - - /** - * Move the screen to requested position. - * - * @param coordinate coordinate to move - */ - void focus(final Coordinate coordinate); -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java index 43f2f5c9..dc0f9775 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java @@ -1,7 +1,7 @@ package com.qreal.wmp.uitesting.dia.scene.elements; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.utils.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java index bf722267..3424db18 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java @@ -1,14 +1,14 @@ package com.qreal.wmp.uitesting.dia.scene.elements; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.utils.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; /** Describes any element on the Scene. */ public interface SceneElement { - SelenideElement getInnerSeleniumElement(); - - Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException; - - String getType(); + SelenideElement getInnerSeleniumElement(); + + Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException; + + String getType(); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java index 9f44cdc8..08e88181 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java @@ -1,7 +1,7 @@ package com.qreal.wmp.uitesting.dia.scene.elements; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.utils.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; public class SceneElementImpl implements SceneElement { @@ -10,6 +10,7 @@ public class SceneElementImpl implements SceneElement { private String type; + /** Based on the Selenium element. */ public SceneElementImpl(SelenideElement innerSeleniumObject) { this.innerSeleniumElement = innerSeleniumObject; this.type = innerSeleniumObject.attr("class"); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindow.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindow.java new file mode 100644 index 00000000..ebe5d8e9 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindow.java @@ -0,0 +1,23 @@ +package com.qreal.wmp.uitesting.dia.scene.window; + +import com.qreal.wmp.uitesting.dia.scene.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; + +public interface SceneWindow { + + /** + * Moves element to the requested position. + * + * @param element element to move + * @param dist position to move + * */ + void move(final Block element, final Coordinate dist) throws ElementNotOnTheSceneException; + + /** + * Move the screen to requested position. + * + * @param coordinate coordinate to move + */ + void focus(final Coordinate coordinate); +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java similarity index 98% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindowImpl.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 0b7f82fa..a9fec4c9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneWindow/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -1,9 +1,9 @@ -package com.qreal.wmp.uitesting.dia.scene.SceneWindow; +package com.qreal.wmp.uitesting.dia.scene.window; import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.scene.Coordinate; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; -import com.qreal.wmp.uitesting.dia.utils.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -188,7 +188,7 @@ private void sendKey(Keys key) { new Actions(driver).sendKeys(key).perform(); try { // wait hard coded time until action is completed - Thread.sleep(30); + Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java index 4b7480a3..ead0f7ab 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java @@ -4,14 +4,14 @@ /** Used for authentication in current browser session. */ public interface Auther { - - /** Realizes authentication to the wmp. - * - * @param username login - * @param password password - * */ - void auth(final String username, final String password) throws WrongAuthException; - - /** Authentication with fixed login and password */ - void auth() throws WrongAuthException; + + /** Realizes authentication to the wmp. + * + * @param username login + * @param password password + * */ + void auth(final String username, final String password) throws WrongAuthException; + + /** Authentication with fixed login and password. */ + void auth() throws WrongAuthException; } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java index a9606470..4ae30ae6 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Opener.java @@ -5,17 +5,17 @@ * Allows you to access as an authorized user and not. */ public interface Opener { - /** - * Opens page from wmp with authentication. - * - * @param page must be one of the keys from pages.property. - */ - void open(final String page); - - /** - * Opens page from wmp without authentication. - * - * @param page must be one of the keys from pages.property. - */ - void cleanOpen(final String page); + /** + * Opens page from wmp with authentication. + * + * @param page must be one of the keys from pages.property. + */ + void open(final String page); + + /** + * Opens page from wmp without authentication. + * + * @param page must be one of the keys from pages.property. + */ + void cleanOpen(final String page); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java index db1394e1..6db732d2 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java @@ -22,6 +22,7 @@ public AutherImpl(Environment env) { this.env = env; } + /** {@inheritDoc} */ public void auth(final String username, final String password) throws WrongAuthException { open(env.getProperty("auth")); $(By.name("username")).setValue(username); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java index df31f047..8fd19272 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java @@ -1,6 +1,6 @@ package com.qreal.wmp.uitesting.services.impl; -import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.InitializedComponent; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import com.qreal.wmp.uitesting.services.Auther; import com.qreal.wmp.uitesting.services.Opener; @@ -9,6 +9,8 @@ import org.springframework.core.env.Environment; import org.springframework.security.access.AccessDeniedException; +import java.util.Arrays; + import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; @@ -18,16 +20,18 @@ public class OpenerImpl implements Opener { private Environment env; private Auther auther; - private Scene scene; + + private InitializedComponent[] components; private static final Logger logger = LoggerFactory.getLogger(OpenerImpl.class); - public OpenerImpl(Environment env, Auther auther, Scene scene) { + public OpenerImpl(Environment env, Auther auther, InitializedComponent... components) { this.env = env; this.auther = auther; - this.scene = scene; + this.components = components; } + /** {@inheritDoc} */ public void open(final String page) { try { com.codeborne.selenide.Selenide.open(env.getProperty(page)); @@ -43,12 +47,12 @@ public void open(final String page) { throw new AccessDeniedException(e.getMessage()); } logger.info("Open page {}", env.getProperty(page)); - scene.init(); + Arrays.stream(components).filter(component -> component.name(page)).forEach(InitializedComponent::init); } public void cleanOpen(final String page) { com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); - scene.init(); + Arrays.stream(components).filter(component -> component.name(page)).forEach(InitializedComponent::init); } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 59e9dcf1..f52fb87d 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -2,7 +2,7 @@ import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.pallete.Pallete; -import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditor; +import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index fe6c85a9..ad4aee89 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -2,7 +2,7 @@ import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.pallete.Pallete; -import com.qreal.wmp.uitesting.dia.propery_editor.PropertyEditor; +import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; From ffdfc411b633e95f7b1902f972dc0461c50e4dd5 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Feb 2017 23:57:00 +0300 Subject: [PATCH 26/40] Add callTomcat.sh --- Travis/callTomcat.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 Travis/callTomcat.sh diff --git a/Travis/callTomcat.sh b/Travis/callTomcat.sh new file mode 100755 index 00000000..df31e8e0 --- /dev/null +++ b/Travis/callTomcat.sh @@ -0,0 +1,47 @@ +#!/bin/bash +iter=1 +all=120 +until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${1:-"8080"}"/auth | grep '302 Found'`" != "" ]; +do + if [ "$iter" -lt "$all" ] + then + echo "--- sleeping for 10 seconds" + sleep 10 + let iter=$iter+1 + else + echo "Server didn't return 302 found for long time" + exit 1 + fi +done +echo "auth-service found" +iter=1 +all=120 +until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${2:-"8082"}"/dashboard | grep '302 Found'`" != "" ]; +do + if [ "$iter" -lt "$all" ] + then + echo "--- sleeping for 10 seconds" + sleep 10 + let iter=$iter+1 + else + echo "Server didn't return 302 found for long time" + exit 1 + fi +done +echo "dashboard-service found" +iter=1 +all=120 +until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${3:-"8081"}"/editor | grep '302 Found'`" != "" ]; +do + if [ "$iter" -lt "$all" ] + then + echo "--- sleeping for 10 seconds" + sleep 10 + let iter=$iter+1 + else + echo "Server didn't return 302 found for long time" + exit 1 + fi +done +echo "editor-service found" +exit 0 From b17459ca0e4dc42ac7751fb3d1084fd35c39dcf0 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Mon, 20 Feb 2017 00:13:43 +0300 Subject: [PATCH 27/40] Code refactor --- .travis.yml | 14 +++++++------- .../qreal/wmp/uitesting/dia/scene/Coordinate.java | 8 ++++---- .../qreal/wmp/uitesting/dia/scene/SceneImpl.java | 8 ++++---- .../dia/scene/window/SceneWindowImpl.java | 4 ++-- .../wmp/uitesting/services/impl/AutherImpl.java | 2 +- .../qreal/wmp/uitesting/innertests/DiaTest.java | 12 ++++++++---- .../testspace/DiagramConstructingTest.java | 5 ++++- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25c079dd..c1ece518 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,31 +44,31 @@ script: - cd db-diagram-service - mvn exec:java -P travis & - - sleep 15 + - sleep 30 - cd ../db-user-service - mvn exec:java -P travis & - - sleep 15 + - sleep 30 - cd ../db-robot-store-service - mvn exec:java -P travis & - - sleep 15 + - sleep 30 - cd ../../auth-service - mvn tomcat7:run-war-only -P travis & - - sleep 30 + - sleep 60 - cd ../dashboard-service - mvn tomcat7:run-war-only -P travis & - - sleep 30 + - sleep 60 - cd ../editor-service - mvn tomcat7:run-war-only -P travis & - - sleep 30 + - sleep 60 - cd ../ui-testing - mvn test -P travis & - - sleep 180 + - sleep 600 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java index 6380db19..aed099e9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java @@ -9,6 +9,10 @@ public class Coordinate { private static final int POINT_IN_CELL = 25; + private final int xAbsolute; + + private final int yAbsolute; + /** Returns coordinate of object on scene. */ @NotNull public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { @@ -22,10 +26,6 @@ public static Optional getCoordinateFromSeleniumObject(SelenideEleme ); } - private final int xAbsolute; - - private final int yAbsolute; - public Coordinate(int xAbsolute, int yAbsolute) { this.xAbsolute = xAbsolute; this.yAbsolute = yAbsolute; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 2002753a..7910cded 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -59,7 +59,7 @@ public void init() { @Override public boolean name(String name) { - return name.equals("editor"); + return "editor".equals(name); } @Override @@ -91,7 +91,7 @@ public void moveToCell(final Block block, final int cell_x, final int cell_y) { try { sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); } catch (ElementNotOnTheSceneException e) { - e.printStackTrace(); + logger.error(e.getMessage()); } } @@ -102,7 +102,7 @@ public void focus(final SceneElement element) { try { sceneWindow.focus(element.getCoordinateOnScene()); } catch (ElementNotOnTheSceneException e) { - e.printStackTrace(); + logger.error(e.getMessage()); } } @@ -189,7 +189,7 @@ private void removeSceneElement(SceneElement sceneElement) { try { Thread.sleep(100); } catch (InterruptedException e) { - e.printStackTrace(); + logger.error(e.getMessage()); } $(By.id("scene-context-menu")).click(); blocks = $$(By.cssSelector(SELECTOR + " #v_7 > *")).stream() diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index a9fec4c9..e6ae3028 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -147,7 +147,7 @@ private int jump(final List elements, int step, int current) { try { return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) < Math.abs(2 * step); } catch (ElementNotOnTheSceneException e) { - e.printStackTrace(); + logger.error(e.getMessage()); } return false; })) { @@ -190,7 +190,7 @@ private void sendKey(Keys key) { // wait hard coded time until action is completed Thread.sleep(50); } catch (InterruptedException e) { - e.printStackTrace(); + logger.error(e.getMessage()); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java index 6db732d2..f1d3529f 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java @@ -35,6 +35,6 @@ public void auth(final String username, final String password) throws WrongAuthE } public void auth() throws WrongAuthException { - auth("123", "123"); + auth("Admin", "Admin"); } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index f52fb87d..cba7906a 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -12,6 +12,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -22,7 +24,9 @@ @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class DiaTest { - + + private static final Logger logger = LoggerFactory.getLogger(DiaTest.class); + @Autowired private Opener opener; @@ -35,7 +39,7 @@ public class DiaTest { @Autowired private PropertyEditor propertyEditor; - /** Setup browser. */ + /** Open editor page. */ @Before public void openEditor() { opener.open("editor"); @@ -90,11 +94,11 @@ public void moveElement() { scene.moveToCell(motor, 0, 0); assert motor.getCoordinateOnScene().getXCell() == 0 && motor.getCoordinateOnScene().getYCell() == 0; } catch (ElementNotOnTheSceneException e) { - e.printStackTrace(); + logger.error(e.getMessage()); } } - /** Close the browser. */ + /** Clean scene. */ @After public void cleanScene() { scene.clean(); diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index ad4aee89..e110c7c0 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -37,8 +37,10 @@ public class DiagramConstructingTest { private PropertyEditor propertyEditor; private ArrayList elements; + private ArrayList links; - + + /** Open editor page. */ @Before public void openEditor() { opener.open("editor"); @@ -80,6 +82,7 @@ public void fillProperties() { assert propertyEditor.getProperty(elements.get(3).getInnerSeleniumElement(), "Delay").equals("200"); } + /** Clean scene. */ @After public void cleanScene() { scene.clean(); From 65f24828aff4ae23137f2eba384702326a6016ea Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 24 Feb 2017 02:01:02 +0300 Subject: [PATCH 28/40] Divide editor to editor/robots and editor/bpmn 1. Change editor uri to editor/robots 2. Add auth test to editor/bpmn 3. Code refactor --- .travis.yml | 12 +++++----- Travis/callTomcat.sh | 6 ++--- .../qreal/wmp/uitesting/dia/scene/Scene.java | 5 +--- .../wmp/uitesting/dia/scene/SceneImpl.java | 13 +++++------ .../src/main/resources/pages.properties | 3 ++- .../wmp/uitesting/innertests/AuthTest.java | 23 +++++++++++++++---- .../wmp/uitesting/innertests/DiaTest.java | 2 +- .../testspace/DiagramConstructingTest.java | 2 +- 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index c1ece518..51707511 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,27 +44,27 @@ script: - cd db-diagram-service - mvn exec:java -P travis & - - sleep 30 + - sleep 15 - cd ../db-user-service - mvn exec:java -P travis & - - sleep 30 + - sleep 15 - cd ../db-robot-store-service - mvn exec:java -P travis & - - sleep 30 + - sleep 15 - cd ../../auth-service - mvn tomcat7:run-war-only -P travis & - - sleep 60 + - sleep 30 - cd ../dashboard-service - mvn tomcat7:run-war-only -P travis & - - sleep 60 + - sleep 30 - cd ../editor-service - mvn tomcat7:run-war-only -P travis & - - sleep 60 + - sleep 30 - cd ../ui-testing - mvn test -P travis & diff --git a/Travis/callTomcat.sh b/Travis/callTomcat.sh index df31e8e0..bfc51400 100755 --- a/Travis/callTomcat.sh +++ b/Travis/callTomcat.sh @@ -1,7 +1,7 @@ #!/bin/bash iter=1 all=120 -until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${1:-"8080"}"/auth | grep '302 Found'`" != "" ]; +until [ "$(curl --silent --show-error --connect-timeout 1 -I http://localhost:"${1:-"8080"}"/auth | grep '302 Found')" != "" ]; do if [ "$iter" -lt "$all" ] then @@ -16,7 +16,7 @@ done echo "auth-service found" iter=1 all=120 -until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${2:-"8082"}"/dashboard | grep '302 Found'`" != "" ]; +until [ "$(curl --silent --show-error --connect-timeout 1 -I http://localhost:"${2:-"8082"}"/dashboard | grep '302 Found')" != "" ]; do if [ "$iter" -lt "$all" ] then @@ -31,7 +31,7 @@ done echo "dashboard-service found" iter=1 all=120 -until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:"${3:-"8081"}"/editor | grep '302 Found'`" != "" ]; +until [ "$(curl --silent --show-error --connect-timeout 1 -I http://localhost:"${3:-"8081"}"/editor | grep '302 Found')" != "" ]; do if [ "$iter" -lt "$all" ] then diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java index 22604990..94273269 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -26,10 +26,7 @@ public interface Scene { boolean exist(SceneElement element); /** Remove block from the scene. */ - void remove(Block block); - - /** Remove link from the scene. */ - void remove(Link link); + void remove(SceneElement element); /** Add link between two elements. */ Link addLink(Block source, Block target); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 7910cded..c6ce282a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -112,13 +112,12 @@ public boolean exist(SceneElement element) { } @Override - public void remove(Block block) { - removeSceneElement(block); - } - - @Override - public void remove(Link link) { - removeSceneElement(link.getSource()); + public void remove(SceneElement element) { + if (element instanceof Link) { + removeSceneElement(((Link) element).getSource()); + } else { + removeSceneElement(element); + } } @Override diff --git a/ui-testing/src/main/resources/pages.properties b/ui-testing/src/main/resources/pages.properties index fd2d42ec..c0ec6690 100644 --- a/ui-testing/src/main/resources/pages.properties +++ b/ui-testing/src/main/resources/pages.properties @@ -1,3 +1,4 @@ auth=http://localhost:${port.auth}${path.auth} dashboard=http://localhost:${port.dashboard}${path.dashboard} -editor=http://localhost:${port.editor}${path.editor} \ No newline at end of file +robotsEditor=http://localhost:${port.editor}${path.editor}/robots +bpmnEditor=http://localhost:${port.editor}${path.editor}/bpmn \ No newline at end of file diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java index f79c6b78..884cb28e 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java @@ -77,15 +77,28 @@ public void dashboardTest() { } /** - * Try to open editor page without authentication. + * Try to open robots-editor page without authentication. * Should be redirected to auth page. - * Try to open editor page with correct login and password. + * Try to open robots-editor page with correct login and password. */ @Test - public void editorTest() { - opener.cleanOpen("editor"); + public void robotsEditorTest() { + opener.cleanOpen("robotsEditor"); assert inAuthPage(); - opener.open("editor"); + opener.open("robotsEditor"); + $(byText("Property Editor")).waitUntil(appear, 5000); + } + + /** + * Try to open bpmn-editor page without authentication. + * Should be redirected to auth page. + * Try to open bpmn-editor page with correct login and password. + */ + @Test + public void bpmnEditorTest() { + opener.cleanOpen("bpmnEditor"); + assert inAuthPage(); + opener.open("bpmnEditor"); $(byText("Property Editor")).waitUntil(appear, 5000); } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index cba7906a..54cdf42c 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -42,7 +42,7 @@ public class DiaTest { /** Open editor page. */ @Before public void openEditor() { - opener.open("editor"); + opener.open("robotsEditor"); } /** Drag element from pallete and drop on the scene. */ diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index e110c7c0..cb5aa2f8 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -43,7 +43,7 @@ public class DiagramConstructingTest { /** Open editor page. */ @Before public void openEditor() { - opener.open("editor"); + opener.open("robotsEditor"); elements = new ArrayList<>(); links = new ArrayList<>(); From 4723a4c2d0af19278ab18c6d7419613286d4ec65 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 24 Feb 2017 16:47:00 +0300 Subject: [PATCH 29/40] Add Page as an object 1. Add enum page 2. Add page factory class --- .../wmp/uitesting/InitializedComponent.java | 2 - .../java/com/qreal/wmp/uitesting/Page.java | 15 +++++ .../com/qreal/wmp/uitesting/PageFactory.java | 42 ++++++++++++++ .../com/qreal/wmp/uitesting/PageLoader.java | 58 +++++++++++++++++++ .../qreal/wmp/uitesting/config/DevConfig.java | 15 ++++- .../wmp/uitesting/dia/scene/SceneImpl.java | 14 ++--- .../qreal/wmp/uitesting/pages/AuthPage.java | 4 ++ .../wmp/uitesting/pages/DashboardPage.java | 4 ++ .../qreal/wmp/uitesting/pages/EditorPage.java | 37 ++++++++++++ .../uitesting/services/impl/OpenerImpl.java | 10 +--- .../wmp/uitesting/innertests/DiaTest.java | 16 ++--- .../testspace/DiagramConstructingTest.java | 18 +++--- 12 files changed, 200 insertions(+), 35 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java index 7236407b..482235db 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java @@ -3,6 +3,4 @@ /** Opening some pages must initialize included components. */ public interface InitializedComponent { void init(); - - boolean name(String name); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java new file mode 100644 index 00000000..c9c7a06b --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java @@ -0,0 +1,15 @@ +package com.qreal.wmp.uitesting; + +public enum Page { + Auth("auth"), Dashboard("dashboard"), EditorRobots("robotsEditor"), EditorBPMN("bpmnEditor"); + + private String identify; + + Page(String identify) { + this.identify = identify; + } + + public String getIdentify() { + return identify; + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java new file mode 100644 index 00000000..c1d015d1 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java @@ -0,0 +1,42 @@ +package com.qreal.wmp.uitesting; + +import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.property.PropertyEditor; +import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.pages.AuthPage; +import com.qreal.wmp.uitesting.pages.DashboardPage; +import com.qreal.wmp.uitesting.pages.EditorPage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PageFactory { + + private static final Logger logger = LoggerFactory.getLogger(PageFactory.class); + + private final Scene scene; + + private final PropertyEditor propertyEditor; + + private final Pallete pallete; + + public PageFactory(Scene scene, PropertyEditor propertyEditor, Pallete pallete) { + this.scene = scene; + this.propertyEditor = propertyEditor; + this.pallete = pallete; + } + + public EditorPage getEditorPage() { + logger.info("Editor page was created"); + return new EditorPage(scene, pallete, propertyEditor, (InitializedComponent) scene); + } + + public DashboardPage getDashboardPage() { + logger.info("Dashboard page was created"); + return new DashboardPage(); + } + + public AuthPage getAuthPage() { + logger.info("Auth page was created"); + return new AuthPage(); + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java new file mode 100644 index 00000000..19f0f20d --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java @@ -0,0 +1,58 @@ +package com.qreal.wmp.uitesting; + +import com.qreal.wmp.uitesting.exceptions.WrongAuthException; +import com.qreal.wmp.uitesting.services.Auther; +import com.qreal.wmp.uitesting.services.Opener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PageLoader { + + private static final Logger logger = LoggerFactory.getLogger(PageLoader.class); + + private final PageFactory pageFactory; + + private final Opener opener; + + private final Auther auther; + + public PageLoader(PageFactory pageFactory, Opener opener, Auther auther) { + this.pageFactory = pageFactory; + this.opener = opener; + this.auther = auther; + } + + public T load(Page page) { + opener.open(page.getIdentify()); + // wait for load + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } + return getPage(page); + } + + public T load(Page page, String username, String password) throws WrongAuthException { + auther.auth(username, password); + opener.open(page.getIdentify()); + // wait for load + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } + return getPage(page); + } + + @SuppressWarnings("unchecked") + private T getPage(Page page) { + switch (page) { + case Auth: return (T) pageFactory.getAuthPage(); + case Dashboard: return (T) pageFactory.getDashboardPage(); + case EditorBPMN: return (T) pageFactory.getEditorPage(); + case EditorRobots: return (T) pageFactory.getEditorPage(); + default: return null; + } + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index b607c41b..c8a4ebaf 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -1,7 +1,8 @@ package com.qreal.wmp.uitesting.config; import com.codeborne.selenide.WebDriverRunner; -import com.qreal.wmp.uitesting.InitializedComponent; +import com.qreal.wmp.uitesting.PageFactory; +import com.qreal.wmp.uitesting.PageLoader; import com.qreal.wmp.uitesting.dia.pallete.Pallete; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; import com.qreal.wmp.uitesting.dia.property.PropertyEditor; @@ -56,7 +57,7 @@ public Auther auther() { @Bean public Opener opener() { - return new OpenerImpl(environment, auther(), (InitializedComponent) scene()); + return new OpenerImpl(environment, auther()); } @Bean @@ -68,4 +69,14 @@ public PropertyEditor propertyEditor() { public Pallete pallete() { return new PalleteImpl(); } + + @Bean + public PageFactory pageFactory() { + return new PageFactory(scene(), propertyEditor(), pallete()); + } + + @Bean + PageLoader pageLoader() { + return new PageLoader(pageFactory(), opener(), auther()); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index c6ce282a..0ccc4815 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -4,11 +4,11 @@ import com.qreal.wmp.uitesting.InitializedComponent; import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; -import com.qreal.wmp.uitesting.dia.scene.window.SceneWindow; -import com.qreal.wmp.uitesting.dia.scene.window.SceneWindowImpl; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; +import com.qreal.wmp.uitesting.dia.scene.window.SceneWindow; +import com.qreal.wmp.uitesting.dia.scene.window.SceneWindowImpl; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -55,11 +55,11 @@ public void init() { createDiv("SceneWindowHorSize") + createDiv("SceneWindowVerSize") ); } - } - - @Override - public boolean name(String name) { - return "editor".equals(name); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } } @Override diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java new file mode 100644 index 00000000..f068daf9 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java @@ -0,0 +1,4 @@ +package com.qreal.wmp.uitesting.pages; + +public class AuthPage { +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java new file mode 100644 index 00000000..cd87621b --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java @@ -0,0 +1,4 @@ +package com.qreal.wmp.uitesting.pages; + +public class DashboardPage { +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java new file mode 100644 index 00000000..7af24e0d --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java @@ -0,0 +1,37 @@ +package com.qreal.wmp.uitesting.pages; + +import com.qreal.wmp.uitesting.InitializedComponent; +import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.property.PropertyEditor; +import com.qreal.wmp.uitesting.dia.scene.Scene; + +import java.util.Arrays; + +public class EditorPage { + + private final Scene scene; + + private final Pallete pallete; + + private final PropertyEditor propertyEditor; + + public EditorPage(Scene scene, Pallete pallete, PropertyEditor propertyEditor, + InitializedComponent... components) { + this.scene = scene; + this.pallete = pallete; + this.propertyEditor = propertyEditor; + Arrays.stream(components).forEach(InitializedComponent::init); + } + + public Scene getScene() { + return scene; + } + + public Pallete getPallete() { + return pallete; + } + + public PropertyEditor getPropertyEditor() { + return propertyEditor; + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java index 8fd19272..f93fcd15 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java @@ -1,6 +1,5 @@ package com.qreal.wmp.uitesting.services.impl; -import com.qreal.wmp.uitesting.InitializedComponent; import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import com.qreal.wmp.uitesting.services.Auther; import com.qreal.wmp.uitesting.services.Opener; @@ -9,8 +8,6 @@ import org.springframework.core.env.Environment; import org.springframework.security.access.AccessDeniedException; -import java.util.Arrays; - import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; @@ -21,14 +18,11 @@ public class OpenerImpl implements Opener { private Auther auther; - private InitializedComponent[] components; - private static final Logger logger = LoggerFactory.getLogger(OpenerImpl.class); - public OpenerImpl(Environment env, Auther auther, InitializedComponent... components) { + public OpenerImpl(Environment env, Auther auther) { this.env = env; this.auther = auther; - this.components = components; } /** {@inheritDoc} */ @@ -47,12 +41,10 @@ public void open(final String page) { throw new AccessDeniedException(e.getMessage()); } logger.info("Open page {}", env.getProperty(page)); - Arrays.stream(components).filter(component -> component.name(page)).forEach(InitializedComponent::init); } public void cleanOpen(final String page) { com.codeborne.selenide.Selenide.open(env.getProperty(page)); logger.info("Open page {}", env.getProperty(page)); - Arrays.stream(components).filter(component -> component.name(page)).forEach(InitializedComponent::init); } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index 54cdf42c..f5e93e73 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -1,5 +1,7 @@ package com.qreal.wmp.uitesting.innertests; +import com.qreal.wmp.uitesting.Page; +import com.qreal.wmp.uitesting.PageLoader; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.pallete.Pallete; import com.qreal.wmp.uitesting.dia.property.PropertyEditor; @@ -7,7 +9,7 @@ import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -import com.qreal.wmp.uitesting.services.Opener; +import com.qreal.wmp.uitesting.pages.EditorPage; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -28,21 +30,21 @@ public class DiaTest { private static final Logger logger = LoggerFactory.getLogger(DiaTest.class); @Autowired - private Opener opener; - - @Autowired + private PageLoader pageLoader; + private Pallete pallete; - @Autowired private Scene scene; - @Autowired private PropertyEditor propertyEditor; /** Open editor page. */ @Before public void openEditor() { - opener.open("robotsEditor"); + EditorPage editorPage = pageLoader.load(Page.EditorRobots); + scene = editorPage.getScene(); + pallete = editorPage.getPallete(); + propertyEditor = editorPage.getPropertyEditor(); } /** Drag element from pallete and drop on the scene. */ diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index cb5aa2f8..61061c72 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -1,12 +1,14 @@ package com.qreal.wmp.uitesting.testspace; +import com.qreal.wmp.uitesting.Page; +import com.qreal.wmp.uitesting.PageLoader; import com.qreal.wmp.uitesting.config.AppInit; import com.qreal.wmp.uitesting.dia.pallete.Pallete; import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; -import com.qreal.wmp.uitesting.services.Opener; +import com.qreal.wmp.uitesting.pages.EditorPage; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -25,15 +27,12 @@ public class DiagramConstructingTest { @Autowired - private Opener opener; - - @Autowired + private PageLoader pageLoader; + private Pallete pallete; - @Autowired private Scene scene; - @Autowired private PropertyEditor propertyEditor; private ArrayList elements; @@ -43,8 +42,11 @@ public class DiagramConstructingTest { /** Open editor page. */ @Before public void openEditor() { - opener.open("robotsEditor"); - + EditorPage editorPage = pageLoader.load(Page.EditorRobots); + scene = editorPage.getScene(); + pallete = editorPage.getPallete(); + propertyEditor = editorPage.getPropertyEditor(); + elements = new ArrayList<>(); links = new ArrayList<>(); From 16ef59c6e2ec97b26ae91797b2f9370ad9e872df Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 24 Feb 2017 17:18:34 +0300 Subject: [PATCH 30/40] Remove Scene, PropertyEditor and Pallete from beans --- .../wmp/uitesting/InitializedComponent.java | 6 ----- .../com/qreal/wmp/uitesting/PageFactory.java | 25 +++++++++---------- .../qreal/wmp/uitesting/config/DevConfig.java | 23 +---------------- .../uitesting/dia/pallete/PalleteImpl.java | 3 +++ .../dia/property/PropertyEditorImpl.java | 13 ++++------ .../wmp/uitesting/dia/scene/SceneImpl.java | 14 +++++------ .../qreal/wmp/uitesting/pages/EditorPage.java | 7 +----- .../testspace/DiagramConstructingTest.java | 4 +-- 8 files changed, 29 insertions(+), 66 deletions(-) delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java deleted file mode 100644 index 482235db..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/InitializedComponent.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.qreal.wmp.uitesting; - -/** Opening some pages must initialize included components. */ -public interface InitializedComponent { - void init(); -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java index c1d015d1..6e4c8b62 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java @@ -1,11 +1,12 @@ package com.qreal.wmp.uitesting; -import com.qreal.wmp.uitesting.dia.pallete.Pallete; -import com.qreal.wmp.uitesting.dia.property.PropertyEditor; -import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; +import com.qreal.wmp.uitesting.dia.property.PropertyEditorImpl; +import com.qreal.wmp.uitesting.dia.scene.SceneImpl; import com.qreal.wmp.uitesting.pages.AuthPage; import com.qreal.wmp.uitesting.pages.DashboardPage; import com.qreal.wmp.uitesting.pages.EditorPage; +import org.openqa.selenium.WebDriver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,21 +14,19 @@ public class PageFactory { private static final Logger logger = LoggerFactory.getLogger(PageFactory.class); - private final Scene scene; + private final WebDriver webDriver; - private final PropertyEditor propertyEditor; - - private final Pallete pallete; - - public PageFactory(Scene scene, PropertyEditor propertyEditor, Pallete pallete) { - this.scene = scene; - this.propertyEditor = propertyEditor; - this.pallete = pallete; + public PageFactory(WebDriver webDriver) { + this.webDriver = webDriver; } public EditorPage getEditorPage() { logger.info("Editor page was created"); - return new EditorPage(scene, pallete, propertyEditor, (InitializedComponent) scene); + return new EditorPage( + SceneImpl.getScene(webDriver), + PalleteImpl.getPallete(), + PropertyEditorImpl.getPropertyEditor() + ); } public DashboardPage getDashboardPage() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index c8a4ebaf..bd47cc99 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -3,12 +3,6 @@ import com.codeborne.selenide.WebDriverRunner; import com.qreal.wmp.uitesting.PageFactory; import com.qreal.wmp.uitesting.PageLoader; -import com.qreal.wmp.uitesting.dia.pallete.Pallete; -import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; -import com.qreal.wmp.uitesting.dia.property.PropertyEditor; -import com.qreal.wmp.uitesting.dia.property.PropertyEditorImpl; -import com.qreal.wmp.uitesting.dia.scene.Scene; -import com.qreal.wmp.uitesting.dia.scene.SceneImpl; import com.qreal.wmp.uitesting.services.Auther; import com.qreal.wmp.uitesting.services.Opener; import com.qreal.wmp.uitesting.services.impl.AutherImpl; @@ -44,11 +38,6 @@ public WebDriver webDriver() { WebDriverRunner.setWebDriver(driver); return driver; } - - @Bean - public Scene scene() { - return new SceneImpl(webDriver()); - } @Bean public Auther auther() { @@ -60,19 +49,9 @@ public Opener opener() { return new OpenerImpl(environment, auther()); } - @Bean - public PropertyEditor propertyEditor() { - return new PropertyEditorImpl(scene()); - } - - @Bean - public Pallete pallete() { - return new PalleteImpl(); - } - @Bean public PageFactory pageFactory() { - return new PageFactory(scene(), propertyEditor(), pallete()); + return new PageFactory(webDriver()); } @Bean diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java index 913697f7..79cf26d5 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java @@ -21,4 +21,7 @@ public PalleteElement getElement(final String elementName) throws NoSuchElementE return new PalleteElement(element); } + public static Pallete getPallete() { + return new PalleteImpl(); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java index efe5e924..5c70f9be 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java @@ -1,7 +1,6 @@ package com.qreal.wmp.uitesting.dia.property; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.scene.Scene; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.slf4j.Logger; @@ -19,12 +18,6 @@ public class PropertyEditorImpl implements PropertyEditor { private static final String SELECTOR = "#property_table"; private static final Logger logger = LoggerFactory.getLogger(PropertyEditorImpl.class); - - private final Scene scene; - - public PropertyEditorImpl(Scene scene) { - this.scene = scene; - } /** {@inheritDoc} */ public void setProperty(final SelenideElement element, final String propertyName, final String propertyValue) @@ -42,7 +35,7 @@ public void setProperty(final SelenideElement element, final String propertyName /** {@inheritDoc} */ public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException { - $(By.cssSelector(scene.getSelector())).click(); + $(By.cssSelector(SELECTOR)).click(); element.click(); SelenideElement property = getInputOfElement(propertyName); logger.info("Get value of preperty {}", propertyName); @@ -53,6 +46,10 @@ public String getProperty(final SelenideElement element, final String propertyNa } } + public static PropertyEditor getPropertyEditor() { + return new PropertyEditorImpl(); + } + /** 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 > * > *")); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 0ccc4815..2a2b6b13 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -1,7 +1,6 @@ package com.qreal.wmp.uitesting.dia.scene; import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.InitializedComponent; import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; import com.qreal.wmp.uitesting.dia.scene.elements.Block; @@ -28,7 +27,7 @@ * Describes Scene of Editor. * Can add rm and manipulate with objects on that area. */ -public class SceneImpl implements Scene, InitializedComponent { +public class SceneImpl implements Scene { private static final String SELECTOR = ".scene-wrapper"; @@ -43,12 +42,7 @@ public class SceneImpl implements Scene, InitializedComponent { /** For actions such as mouse move we need driver of current page. */ public SceneImpl(WebDriver webDriver) { this.webDriver = webDriver; - } - - /** Creates divs for window. */ - @Override - public void init() { - clean(); + /** For actions such as mouse move we need driver of current page. */ if (webDriver instanceof JavascriptExecutor) { ((JavascriptExecutor) webDriver).executeScript( createDiv("SceneWindowLeft") + createDiv("SceneWindowTop") + @@ -155,6 +149,10 @@ public List getBlocks() { return blocks.stream().collect(Collectors.toList()); } + public static Scene getScene(WebDriver webDriver) { + return new SceneImpl(webDriver); + } + /** Return new element of the scene. */ private Optional updateBlocks() { final List allElements = $$(By.cssSelector(SELECTOR + " #v_7 > *")); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java index 7af24e0d..348dd8df 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java @@ -1,12 +1,9 @@ package com.qreal.wmp.uitesting.pages; -import com.qreal.wmp.uitesting.InitializedComponent; import com.qreal.wmp.uitesting.dia.pallete.Pallete; import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; -import java.util.Arrays; - public class EditorPage { private final Scene scene; @@ -15,12 +12,10 @@ public class EditorPage { private final PropertyEditor propertyEditor; - public EditorPage(Scene scene, Pallete pallete, PropertyEditor propertyEditor, - InitializedComponent... components) { + public EditorPage(Scene scene, Pallete pallete, PropertyEditor propertyEditor) { this.scene = scene; this.pallete = pallete; this.propertyEditor = propertyEditor; - Arrays.stream(components).forEach(InitializedComponent::init); } public Scene getScene() { diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 61061c72..49a4e318 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -29,8 +29,6 @@ public class DiagramConstructingTest { @Autowired private PageLoader pageLoader; - private Pallete pallete; - private Scene scene; private PropertyEditor propertyEditor; @@ -44,7 +42,7 @@ public class DiagramConstructingTest { public void openEditor() { EditorPage editorPage = pageLoader.load(Page.EditorRobots); scene = editorPage.getScene(); - pallete = editorPage.getPallete(); + Pallete pallete = editorPage.getPallete(); propertyEditor = editorPage.getPropertyEditor(); elements = new ArrayList<>(); From 49765e787ddc7c4347c47a3c2a7bc2ce6865ad95 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 24 Feb 2017 17:35:56 +0300 Subject: [PATCH 31/40] Code refactor --- pom.xml | 2 + .../java/com/qreal/wmp/uitesting/Page.java | 22 ++--- .../com/qreal/wmp/uitesting/PageFactory.java | 57 ++++++----- .../com/qreal/wmp/uitesting/PageLoader.java | 98 ++++++++++--------- .../qreal/wmp/uitesting/config/DevConfig.java | 2 +- .../qreal/wmp/uitesting/dia/scene/Scene.java | 1 + .../wmp/uitesting/dia/scene/SceneImpl.java | 13 +-- .../dia/scene/window/SceneWindowImpl.java | 16 +-- .../qreal/wmp/uitesting/pages/EditorPage.java | 48 ++++----- .../src/main/resources/pages.properties | 4 +- .../wmp/uitesting/innertests/AuthTest.java | 1 + 11 files changed, 139 insertions(+), 125 deletions(-) diff --git a/pom.xml b/pom.xml index b8015ce8..45a17bae 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,8 @@ 8080 8080 /editor + ${path.editor}/robots + ${path.editor}/bpmn /auth /dashboard /editorRest diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java index c9c7a06b..42165cae 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java @@ -1,15 +1,15 @@ package com.qreal.wmp.uitesting; public enum Page { - Auth("auth"), Dashboard("dashboard"), EditorRobots("robotsEditor"), EditorBPMN("bpmnEditor"); - - private String identify; - - Page(String identify) { - this.identify = identify; - } - - public String getIdentify() { - return identify; - } + Auth("auth"), Dashboard("dashboard"), EditorRobots("robotsEditor"), EditorBPMN("bpmnEditor"); + + private String identify; + + Page(String identify) { + this.identify = identify; + } + + public String getIdentify() { + return identify; + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java index 6e4c8b62..09525feb 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java @@ -11,31 +11,34 @@ import org.slf4j.LoggerFactory; public class PageFactory { - - private static final Logger logger = LoggerFactory.getLogger(PageFactory.class); - - private final WebDriver webDriver; - - public PageFactory(WebDriver webDriver) { - this.webDriver = webDriver; - } - - public EditorPage getEditorPage() { - logger.info("Editor page was created"); - return new EditorPage( - SceneImpl.getScene(webDriver), - PalleteImpl.getPallete(), - PropertyEditorImpl.getPropertyEditor() - ); - } - - public DashboardPage getDashboardPage() { - logger.info("Dashboard page was created"); - return new DashboardPage(); - } - - public AuthPage getAuthPage() { - logger.info("Auth page was created"); - return new AuthPage(); - } + + private static final Logger logger = LoggerFactory.getLogger(PageFactory.class); + + private final WebDriver webDriver; + + public PageFactory(WebDriver webDriver) { + this.webDriver = webDriver; + } + + /** Returns Editor Page instance. */ + public EditorPage getEditorPage() { + logger.info("Editor page was created"); + return new EditorPage( + SceneImpl.getScene(webDriver), + PalleteImpl.getPallete(), + PropertyEditorImpl.getPropertyEditor() + ); + } + + /** Returns Dashboard Page instance. */ + public DashboardPage getDashboardPage() { + logger.info("Dashboard page was created"); + return new DashboardPage(); + } + + /** Returns Auth Page instance. */ + public AuthPage getAuthPage() { + logger.info("Auth page was created"); + return new AuthPage(); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java index 19f0f20d..a81f51bd 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java @@ -7,52 +7,54 @@ import org.slf4j.LoggerFactory; public class PageLoader { - - private static final Logger logger = LoggerFactory.getLogger(PageLoader.class); - - private final PageFactory pageFactory; - - private final Opener opener; - - private final Auther auther; - - public PageLoader(PageFactory pageFactory, Opener opener, Auther auther) { - this.pageFactory = pageFactory; - this.opener = opener; - this.auther = auther; - } - - public T load(Page page) { - opener.open(page.getIdentify()); - // wait for load - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } - return getPage(page); - } - - public T load(Page page, String username, String password) throws WrongAuthException { - auther.auth(username, password); - opener.open(page.getIdentify()); - // wait for load - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } - return getPage(page); - } - - @SuppressWarnings("unchecked") - private T getPage(Page page) { - switch (page) { - case Auth: return (T) pageFactory.getAuthPage(); - case Dashboard: return (T) pageFactory.getDashboardPage(); - case EditorBPMN: return (T) pageFactory.getEditorPage(); - case EditorRobots: return (T) pageFactory.getEditorPage(); - default: return null; - } - } + + private static final Logger logger = LoggerFactory.getLogger(PageLoader.class); + + private final PageFactory pageFactory; + + private final Opener opener; + + private final Auther auther; + + public PageLoader(PageFactory pageFactory, Opener opener, Auther auther) { + this.pageFactory = pageFactory; + this.opener = opener; + this.auther = auther; + } + + /** Loads and returns requested page with default authentication. */ + public T load(Page page) { + opener.open(page.getIdentify()); + // wait for load + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } + return getPage(page); + } + + /** Loads and returns requested page with login and password. */ + public T load(Page page, String username, String password) throws WrongAuthException { + auther.auth(username, password); + opener.open(page.getIdentify()); + // wait for load + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } + return getPage(page); + } + + @SuppressWarnings("unchecked") + private T getPage(Page page) { + switch (page) { + case Auth: return (T) pageFactory.getAuthPage(); + case Dashboard: return (T) pageFactory.getDashboardPage(); + case EditorBPMN: return (T) pageFactory.getEditorPage(); + case EditorRobots: return (T) pageFactory.getEditorPage(); + default: return null; + } + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index bd47cc99..c05bf8fb 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -55,7 +55,7 @@ public PageFactory pageFactory() { } @Bean - PageLoader pageLoader() { + public PageLoader pageLoader() { return new PageLoader(pageFactory(), opener(), auther()); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java index 94273269..6723f97c 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -17,6 +17,7 @@ public interface Scene { /** Drag element from scene or pallete and put it in cell of the scene. */ Block dragAndDrop(PalleteElement element, int cell_x, int cell_y); + /** Move element from scene to the cell. */ void moveToCell(Block block, int cell_x, int cell_y); /** Focus the element. */ diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 2a2b6b13..f3d49d74 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -32,15 +32,17 @@ public class SceneImpl implements Scene { private static final String SELECTOR = ".scene-wrapper"; private static final Logger logger = LoggerFactory.getLogger(PalleteImpl.class); - + + private final WebDriver webDriver; + + private final SceneWindow sceneWindow; + private Set blocks = new HashSet<>(); private Set links = new HashSet<>(); - - private WebDriver webDriver; /** For actions such as mouse move we need driver of current page. */ - public SceneImpl(WebDriver webDriver) { + private SceneImpl(WebDriver webDriver) { this.webDriver = webDriver; /** For actions such as mouse move we need driver of current page. */ if (webDriver instanceof JavascriptExecutor) { @@ -54,6 +56,7 @@ public SceneImpl(WebDriver webDriver) { } catch (InterruptedException e) { logger.error(e.getMessage()); } + sceneWindow = SceneWindowImpl.getSceneWindow(this, webDriver); } @Override @@ -80,7 +83,6 @@ public Block dragAndDrop(final PalleteElement element, int cell_x, int cell_y) { @Override public void moveToCell(final Block block, final int cell_x, final int cell_y) { - SceneWindow sceneWindow = new SceneWindowImpl(this, webDriver); logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); try { sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); @@ -91,7 +93,6 @@ public void moveToCell(final Block block, final int cell_x, final int cell_y) { @Override public void focus(final SceneElement element) { - SceneWindow sceneWindow = new SceneWindowImpl(this, webDriver); logger.info("Focus on the element {}", element); try { sceneWindow.focus(element.getCoordinateOnScene()); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index e6ae3028..45335cdc 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -21,20 +21,20 @@ * Describes part of the scene, which is shown on browser. */ public class SceneWindowImpl implements SceneWindow { - + + private static final Logger logger = LoggerFactory.getLogger(SceneWindowImpl.class); + + private final WebDriver driver; + /** Link to full scene. */ private final Scene scene; private int stepVert; private int stepHor; - - private final WebDriver driver; - - private static final Logger logger = LoggerFactory.getLogger(SceneWindowImpl.class); /** Constructor takes links to current scene and current driver. */ - public SceneWindowImpl(final Scene scene, final WebDriver driver) { + private SceneWindowImpl(final Scene scene, final WebDriver driver) { this.scene = scene; this.driver = driver; updateSteps(); @@ -80,6 +80,10 @@ public void focus(final Coordinate coordinate) { verticalWindowMovement(coordinate.getYAbsolute()); } + public static SceneWindow getSceneWindow(Scene scene, WebDriver webDriver) { + return new SceneWindowImpl(scene, webDriver); + } + private void horizontalWindowMovement(int horizontal) { int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); int left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java index 348dd8df..680cd697 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java @@ -5,28 +5,28 @@ import com.qreal.wmp.uitesting.dia.scene.Scene; public class EditorPage { - - private final Scene scene; - - private final Pallete pallete; - - private final PropertyEditor propertyEditor; - - public EditorPage(Scene scene, Pallete pallete, PropertyEditor propertyEditor) { - this.scene = scene; - this.pallete = pallete; - this.propertyEditor = propertyEditor; - } - - public Scene getScene() { - return scene; - } - - public Pallete getPallete() { - return pallete; - } - - public PropertyEditor getPropertyEditor() { - return propertyEditor; - } + + private final Scene scene; + + private final Pallete pallete; + + private final PropertyEditor propertyEditor; + + public EditorPage(Scene scene, Pallete pallete, PropertyEditor propertyEditor) { + this.scene = scene; + this.pallete = pallete; + this.propertyEditor = propertyEditor; + } + + public Scene getScene() { + return scene; + } + + public Pallete getPallete() { + return pallete; + } + + public PropertyEditor getPropertyEditor() { + return propertyEditor; + } } diff --git a/ui-testing/src/main/resources/pages.properties b/ui-testing/src/main/resources/pages.properties index c0ec6690..0ffeabe3 100644 --- a/ui-testing/src/main/resources/pages.properties +++ b/ui-testing/src/main/resources/pages.properties @@ -1,4 +1,4 @@ auth=http://localhost:${port.auth}${path.auth} dashboard=http://localhost:${port.dashboard}${path.dashboard} -robotsEditor=http://localhost:${port.editor}${path.editor}/robots -bpmnEditor=http://localhost:${port.editor}${path.editor}/bpmn \ No newline at end of file +robotsEditor=http://localhost:${port.editor}${path.editor.robots} +bpmnEditor=http://localhost:${port.editor}${path.editor.bpmn} \ No newline at end of file diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java index 884cb28e..6e402412 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java @@ -17,6 +17,7 @@ import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; +/** Tests for opener and auther services. */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) From 447413fbafe0e0dc594fc06c7488ed8a87ad0b93 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sat, 25 Feb 2017 01:44:36 +0300 Subject: [PATCH 32/40] Add Block and Link providers 1. Add Block and Link providers 2. Add Focus and Move helpers --- .travis.yml | 4 +- pom.xml | 8 +- .../qreal/wmp/uitesting/dia/scene/Scene.java | 9 +- .../wmp/uitesting/dia/scene/SceneImpl.java | 148 ++++++----------- .../dia/scene/providers/BlockProvider.java | 88 ++++++++++ .../dia/scene/providers/LinkProvider.java | 82 ++++++++++ .../dia/scene/window/FocusHelper.java | 69 ++++++++ .../dia/scene/window/MoveHelper.java | 83 ++++++++++ .../dia/scene/window/PageInfoUpdator.java | 12 ++ .../dia/scene/window/SceneWindowImpl.java | 151 +++++------------- .../wmp/uitesting/innertests/DiaTest.java | 6 +- 11 files changed, 438 insertions(+), 222 deletions(-) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java diff --git a/.travis.yml b/.travis.yml index 51707511..f3e95d86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ before_install: install: #install and run tests and run style checking - - mvn install -P travis + - mvn clean install -P travis - cd ui-testing - mvn clean install -DskipTests - cd .. @@ -68,7 +68,7 @@ script: - cd ../ui-testing - mvn test -P travis & - - sleep 600 + - sleep 900 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/pom.xml b/pom.xml index 45a17bae..7c106d84 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,8 @@ 8080 8082 /editor + /editor/robots + /editor/bpmn /auth /dashboard /editorRest @@ -53,8 +55,8 @@ 8080 8080 /editor - ${path.editor}/robots - ${path.editor}/bpmn + /editor/robots + /editor/bpmn /auth /dashboard /editorRest @@ -72,6 +74,8 @@ 8080 8082 /editor + /editor/robots + /editor/bpmn /auth /dashboard /editorRest diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java index 6723f97c..1bbbd00a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -4,13 +4,11 @@ import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import java.util.List; public interface Scene { - /** Return selector of Scene in html-page. */ - String getSelector(); - /** Drag element from scene or pallete and put it on the center of scene. */ Block dragAndDrop(PalleteElement palleteElement); @@ -20,14 +18,11 @@ public interface Scene { /** Move element from scene to the cell. */ void moveToCell(Block block, int cell_x, int cell_y); - /** Focus the element. */ - void focus(SceneElement element); - /** Check if element exist on the scene. */ boolean exist(SceneElement element); /** Remove block from the scene. */ - void remove(SceneElement element); + void remove(SceneElement element) throws ElementNotOnTheSceneException; /** Add link between two elements. */ Link addLink(Block source, Block target); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index f3d49d74..757ddcda 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -1,27 +1,26 @@ package com.qreal.wmp.uitesting.dia.scene; -import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; +import com.qreal.wmp.uitesting.dia.scene.providers.BlockProvider; +import com.qreal.wmp.uitesting.dia.scene.providers.LinkProvider; import com.qreal.wmp.uitesting.dia.scene.window.SceneWindow; import com.qreal.wmp.uitesting.dia.scene.window.SceneWindowImpl; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; +import org.jetbrains.annotations.Contract; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.NotFoundException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; -import java.util.stream.Collectors; +import java.util.List; import static com.codeborne.selenide.Selenide.$; -import static com.codeborne.selenide.Selenide.$$; /** * Describes Scene of Editor. @@ -37,14 +36,14 @@ public class SceneImpl implements Scene { private final SceneWindow sceneWindow; - private Set blocks = new HashSet<>(); + private final BlockProvider blockProvider; - private Set links = new HashSet<>(); + private final LinkProvider linkProvider; /** For actions such as mouse move we need driver of current page. */ private SceneImpl(WebDriver webDriver) { this.webDriver = webDriver; - /** For actions such as mouse move we need driver of current page. */ + // For actions such as mouse move we need driver of current page. if (webDriver instanceof JavascriptExecutor) { ((JavascriptExecutor) webDriver).executeScript( createDiv("SceneWindowLeft") + createDiv("SceneWindowTop") + @@ -56,58 +55,42 @@ private SceneImpl(WebDriver webDriver) { } catch (InterruptedException e) { logger.error(e.getMessage()); } - sceneWindow = SceneWindowImpl.getSceneWindow(this, webDriver); - } - - @Override - public String getSelector() { - return SELECTOR; + sceneWindow = SceneWindowImpl.getSceneWindow(this, webDriver, SELECTOR); + blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR); + linkProvider = LinkProvider.getLinkProvider(SELECTOR, webDriver); } @Override public Block dragAndDrop(final PalleteElement element) { element.getInner().dragAndDropTo(SELECTOR); - final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); - Block newBlock = new Block("name", newEl); - blocks.add(newBlock); - logger.info("Add element {} to scene", newEl); - return newBlock; + return blockProvider.getNewBlock(); } @Override public Block dragAndDrop(final PalleteElement element, int cell_x, int cell_y) { Block newBlock = dragAndDrop(element); - moveToCell(newBlock, cell_x, cell_y); + blockProvider.moveToCell(newBlock, cell_x, cell_y); return newBlock; } @Override - public void moveToCell(final Block block, final int cell_x, final int cell_y) { - logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); - try { - sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); - } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); - } - } - - @Override - public void focus(final SceneElement element) { - logger.info("Focus on the element {}", element); - try { - sceneWindow.focus(element.getCoordinateOnScene()); - } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); - } + public void moveToCell(Block block, final int cell_x, final int cell_y) { + blockProvider.moveToCell(block, cell_x, cell_y); } @Override public boolean exist(SceneElement element) { - return blocks.stream().anyMatch(element::equals) || links.stream().anyMatch(element::equals); + if (element instanceof Block) { + return blockProvider.exist((Block) element); + } + if (element instanceof Link) { + return linkProvider.exist((Link) element); + } + return false; } @Override - public void remove(SceneElement element) { + public void remove(SceneElement element) throws ElementNotOnTheSceneException { if (element instanceof Link) { removeSceneElement(((Link) element).getSource()); } else { @@ -115,14 +98,32 @@ public void remove(SceneElement element) { } } + @Override + public Link addLink(final Block source, final Block target) { + return linkProvider.addLink(source, target); + } + + @Override + public List getBlocks() { + return blockProvider.getBlocks(); + } + @Override public void clean() { - if (!links.isEmpty()) { - remove(links.stream().collect(Collectors.toList()).get(0)); + if (!linkProvider.isEmpty()) { + try { + remove(linkProvider.getLinks().get(0)); + } catch (ElementNotOnTheSceneException e) { + logger.error(e.getMessage()); + } clean(); } else { - if (!blocks.isEmpty()) { - remove(blocks.stream().collect(Collectors.toList()).get(0)); + if (!blockProvider.isEmpty()) { + try { + remove(blockProvider.getBlocks().get(0)); + } catch (ElementNotOnTheSceneException e) { + logger.error(e.getMessage()); + } clean(); } else { logger.info("Clean scene"); @@ -130,74 +131,29 @@ public void clean() { } } - @Override - public Link addLink(final Block source, final Block target) { - final SelenideElement begin = $(By.cssSelector(SELECTOR + " #" + - source.getInnerSeleniumElement().attr("id") + " .outPorts")); - logger.info("Begin element {}, end element {} ", begin, target); - new Actions(webDriver) - .dragAndDrop(source.getPort().getInnerSeleniumElement(), target.getInnerSeleniumElement()) - .build().perform(); - SelenideElement newEl = updateLinks().orElseThrow(() -> new NoSuchElementException("Link was not created")); - logger.info("Add link {}", newEl); - Link res = new Link("link", newEl); - links.add(res); - return res; - } - - @Override - public List getBlocks() { - return blocks.stream().collect(Collectors.toList()); - } - + @Contract("_ -> !null") public static Scene getScene(WebDriver webDriver) { return new SceneImpl(webDriver); } - /** Return new element of the scene. */ - private Optional updateBlocks() { - final List allElements = $$(By.cssSelector(SELECTOR + " #v_7 > *")); - return allElements.stream() - .filter(htmlElement -> - htmlElement.attr("class").contains("element devs ImageWithPorts") && - blocks.stream().noneMatch(block -> block.getInnerSeleniumElement() - .attr("id").equals(htmlElement.attr("id"))) - ).findFirst(); - } - - private Optional updateLinks() { - final List allElements = $$(By.cssSelector(SELECTOR + " #v_7 > *")); - return allElements.stream() - .filter(htmlElement -> - htmlElement.attr("class").contains("link") && - links.stream().noneMatch(link -> htmlElement.attr("id") - .equals(link.getInnerSeleniumElement().attr("id"))) - ).findFirst(); - } - + @Contract(pure = true) private static String createDiv(String divName) { return "$('body').append('');"; } - private void removeSceneElement(SceneElement sceneElement) { - focus(sceneElement); - assert sceneElement != null; + @Contract("null -> fail") + 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(); try { - Thread.sleep(100); + Thread.sleep(1000); } catch (InterruptedException e) { logger.error(e.getMessage()); } $(By.id("scene-context-menu")).click(); - blocks = $$(By.cssSelector(SELECTOR + " #v_7 > *")).stream() - .filter(x -> x.attr("class").contains(Block.CLASS_NAME)) - .map(x -> new Block("name", x)) - .collect(Collectors.toSet()); - links = $$(By.cssSelector(SELECTOR + " #v_7 > *")).stream() - .filter(x -> x.attr("class").contains(Link.CLASS_NAME)) - .map(x -> new Link("name", x)) - .collect(Collectors.toSet()); + blockProvider.recalculateBlocks(); + linkProvider.recalculateLinks(); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java new file mode 100644 index 00000000..5b98d6ae --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java @@ -0,0 +1,88 @@ +package com.qreal.wmp.uitesting.dia.scene.providers; + +import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.scene.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.scene.window.SceneWindow; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; +import org.jetbrains.annotations.Contract; +import org.openqa.selenium.By; +import org.openqa.selenium.NotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; +import java.util.stream.Collectors; + +import static com.codeborne.selenide.Selenide.$$; + +public class BlockProvider { + + private static final Logger logger = LoggerFactory.getLogger(BlockProvider.class); + + private final SceneWindow sceneWindow; + + private final String selector; + + private Set blocks = new HashSet<>(); + + private BlockProvider(SceneWindow sceneWindow, String selector) { + this.sceneWindow = sceneWindow; + this.selector = selector; + } + + /** Move element to cell with x and y coordinates. */ + public void moveToCell(final Block block, final int cell_x, final int cell_y) { + logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); + try { + sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); + } catch (ElementNotOnTheSceneException e) { + logger.error(e.getMessage()); + } + } + + public List getBlocks() { + return Collections.unmodifiableList(blocks.stream().collect(Collectors.toList())); + } + + /** Return added block. */ + public Block getNewBlock() { + final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); + logger.info("Add element {} to scene", newEl); + Block block = new Block(newEl.attr("id"), newEl); + blocks.add(block); + return block; + } + + public boolean exist(Block block) { + return blocks.stream().anyMatch(anyBlock -> anyBlock.getName().equals(block.getName())); + } + + public boolean isEmpty() { + return blocks.isEmpty(); + } + + public void recalculateBlocks() { + blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream() + .filter(x -> x.attr("class").contains(Block.CLASS_NAME)) + .map(x -> new Block(x.attr("id"), x)) + .collect(Collectors.toSet()); + } + + @Contract("_, _ -> !null") + public static BlockProvider getBlockProvider(SceneWindow sceneWindow, String selector) { + return new BlockProvider(sceneWindow, selector); + } + + /** Return new element of the scene. */ + private Optional updateBlocks() { + final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); + return allElements.stream() + .filter(htmlElement -> + htmlElement.attr("class").contains("element devs ImageWithPorts") && + blocks.stream().noneMatch(block -> block.getInnerSeleniumElement() + .attr("id").equals(htmlElement.attr("id"))) + ).findFirst(); + } + +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java new file mode 100644 index 00000000..6b8c9029 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java @@ -0,0 +1,82 @@ +package com.qreal.wmp.uitesting.dia.scene.providers; + +import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.scene.elements.Link; +import org.jetbrains.annotations.Contract; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.interactions.Actions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; +import java.util.stream.Collectors; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; + +public class LinkProvider { + + private static final Logger logger = LoggerFactory.getLogger(LinkProvider.class); + + private final String selector; + + private final WebDriver webDriver; + + private Set links = new HashSet<>(); + + private LinkProvider(String selector, WebDriver webDriver) { + this.selector = selector; + this.webDriver = webDriver; + } + + public List getLinks() { + return Collections.unmodifiableList(links.stream().collect(Collectors.toList())); + } + + public boolean isEmpty() { + return links.isEmpty(); + } + + public boolean exist(Link link) { + return links.stream().anyMatch(anyLink -> anyLink.getName().equals(link.getName())); + } + + /** Add link between two blocks. */ + public Link addLink(final Block source, final Block target) { + final SelenideElement begin = $(By.cssSelector(selector + " #" + + source.getInnerSeleniumElement().attr("id") + " .outPorts")); + logger.info("Begin element {}, end element {} ", begin, target); + new Actions(webDriver) + .dragAndDrop(source.getPort().getInnerSeleniumElement(), target.getInnerSeleniumElement()) + .build().perform(); + SelenideElement newEl = updateLinks().orElseThrow(() -> new NoSuchElementException("Link was not created")); + logger.info("Add link {}", newEl); + Link res = new Link(newEl.attr("id"), newEl); + links.add(res); + return res; + } + + public void recalculateLinks() { + links = $$(By.cssSelector(selector + " #v_7 > *")).stream() + .filter(x -> x.attr("class").contains(Link.CLASS_NAME)) + .map(x -> new Link(x.attr("id"), x)) + .collect(Collectors.toSet()); + } + + @Contract("_, _ -> !null") + public static LinkProvider getLinkProvider(String selector, WebDriver webDriver) { + return new LinkProvider(selector, webDriver); + } + + private Optional updateLinks() { + final List allElements = $$(By.cssSelector(selector + " #v_7 > *")); + return allElements.stream() + .filter(htmlElement -> + htmlElement.attr("class").contains("link") && + links.stream().noneMatch(link -> htmlElement.attr("id") + .equals(link.getInnerSeleniumElement().attr("id"))) + ).findFirst(); + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java new file mode 100644 index 00000000..116ee26b --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java @@ -0,0 +1,69 @@ +package com.qreal.wmp.uitesting.dia.scene.window; + +import org.jetbrains.annotations.Contract; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static com.codeborne.selenide.Selenide.$; + +public class FocusHelper { + + private static final Logger logger = LoggerFactory.getLogger(FocusHelper.class); + + private final PageInfoUpdator updator; + + private FocusHelper(PageInfoUpdator updator) { + this.updator = updator; + } + + /** Horizontal movement. */ + public void horizontalWindowMovement(int horizontal) { + int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); + int left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); + logger.info("focus horizontal " + left + " " + sizeHor + " " + horizontal); + + if (left + sizeHor * 2 / 3 < horizontal) { + updator.sendKey(Keys.RIGHT); + updator.updateCanvasInfo(); + if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { + horizontalWindowMovement(horizontal); + } + } + if (left + sizeHor / 3 > horizontal) { + updator.sendKey(Keys.LEFT); + updator.updateCanvasInfo(); + if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { + horizontalWindowMovement(horizontal); + } + } + } + + /** Vertical movement. */ + public void verticalWindowMovement(int vertical) { + int sizeVer = Double.valueOf($(By.id("SceneWindowVerSize")).innerHtml()).intValue(); + int top = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); + logger.info("focus vertical " + top + " " + sizeVer + " " + vertical); + + if (top + sizeVer * 2 / 3 < vertical) { + updator.sendKey(Keys.DOWN); + updator.updateCanvasInfo(); + if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { + verticalWindowMovement(vertical); + } + } + if (top + sizeVer / 3 > vertical) { + updator.sendKey(Keys.UP); + updator.updateCanvasInfo(); + if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { + verticalWindowMovement(vertical); + } + } + } + + @Contract("_ -> !null") + public static FocusHelper getFocusHelper(PageInfoUpdator updator) { + return new FocusHelper(updator); + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java new file mode 100644 index 00000000..027cadb2 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java @@ -0,0 +1,83 @@ +package com.qreal.wmp.uitesting.dia.scene.window; + +import com.codeborne.selenide.SelenideElement; +import com.qreal.wmp.uitesting.dia.scene.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.Scene; +import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.interactions.Actions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +public class MoveHelper { + + private static final Logger logger = LoggerFactory.getLogger(MoveHelper.class); + + private final Scene scene; + + private final WebDriver driver; + + private MoveHelper(Scene scene, WebDriver driver) { + this.scene = scene; + this.driver = driver; + } + + /** Horizontal move. */ + public Actions callDragAndDropByX(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { + final List elements = scene.getBlocks(); + return Math.abs(src - dst) > Math.abs(step) ? + callDragAndDropByX(src + step, dst, step, + actions.sendKeys(key) + .clickAndHold(element) + .moveByOffset(jump(elements, 2 * step, src), 0), key, element + ) : actions.sendKeys(key, key); + } + + /** Vertical move. */ + public Actions callDragAndDropByY(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { + final List elements = scene.getBlocks(); + return Math.abs(src - dst) > Math.abs(step) ? + callDragAndDropByY(src + step, dst, step, + actions.sendKeys(key) + .clickAndHold(element) + .moveByOffset(0, jump(elements, 2 * step, src)), key, element + ) : actions.sendKeys(key, key); + } + + /** Movement to the exact point when element in the SceneWindow. */ + public Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTheSceneException { + Coordinate currentPosition = block.getCoordinateOnScene(); + + new Actions(driver).release() + .clickAndHold(block.getInnerSeleniumElement()) + .moveByOffset( + dist.getXAbsolute() - currentPosition.getXAbsolute(), + dist.getYAbsolute() - currentPosition.getYAbsolute() + ).release().perform(); + + return block.getCoordinateOnScene(); + } + + private int jump(final List elements, int step, int current) { + if (elements.stream().anyMatch(x -> { + try { + return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) < Math.abs(2 * step); + } catch (ElementNotOnTheSceneException e) { + logger.error(e.getMessage()); + } + return false; + })) { + return step + jump(elements, step, step + current); + } else { + return step; + } + } + + public static MoveHelper getMoveHelper(Scene scene, WebDriver webDriver) { + return new MoveHelper(scene, webDriver); + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java new file mode 100644 index 00000000..7158f29f --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java @@ -0,0 +1,12 @@ +package com.qreal.wmp.uitesting.dia.scene.window; + +import org.openqa.selenium.Keys; + +public interface PageInfoUpdator { + + void updateSteps(); + + void sendKey(Keys key); + + void updateCanvasInfo(); +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 45335cdc..951139ea 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -1,10 +1,10 @@ package com.qreal.wmp.uitesting.dia.scene.window; -import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.scene.Coordinate; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; +import org.jetbrains.annotations.Contract; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; @@ -13,30 +13,33 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; - import static com.codeborne.selenide.Selenide.$; /** * Describes part of the scene, which is shown on browser. */ -public class SceneWindowImpl implements SceneWindow { +public class SceneWindowImpl implements SceneWindow, PageInfoUpdator { private static final Logger logger = LoggerFactory.getLogger(SceneWindowImpl.class); private final WebDriver driver; - /** Link to full scene. */ - private final Scene scene; - + private final String selector; + + private final FocusHelper focusHelper; + + private final MoveHelper moveHelper; + private int stepVert; private int stepHor; /** Constructor takes links to current scene and current driver. */ - private SceneWindowImpl(final Scene scene, final WebDriver driver) { - this.scene = scene; + 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(); } @@ -52,129 +55,41 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn focus(src); if (src.getXAbsolute() < dist.getXAbsolute()) { - callDragAndDropByX( + moveHelper.callDragAndDropByX( src.getXAbsolute(), dist.getXAbsolute(), stepHor, new Actions(driver), Keys.ARROW_RIGHT, element.getInnerSeleniumElement()).perform(); } else { - callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), -stepHor, + moveHelper.callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), -stepHor, new Actions(driver), Keys.ARROW_LEFT, element.getInnerSeleniumElement()).perform(); } if (src.getYAbsolute() < dist.getYAbsolute()) { - callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), stepVert, + moveHelper.callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), stepVert, new Actions(driver), Keys.ARROW_DOWN, element.getInnerSeleniumElement()).perform(); } else { - callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), -stepVert, + moveHelper.callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), -stepVert, new Actions(driver), Keys.ARROW_UP, element.getInnerSeleniumElement()).perform(); } - if (!finalJump(element, dist).equals(dist)) { + if (!moveHelper.finalJump(element, dist).equals(dist)) { move(element, dist); } } @Override public void focus(final Coordinate coordinate) { - logger.debug("Focus to " + coordinate.getXAbsolute() + " " + coordinate.getYAbsolute()); - horizontalWindowMovement(coordinate.getXAbsolute()); - verticalWindowMovement(coordinate.getYAbsolute()); - } - - public static SceneWindow getSceneWindow(Scene scene, WebDriver webDriver) { - return new SceneWindowImpl(scene, webDriver); + logger.info("Focus to " + coordinate.getXAbsolute() + " " + coordinate.getYAbsolute()); + focusHelper.horizontalWindowMovement(coordinate.getXAbsolute()); + focusHelper.verticalWindowMovement(coordinate.getYAbsolute()); } - private void horizontalWindowMovement(int horizontal) { - int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); - int left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); - logger.debug("focus horizontal " + left + " " + sizeHor); - - if (left + sizeHor * 2 / 3 < horizontal) { - sendKey(Keys.RIGHT); - updateCanvasInfo(); - if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { - horizontalWindowMovement(horizontal); - } - } - if (left + sizeHor / 3 > horizontal) { - sendKey(Keys.LEFT); - updateCanvasInfo(); - if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { - horizontalWindowMovement(horizontal); - } - } + @Contract("_, _, _ -> !null") + public static SceneWindow getSceneWindow(Scene scene, WebDriver webDriver, String selector) { + return new SceneWindowImpl(scene, webDriver, selector); } - private void verticalWindowMovement(int vertical) { - int sizeVer = Double.valueOf($(By.id("SceneWindowVerSize")).innerHtml()).intValue(); - int top = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); - logger.info("focus vertical " + top + " " + sizeVer); - - if (top + sizeVer * 2 / 3 < vertical) { - sendKey(Keys.DOWN); - updateCanvasInfo(); - if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { - verticalWindowMovement(vertical); - } - } - if (top + sizeVer / 3 > vertical) { - sendKey(Keys.UP); - updateCanvasInfo(); - if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { - verticalWindowMovement(vertical); - } - } - } - - private Actions callDragAndDropByX(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { - final List elements = scene.getBlocks(); - return Math.abs(src - dst) > Math.abs(step) ? - callDragAndDropByX(src + step, dst, step, - 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.getBlocks(); - return Math.abs(src - dst) > Math.abs(step) ? - callDragAndDropByY(src + step, dst, step, - 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) { - if (elements.stream().anyMatch(x -> { - try { - return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) < Math.abs(2 * step); - } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); - } - return false; - })) { - return step + jump(elements, step, step + current); - } else { - return step; - } - } - - private Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTheSceneException { - Coordinate currentPosition = block.getCoordinateOnScene(); - - new Actions(driver).release() - .clickAndHold(block.getInnerSeleniumElement()) - .moveByOffset( - dist.getXAbsolute() - currentPosition.getXAbsolute(), - dist.getYAbsolute() - currentPosition.getYAbsolute() - ).release().perform(); - - return block.getCoordinateOnScene(); - } - - private void updateCanvasInfo() { + @Override + public void updateCanvasInfo() { if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("var canvas = " + "document.getElementsByClassName(\"scene-wrapper\")[0]; " + @@ -185,22 +100,29 @@ private void updateCanvasInfo() { "$('#SceneWindowVerSize').html(BB.bottom - BB.top);" ); } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } } // todo: make it waits real time until action is completed - private void sendKey(Keys key) { + @Override + public void sendKey(Keys key) { new Actions(driver).sendKeys(key).perform(); try { // wait hard coded time until action is completed - Thread.sleep(50); + Thread.sleep(1000); } catch (InterruptedException e) { logger.error(e.getMessage()); } } - private void updateSteps() { + @Override + public void updateSteps() { updateCanvasInfo(); - $(scene.getSelector()).click(); + $(selector).click(); focus(new Coordinate(0, 0)); updateCanvasInfo(); sendKey(Keys.DOWN); @@ -208,5 +130,6 @@ private void updateSteps() { updateCanvasInfo(); stepHor = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); stepVert = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); + logger.info("stepHor = " + stepHor + "; stepVert = " + stepVert); } } \ No newline at end of file diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java index f5e93e73..295c31fa 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java @@ -59,7 +59,11 @@ public void dragAndDrop() { public void remove() { final Block sceneElement = scene.dragAndDrop(pallete.getElement("Initial Node")); assert scene.exist(sceneElement); - scene.remove(sceneElement); + try { + scene.remove(sceneElement); + } catch (ElementNotOnTheSceneException e) { + logger.error(e.getMessage()); + } assert !scene.exist(sceneElement); } From 2441162d1267265f23bc9e2d01de3f38c6fee60f Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 26 Feb 2017 16:59:48 +0300 Subject: [PATCH 33/40] Add additional condition for remove --- .travis.yml | 2 +- .../wmp/uitesting/dia/scene/SceneImpl.java | 19 +++++++++++---- .../dia/scene/window/FocusHelper.java | 23 +++++++++++++++++-- .../dia/scene/window/SceneWindowImpl.java | 11 +++++---- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index f3e95d86..3ddf0c87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,7 +68,7 @@ script: - cd ../ui-testing - mvn test -P travis & - - sleep 900 + - sleep 1200 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 757ddcda..d5b6932d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -1,5 +1,7 @@ package com.qreal.wmp.uitesting.dia.scene; +import com.codeborne.selenide.Condition; +import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; import com.qreal.wmp.uitesting.dia.scene.elements.Block; @@ -51,7 +53,7 @@ private SceneImpl(WebDriver webDriver) { ); } try { - Thread.sleep(3000); + Thread.sleep(1000); } catch (InterruptedException e) { logger.error(e.getMessage()); } @@ -151,9 +153,16 @@ private void removeSceneElement(SceneElement sceneElement) throws ElementNotOnTh } catch (InterruptedException e) { logger.error(e.getMessage()); } - $(By.id("scene-context-menu")).click(); - - blockProvider.recalculateBlocks(); - linkProvider.recalculateLinks(); + 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(); + + removeSceneElement(sceneElement); + } else { + contextMenu.click(); + blockProvider.recalculateBlocks(); + linkProvider.recalculateLinks(); + } } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java index 116ee26b..23964981 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java @@ -27,6 +27,7 @@ public void horizontalWindowMovement(int horizontal) { if (left + sizeHor * 2 / 3 < horizontal) { updator.sendKey(Keys.RIGHT); updator.updateCanvasInfo(); + logger.info("Now left = " + Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue()); if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { horizontalWindowMovement(horizontal); } @@ -34,10 +35,17 @@ public void horizontalWindowMovement(int horizontal) { if (left + sizeHor / 3 > horizontal) { updator.sendKey(Keys.LEFT); updator.updateCanvasInfo(); + logger.info("Now left = " + Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue()); if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { horizontalWindowMovement(horizontal); } } + + updator.updateCanvasInfo(); + left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); + if (!inVisibleSpace(left, horizontal, sizeHor)) { + horizontalWindowMovement(horizontal); + } } /** Vertical movement. */ @@ -49,21 +57,32 @@ public void verticalWindowMovement(int vertical) { if (top + sizeVer * 2 / 3 < vertical) { updator.sendKey(Keys.DOWN); updator.updateCanvasInfo(); + logger.info("Now top = " + Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue()); if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { verticalWindowMovement(vertical); } - } - if (top + sizeVer / 3 > vertical) { + } else if (top + sizeVer / 3 > vertical) { updator.sendKey(Keys.UP); updator.updateCanvasInfo(); + logger.info("Now top = " + Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue()); if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { verticalWindowMovement(vertical); } } + + updator.updateCanvasInfo(); + top = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); + if (!inVisibleSpace(top, vertical, sizeVer)) { + verticalWindowMovement(vertical); + } } @Contract("_ -> !null") public static FocusHelper getFocusHelper(PageInfoUpdator updator) { return new FocusHelper(updator); } + + private boolean inVisibleSpace(int src, int dist, int size) { + return Math.abs(src - dist) <= size; + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 951139ea..ef62b070 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -30,9 +30,9 @@ public class SceneWindowImpl implements SceneWindow, PageInfoUpdator { private final MoveHelper moveHelper; - private int stepVert; + private int stepVert = 40; - private int stepHor; + private int stepHor = 40; /** Constructor takes links to current scene and current driver. */ private SceneWindowImpl(final Scene scene, final WebDriver driver, String selector) { @@ -101,7 +101,7 @@ public void updateCanvasInfo() { ); } try { - Thread.sleep(1000); + Thread.sleep(100); } catch (InterruptedException e) { logger.error(e.getMessage()); } @@ -110,10 +110,11 @@ public void updateCanvasInfo() { // todo: make it waits real time until action is completed @Override public void sendKey(Keys key) { - new Actions(driver).sendKeys(key).perform(); + $(selector).click(); + new Actions(driver).sendKeys(key).build().perform(); try { // wait hard coded time until action is completed - Thread.sleep(1000); + Thread.sleep(100); } catch (InterruptedException e) { logger.error(e.getMessage()); } From e77cadb48f020472d76f674d7e82606d9be39265 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 26 Feb 2017 18:10:25 +0300 Subject: [PATCH 34/40] Make focus works by JavaScriptExecutor --- .travis.yml | 1 + ui-testing/pom.xml | 2 +- .../dia/property/PropertyEditorImpl.java | 5 ++ .../wmp/uitesting/dia/scene/SceneImpl.java | 10 +-- .../uitesting/dia/scene/elements/Link.java | 22 +++-- .../dia/scene/window/FocusHelper.java | 88 ------------------- .../dia/scene/window/SceneWindowImpl.java | 22 ++++- ui-testing/ui-testing.iml | 1 + 8 files changed, 48 insertions(+), 103 deletions(-) delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java diff --git a/.travis.yml b/.travis.yml index 3ddf0c87..3692d2bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/ui-testing/pom.xml b/ui-testing/pom.xml index ac451c60..2ca83421 100644 --- a/ui-testing/pom.xml +++ b/ui-testing/pom.xml @@ -104,7 +104,7 @@ io.github.bonigarcia webdrivermanager - 1.4.10 + 1.6.0 diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java index 5c70f9be..a95c016b 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java @@ -37,6 +37,11 @@ public void setProperty(final SelenideElement element, final String propertyName public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException { $(By.cssSelector(SELECTOR)).click(); element.click(); + try { + Thread.sleep(300); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } SelenideElement property = getInputOfElement(propertyName); logger.info("Get value of preperty {}", propertyName); if (property.attr("class").equals("input-group")) { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index d5b6932d..0b9cb5e6 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -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); } @@ -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(); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java index dc0f9775..3a761e32 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java @@ -4,16 +4,18 @@ 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; @@ -21,11 +23,21 @@ public class Link extends SceneElementImpl { 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() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java deleted file mode 100644 index 23964981..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/FocusHelper.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.qreal.wmp.uitesting.dia.scene.window; - -import org.jetbrains.annotations.Contract; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static com.codeborne.selenide.Selenide.$; - -public class FocusHelper { - - private static final Logger logger = LoggerFactory.getLogger(FocusHelper.class); - - private final PageInfoUpdator updator; - - private FocusHelper(PageInfoUpdator updator) { - this.updator = updator; - } - - /** Horizontal movement. */ - public void horizontalWindowMovement(int horizontal) { - int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); - int left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); - logger.info("focus horizontal " + left + " " + sizeHor + " " + horizontal); - - if (left + sizeHor * 2 / 3 < horizontal) { - updator.sendKey(Keys.RIGHT); - updator.updateCanvasInfo(); - logger.info("Now left = " + Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue()); - if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { - horizontalWindowMovement(horizontal); - } - } - if (left + sizeHor / 3 > horizontal) { - updator.sendKey(Keys.LEFT); - updator.updateCanvasInfo(); - logger.info("Now left = " + Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue()); - if (Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue() != left) { - horizontalWindowMovement(horizontal); - } - } - - updator.updateCanvasInfo(); - left = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); - if (!inVisibleSpace(left, horizontal, sizeHor)) { - horizontalWindowMovement(horizontal); - } - } - - /** Vertical movement. */ - public void verticalWindowMovement(int vertical) { - int sizeVer = Double.valueOf($(By.id("SceneWindowVerSize")).innerHtml()).intValue(); - int top = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); - logger.info("focus vertical " + top + " " + sizeVer + " " + vertical); - - if (top + sizeVer * 2 / 3 < vertical) { - updator.sendKey(Keys.DOWN); - updator.updateCanvasInfo(); - logger.info("Now top = " + Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue()); - if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { - verticalWindowMovement(vertical); - } - } else if (top + sizeVer / 3 > vertical) { - updator.sendKey(Keys.UP); - updator.updateCanvasInfo(); - logger.info("Now top = " + Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue()); - if (Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue() != top) { - verticalWindowMovement(vertical); - } - } - - updator.updateCanvasInfo(); - top = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); - if (!inVisibleSpace(top, vertical, sizeVer)) { - verticalWindowMovement(vertical); - } - } - - @Contract("_ -> !null") - public static FocusHelper getFocusHelper(PageInfoUpdator updator) { - return new FocusHelper(updator); - } - - private boolean inVisibleSpace(int src, int dist, int size) { - return Math.abs(src - dist) <= size; - } -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index ef62b070..2d20083a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -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; @@ -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(); } @@ -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") diff --git a/ui-testing/ui-testing.iml b/ui-testing/ui-testing.iml index f1174f95..9aa516a1 100644 --- a/ui-testing/ui-testing.iml +++ b/ui-testing/ui-testing.iml @@ -21,6 +21,7 @@ + From a001a6d6e565d6b82942d87a3ae7ed9136bb8c51 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Mon, 27 Feb 2017 00:24:55 +0300 Subject: [PATCH 35/40] Add webdriver's timeouts --- .../java/com/qreal/wmp/uitesting/PageLoader.java | 16 ---------------- .../qreal/wmp/uitesting/config/DevConfig.java | 6 ++++++ .../dia/property/PropertyEditorImpl.java | 5 ----- .../qreal/wmp/uitesting/dia/scene/SceneImpl.java | 10 ---------- .../wmp/uitesting/dia/scene/elements/Link.java | 9 --------- .../dia/scene/window/SceneWindowImpl.java | 15 --------------- 6 files changed, 6 insertions(+), 55 deletions(-) diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java index a81f51bd..ca218ab9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java @@ -3,13 +3,9 @@ import com.qreal.wmp.uitesting.exceptions.WrongAuthException; import com.qreal.wmp.uitesting.services.Auther; import com.qreal.wmp.uitesting.services.Opener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class PageLoader { - private static final Logger logger = LoggerFactory.getLogger(PageLoader.class); - private final PageFactory pageFactory; private final Opener opener; @@ -25,12 +21,6 @@ public PageLoader(PageFactory pageFactory, Opener opener, Auther auther) { /** Loads and returns requested page with default authentication. */ public T load(Page page) { opener.open(page.getIdentify()); - // wait for load - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } return getPage(page); } @@ -38,12 +28,6 @@ public T load(Page page) { public T load(Page page, String username, String password) throws WrongAuthException { auther.auth(username, password); opener.open(page.getIdentify()); - // wait for load - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } return getPage(page); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index c05bf8fb..a834b827 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -17,6 +17,8 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.env.Environment; +import java.util.concurrent.TimeUnit; + /** Creates beans for Spring needs. **/ @Configuration @PropertySource("classpath:pages.properties") @@ -35,6 +37,10 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon public WebDriver webDriver() { ChromeDriverManager.getInstance().setup(); WebDriver driver = new ChromeDriver(); + driver.manage().window().maximize(); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS); + driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); WebDriverRunner.setWebDriver(driver); return driver; } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java index a95c016b..5c70f9be 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java @@ -37,11 +37,6 @@ public void setProperty(final SelenideElement element, final String propertyName public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException { $(By.cssSelector(SELECTOR)).click(); element.click(); - try { - Thread.sleep(300); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } SelenideElement property = getInputOfElement(propertyName); logger.info("Get value of preperty {}", propertyName); if (property.attr("class").equals("input-group")) { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 0b9cb5e6..cb973467 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -52,11 +52,6 @@ private SceneImpl(WebDriver webDriver) { createDiv("SceneWindowHorSize") + createDiv("SceneWindowVerSize") ); } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } sceneWindow = SceneWindowImpl.getSceneWindow(this, webDriver, SELECTOR); blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR); linkProvider = LinkProvider.getLinkProvider(SELECTOR, webDriver); @@ -148,11 +143,6 @@ private void removeSceneElement(SceneElement sceneElement) throws ElementNotOnTh sceneWindow.focus(sceneElement.getCoordinateOnScene()); logger.info("Remove element {} form scene", sceneElement.getInnerSeleniumElement().toString()); new Actions(webDriver).contextClick(sceneElement.getInnerSeleniumElement()).perform(); - try { - 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 " + contextMenu + " is not visible. Try to focus again. " ); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java index 3a761e32..d4f02c29 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java @@ -4,15 +4,11 @@ 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 { - private static final Logger logger = LoggerFactory.getLogger(Link.class); - public static final String CLASS_NAME = "link"; private static final String ARROWHEAD = "marker-arrowheads"; @@ -27,11 +23,6 @@ public class Link extends SceneElementImpl { public Link(String name, SelenideElement innerSeleniumObject) { super(innerSeleniumObject); this.name = name; - 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)")) ); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 2d20083a..69bedca1 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -87,16 +87,6 @@ public void focus(final Coordinate coordinate) { "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") @@ -116,11 +106,6 @@ public void updateCanvasInfo() { "$('#SceneWindowVerSize').html(BB.bottom - BB.top);" ); } - try { - Thread.sleep(100); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } } // todo: make it waits real time until action is completed From e0f219398211b85bfb9601220f3d16a601309b88 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 3 Mar 2017 02:31:33 +0300 Subject: [PATCH 36/40] Fix bug with movement 1. Fix bug with movement 2. Add scrolling by movement on the client side 3. Code refactor --- .travis.yml | 2 +- .../editorCore/controller/SceneController.ts | 114 +++++++++++++- .../app/core/editorCore/model/DiagramScene.ts | 7 +- .../app/core/editorCore/model/Scroller.ts | 42 +++++ .../qreal/wmp/uitesting/config/DevConfig.java | 4 +- .../wmp/uitesting/dia/scene/Coordinate.java | 8 +- .../wmp/uitesting/dia/scene/SceneImpl.java | 27 ++-- .../uitesting/dia/scene/elements/Block.java | 7 +- .../uitesting/dia/scene/elements/Link.java | 14 +- .../dia/scene/elements/SceneElement.java | 5 +- .../dia/scene/elements/SceneElementImpl.java | 27 ++-- .../dia/scene/providers/BlockProvider.java | 5 +- .../dia/scene/providers/LinkProvider.java | 5 +- .../dia/scene/window/MoveHelper.java | 83 ---------- .../dia/scene/window/PageInfoUpdator.java | 12 -- .../dia/scene/window/SceneWindowImpl.java | 149 +++++++++++------- 16 files changed, 304 insertions(+), 207 deletions(-) create mode 100644 editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java diff --git a/.travis.yml b/.travis.yml index 3692d2bd..c7cd3268 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ script: - cd ../ui-testing - mvn test -P travis & - - sleep 1200 + - sleep 900 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts index 7ce43ee1..32f5707e 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts @@ -3,6 +3,7 @@ /// /// /// +/// /// /// /// @@ -15,8 +16,10 @@ class SceneController { private currentElement: DiagramElement; private clickFlag : boolean; private rightClickFlag : boolean; + private scroller : Scroller; private undoRedoController: UndoRedoController; private lastCellMouseDownPosition: {x: number, y: number}; + private lastCellScrollPosition: {x: number, y: number}; private paperCommandFactory: SceneCommandFactory; private contextMenuId = "scene-context-menu"; @@ -27,7 +30,9 @@ class SceneController { this.paperCommandFactory = new SceneCommandFactory(this); this.clickFlag = false; this.rightClickFlag = false; + this.scroller = new Scroller(); this.lastCellMouseDownPosition = { x: 0, y: 0 }; + this.lastCellScrollPosition = { x: 0, y: 0 }; this.scene.on('cell:pointerdown', (cellView, event, x, y): void => { this.cellPointerdownListener(cellView, event, x, y); @@ -44,10 +49,12 @@ class SceneController { }); this.diagramEditorController.getGraph().on('change:position', (cell) => { - if (!this.rightClickFlag) { - return; + if (this.scroller.scroll) { + cell.set('position', this.lastCellScrollPosition); + } + if (this.rightClickFlag) { + cell.set('position', cell.previous('position')); } - cell.set('position', cell.previous('position')); }); this.initDropPaletteElementListener(); @@ -252,7 +259,7 @@ class SceneController { this.changeCurrentElement(element); if (this.scene.getNodeById(cellView.model.id) && event.button == MouseButton.left) { - var node:DiagramNode = this.scene.getNodeById(cellView.model.id); + var node: DiagramNode = this.scene.getNodeById(cellView.model.id); this.lastCellMouseDownPosition.x = node.getX(); this.lastCellMouseDownPosition.y = node.getY(); } @@ -271,6 +278,7 @@ class SceneController { }); } else if (event.button == MouseButton.left){ + this.borderUnCrossed(); var node: DiagramNode = this.scene.getNodeById(cellView.model.id); if (node) { var command: Command = this.paperCommandFactory.makeMoveCommand(node, this.lastCellMouseDownPosition.x, @@ -281,6 +289,28 @@ class SceneController { } private cellPointermoveListener(cellView, event, x, y): void { + var element: DiagramElement = this.scene.getNodeById(cellView.model.id) || + this.scene.getLinkById(cellView.model.id); + var sceneWrapper: HTMLDivElement = $(".scene-wrapper")[0]; + var boundingBox: any = sceneWrapper.getBoundingClientRect(); + if (element instanceof DefaultDiagramNode) { + var node = this.scene.getNodeById(cellView.model.id); + this.borderUnCrossed(); + if (event.pageX + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.right) { + this.scroller.direction = Direction.Right; + this.borderCrossed(node, event); + } else if (event.pageX - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.left) { + this.scroller.direction = Direction.Left; + this.borderCrossed(node, event); + } else if (event.pageY + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.bottom) { + this.scroller.direction = Direction.Down; + this.borderCrossed(node, event); + } else if (event.pageY - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.top) { + this.scroller.direction = Direction.Up; + this.borderCrossed(node, event); + } + this.updateLastCellScrollPosition(event); + } this.clickFlag = false; } @@ -371,4 +401,80 @@ class SceneController { }); } + private borderCrossed(node: DiagramNode, event): void { + this.scroller.scroll = true; + var that = this; + switch (this.scroller.direction) { + case Direction.Right: { + this.scroller.intervalId = setInterval(() => that.scrollRight(node, event), 150); + break; + } + case Direction.Left: { + this.scroller.intervalId = setInterval(() => that.scrollLeft(node, event), 150); + break; + } + case Direction.Down: { + this.scroller.intervalId = setInterval(() => that.scrollBottom(node, event), 150); + break; + } + case Direction.Up: { + this.scroller.intervalId = setInterval(() => that.scrollTop(node, event), 150); + break; + } + } + } + + private borderUnCrossed(): void { + this.scroller.direction = Direction.None; + if (this.scroller.intervalId != -1) { + clearInterval(this.scroller.intervalId); + this.scroller.intervalId = -1; + this.scroller.scroll = false; + } + } + + private scrollRight(node: DiagramNode, event) : void { + var sceneWrapper : HTMLDivElement = ( $(".scene-wrapper")[0]); + sceneWrapper.scrollLeft += this.scene.getGridSize() * this.scene.getZoom(); + if (node.getX() + 3 * this.scene.getGridSize() <= DiagramScene.WIDTH) { + this.updateLastCellScrollPosition(event); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + } + } + + private scrollLeft(node: DiagramNode, event) : void { + ( $(".scene-wrapper")[0]).scrollLeft -= this.scene.getGridSize() * this.scene.getZoom(); + if (node.getX() >= this.scene.getGridSize()) { + this.updateLastCellScrollPosition(event); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + } + } + + private scrollBottom(node: DiagramNode, event) : void { + ( $(".scene-wrapper")[0]).scrollTop += this.scene.getGridSize() * this.scene.getZoom(); + if (node.getY() + 3 * this.scene.getGridSize() <= DiagramScene.HEIGHT) { + this.updateLastCellScrollPosition(event); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + } + } + + private scrollTop(node: DiagramNode, event) : void { + ( $(".scene-wrapper")[0]).scrollTop -= this.scene.getGridSize() * this.scene.getZoom(); + if (node.getY() >= this.scene.getGridSize()) { + this.updateLastCellScrollPosition(event); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + } + } + + private updateLastCellScrollPosition(event) : void { + var offsetX = (event.pageX - $("#" + this.scene.getId()).offset().left + + $("#" + this.scene.getId()).scrollLeft()) / this.scene.getZoom(); + var offsetY = (event.pageY - $("#" + this.scene.getId()).offset().top + + $("#" + this.scene.getId()).scrollTop()) / this.scene.getZoom(); + var gridSize: number = this.scene.getGridSize(); + offsetX -= offsetX % gridSize; + offsetY -= offsetY % gridSize; + this.lastCellScrollPosition.x = Math.min(offsetX, DiagramScene.WIDTH - 2 * this.scene.getGridSize()); + this.lastCellScrollPosition.y = Math.min(offsetY, DiagramScene.HEIGHT - 2 * this.scene.getGridSize()); + } } \ No newline at end of file diff --git a/editor-core/src/main/webapp/app/core/editorCore/model/DiagramScene.ts b/editor-core/src/main/webapp/app/core/editorCore/model/DiagramScene.ts index a5b6bd93..b25e86ec 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/model/DiagramScene.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/model/DiagramScene.ts @@ -6,6 +6,9 @@ class DiagramScene extends joint.dia.Paper { + public static get WIDTH(): number {return 2000;} + public static get HEIGHT(): number {return 2000;} + private htmlId: string; private graph: joint.dia.Graph; private currentLinkType: string; @@ -22,8 +25,8 @@ class DiagramScene extends joint.dia.Paper { super({ el: $('#' + htmlId), - width: 2000, - height: 2000, + width: DiagramScene.WIDTH, + height: DiagramScene.HEIGHT, model: graph, gridSize: gridSize, defaultLink: new joint.dia.Link({ diff --git a/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts new file mode 100644 index 00000000..43694f6f --- /dev/null +++ b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts @@ -0,0 +1,42 @@ +enum Direction { + Up, Down, Left, Right, None +} + +class Scroller { + + private _scroll: boolean; + + private _intervalId: number; + + private _direction: Direction; + + constructor() { + this.scroll = false; + this.direction = Direction.None; + } + + get direction(): Direction { + return this._direction; + } + + set direction(value: Direction) { + this._direction = value; + } + + get intervalId(): number { + return this._intervalId; + } + + set intervalId(value: number) { + this._intervalId = value; + } + + get scroll(): boolean { + return this._scroll; + } + + set scroll(value: boolean) { + this._scroll = value; + } + +} \ No newline at end of file diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index a834b827..8599d2e0 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -38,9 +38,9 @@ public WebDriver webDriver() { ChromeDriverManager.getInstance().setup(); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); - driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS); - driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); + driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS); WebDriverRunner.setWebDriver(driver); return driver; } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java index aed099e9..cf19d42a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java @@ -7,7 +7,9 @@ public class Coordinate { - private static final int POINT_IN_CELL = 25; + public static final String SELECTOR = "transform"; + + public static final int POINT_IN_CELL = 25; private final int xAbsolute; @@ -50,4 +52,8 @@ public int getYAbsolute() { public boolean equals(final Coordinate other) { return xAbsolute == other.getXAbsolute() && yAbsolute == other.getYAbsolute(); } + + public String toString() { + return "(" + getXAbsolute() + "," + getYAbsolute() + ")"; + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index cb973467..70f7e4c2 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -2,6 +2,7 @@ import com.codeborne.selenide.Condition; import com.codeborne.selenide.SelenideElement; +import com.google.common.base.Predicate; import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; import com.qreal.wmp.uitesting.dia.scene.elements.Block; @@ -17,6 +18,7 @@ import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.WebDriverWait; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +54,7 @@ private SceneImpl(WebDriver webDriver) { createDiv("SceneWindowHorSize") + createDiv("SceneWindowVerSize") ); } - sceneWindow = SceneWindowImpl.getSceneWindow(this, webDriver, SELECTOR); + sceneWindow = SceneWindowImpl.getSceneWindow(webDriver); blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR); linkProvider = LinkProvider.getLinkProvider(SELECTOR, webDriver); } @@ -75,6 +77,7 @@ public void moveToCell(Block block, final int cell_x, final int cell_y) { blockProvider.moveToCell(block, cell_x, cell_y); } + @SuppressWarnings("SimplifiableIfStatement") @Override public boolean exist(SceneElement element) { if (element instanceof Block) { @@ -142,15 +145,19 @@ 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()).perform(); + new Actions(webDriver) + .contextClick(sceneElement.getInnerSeleniumElement()) + .build() + .perform(); SelenideElement contextMenu = $(By.id("scene-context-menu")); - if (!contextMenu.is(Condition.visible)) { - logger.info("Context menu " + contextMenu + " is not visible. Try to focus again. " ); - removeSceneElement(sceneElement); - } else { - contextMenu.click(); - blockProvider.recalculateBlocks(); - linkProvider.recalculateLinks(); - } + contextMenu.shouldBe(Condition.visible); + contextMenu.click(); + (new WebDriverWait(webDriver, 5)) + .until((Predicate) webDriver -> { + assert webDriver != null; + return webDriver.findElements(sceneElement.getBy()).size() == 0; + }); + blockProvider.recalculateBlocks(); + linkProvider.recalculateLinks(); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java index 757552be..def9e525 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java @@ -1,6 +1,5 @@ package com.qreal.wmp.uitesting.dia.scene.elements; -import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.$; @@ -15,10 +14,10 @@ public class Block extends SceneElementImpl { private final SceneElement port; - public Block(String name, SelenideElement innerSeleniumObject) { - super(innerSeleniumObject); + public Block(String name, By by) { + super(by); this.name = name; - this.port = new SceneElementImpl($(innerSeleniumObject.find(By.className(PORT_CLASS_NAME)))); + this.port = new SceneElementImpl(By.id($(by).find(By.className(PORT_CLASS_NAME)).attr("id"))); } public String getName() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java index d4f02c29..6da6e550 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java @@ -20,15 +20,13 @@ public class Link extends SceneElementImpl { private final SceneElement target; /** Describes link between two blocks. */ - public Link(String name, SelenideElement innerSeleniumObject) { - super(innerSeleniumObject); + public Link(String name, By by) { + super(by); this.name = name; - 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)")) - ); + SelenideElement source = $(by).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(1)")); + this.source = new SceneElementImpl(By.id(source.attr("id"))); + SelenideElement target = $(by).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(2)")); + this.target = new SceneElementImpl(By.id(target.attr("id"))); } public String getName() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java index 3424db18..cba5a1cf 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElement.java @@ -3,12 +3,13 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.scene.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; +import org.openqa.selenium.By; /** Describes any element on the Scene. */ public interface SceneElement { SelenideElement getInnerSeleniumElement(); - Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException; + By getBy(); - String getType(); + Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException; } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java index 08e88181..fd0436cb 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java @@ -3,32 +3,29 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.scene.Coordinate; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; +import org.openqa.selenium.By; + +import static com.codeborne.selenide.Selenide.$; public class SceneElementImpl implements SceneElement { - private final SelenideElement innerSeleniumElement; + private By by; - private String type; + public SceneElementImpl(By by) { + this.by = by; + } /** Based on the Selenium element. */ - public SceneElementImpl(SelenideElement innerSeleniumObject) { - this.innerSeleniumElement = innerSeleniumObject; - this.type = innerSeleniumObject.attr("class"); - if (type.contains("selected")) { - type = type.substring(0, type.indexOf(" selected")); - } + public SelenideElement getInnerSeleniumElement() { + return $(by); } - public SelenideElement getInnerSeleniumElement() { - return innerSeleniumElement; + public By getBy() { + return by; } public Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException { - return Coordinate.getCoordinateFromSeleniumObject(innerSeleniumElement) + return Coordinate.getCoordinateFromSeleniumObject(getInnerSeleniumElement()) .orElseThrow(ElementNotOnTheSceneException::new); } - - public String getType() { - return type; - } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java index 5b98d6ae..e79e1b8a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java @@ -49,7 +49,7 @@ public List getBlocks() { public Block getNewBlock() { final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); logger.info("Add element {} to scene", newEl); - Block block = new Block(newEl.attr("id"), newEl); + Block block = new Block(newEl.attr("id"), By.id(newEl.attr("id"))); blocks.add(block); return block; } @@ -65,7 +65,7 @@ public boolean isEmpty() { public void recalculateBlocks() { blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream() .filter(x -> x.attr("class").contains(Block.CLASS_NAME)) - .map(x -> new Block(x.attr("id"), x)) + .map(x -> new Block(x.attr("id"), By.id(x.attr("id")))) .collect(Collectors.toSet()); } @@ -84,5 +84,4 @@ private Optional updateBlocks() { .attr("id").equals(htmlElement.attr("id"))) ).findFirst(); } - } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java index 6b8c9029..e82240f4 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java @@ -49,11 +49,12 @@ public Link addLink(final Block source, final Block target) { source.getInnerSeleniumElement().attr("id") + " .outPorts")); logger.info("Begin element {}, end element {} ", begin, target); new Actions(webDriver) + .release() .dragAndDrop(source.getPort().getInnerSeleniumElement(), target.getInnerSeleniumElement()) .build().perform(); SelenideElement newEl = updateLinks().orElseThrow(() -> new NoSuchElementException("Link was not created")); logger.info("Add link {}", newEl); - Link res = new Link(newEl.attr("id"), newEl); + Link res = new Link(newEl.attr("id"), By.id(newEl.attr("id"))); links.add(res); return res; } @@ -61,7 +62,7 @@ public Link addLink(final Block source, final Block target) { public void recalculateLinks() { links = $$(By.cssSelector(selector + " #v_7 > *")).stream() .filter(x -> x.attr("class").contains(Link.CLASS_NAME)) - .map(x -> new Link(x.attr("id"), x)) + .map(x -> new Link(x.attr("id"), By.id(x.attr("id")))) .collect(Collectors.toSet()); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java deleted file mode 100644 index 027cadb2..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/MoveHelper.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.qreal.wmp.uitesting.dia.scene.window; - -import com.codeborne.selenide.SelenideElement; -import com.qreal.wmp.uitesting.dia.scene.Coordinate; -import com.qreal.wmp.uitesting.dia.scene.Scene; -import com.qreal.wmp.uitesting.dia.scene.elements.Block; -import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.interactions.Actions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public class MoveHelper { - - private static final Logger logger = LoggerFactory.getLogger(MoveHelper.class); - - private final Scene scene; - - private final WebDriver driver; - - private MoveHelper(Scene scene, WebDriver driver) { - this.scene = scene; - this.driver = driver; - } - - /** Horizontal move. */ - public Actions callDragAndDropByX(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { - final List elements = scene.getBlocks(); - return Math.abs(src - dst) > Math.abs(step) ? - callDragAndDropByX(src + step, dst, step, - actions.sendKeys(key) - .clickAndHold(element) - .moveByOffset(jump(elements, 2 * step, src), 0), key, element - ) : actions.sendKeys(key, key); - } - - /** Vertical move. */ - public Actions callDragAndDropByY(int src, int dst, int step, Actions actions, Keys key, SelenideElement element) { - final List elements = scene.getBlocks(); - return Math.abs(src - dst) > Math.abs(step) ? - callDragAndDropByY(src + step, dst, step, - actions.sendKeys(key) - .clickAndHold(element) - .moveByOffset(0, jump(elements, 2 * step, src)), key, element - ) : actions.sendKeys(key, key); - } - - /** Movement to the exact point when element in the SceneWindow. */ - public Coordinate finalJump(Block block, Coordinate dist) throws ElementNotOnTheSceneException { - Coordinate currentPosition = block.getCoordinateOnScene(); - - new Actions(driver).release() - .clickAndHold(block.getInnerSeleniumElement()) - .moveByOffset( - dist.getXAbsolute() - currentPosition.getXAbsolute(), - dist.getYAbsolute() - currentPosition.getYAbsolute() - ).release().perform(); - - return block.getCoordinateOnScene(); - } - - private int jump(final List elements, int step, int current) { - if (elements.stream().anyMatch(x -> { - try { - return Math.abs(current - x.getCoordinateOnScene().getXAbsolute()) < Math.abs(2 * step); - } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); - } - return false; - })) { - return step + jump(elements, step, step + current); - } else { - return step; - } - } - - public static MoveHelper getMoveHelper(Scene scene, WebDriver webDriver) { - return new MoveHelper(scene, webDriver); - } -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java deleted file mode 100644 index 7158f29f..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/PageInfoUpdator.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.qreal.wmp.uitesting.dia.scene.window; - -import org.openqa.selenium.Keys; - -public interface PageInfoUpdator { - - void updateSteps(); - - void sendKey(Keys key); - - void updateCanvasInfo(); -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 69bedca1..76554a7e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -1,43 +1,35 @@ package com.qreal.wmp.uitesting.dia.scene.window; +import com.google.common.base.Predicate; import com.qreal.wmp.uitesting.dia.scene.Coordinate; -import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; +import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; import org.jetbrains.annotations.Contract; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.WebDriverWait; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Random; + import static com.codeborne.selenide.Selenide.$; /** * Describes part of the scene, which is shown on browser. */ -public class SceneWindowImpl implements SceneWindow, PageInfoUpdator { +public class SceneWindowImpl implements SceneWindow { private static final Logger logger = LoggerFactory.getLogger(SceneWindowImpl.class); private final WebDriver driver; - private final String selector; - - private final MoveHelper moveHelper; - - private int stepVert = 40; - - private int stepHor = 40; - /** Constructor takes links to current scene and current driver. */ - private SceneWindowImpl(final Scene scene, final WebDriver driver, String selector) { + private SceneWindowImpl(final WebDriver driver) { this.driver = driver; - this.selector = selector; - moveHelper = MoveHelper.getMoveHelper(scene, driver); - updateSteps(); } /** @@ -50,31 +42,50 @@ private SceneWindowImpl(final Scene scene, final WebDriver driver, String select public void move(final Block element, final Coordinate dist) throws ElementNotOnTheSceneException { Coordinate src = element.getCoordinateOnScene(); focus(src); - - if (src.getXAbsolute() < dist.getXAbsolute()) { - moveHelper.callDragAndDropByX( - src.getXAbsolute(), dist.getXAbsolute(), stepHor, - new Actions(driver), Keys.ARROW_RIGHT, element.getInnerSeleniumElement()).perform(); + int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); + int sizeVer = Double.valueOf($(By.id("SceneWindowVerSize")).innerHtml()).intValue(); + + Actions actions = new Actions(driver); + actions.clickAndHold(element.getInnerSeleniumElement()); + if (Math.abs(dist.getXAbsolute() - element.getCoordinateOnScene().getXAbsolute()) < sizeHor / 2 + && Math.abs(dist.getYAbsolute() - element.getCoordinateOnScene().getYAbsolute()) < sizeVer / 2) { + jump(actions, element, dist); } else { - moveHelper.callDragAndDropByX(src.getXAbsolute(), dist.getXAbsolute(), -stepHor, - new Actions(driver), Keys.ARROW_LEFT, element.getInnerSeleniumElement()).perform(); + Predicate condX = x -> Math.abs(x.getXAbsolute() - dist.getXAbsolute()) <= sizeHor / 3; + if (src.getXAbsolute() < dist.getXAbsolute()) { + movement(actions, element, new OffsetObject(sizeHor / 4, 0), condX); + } else { + movement(actions, element, new OffsetObject(-sizeHor / 4, 0), condX); + } } - - if (src.getYAbsolute() < dist.getYAbsolute()) { - moveHelper.callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), stepVert, - new Actions(driver), Keys.ARROW_DOWN, element.getInnerSeleniumElement()).perform(); + if (Math.abs(dist.getXAbsolute() - element.getCoordinateOnScene().getXAbsolute()) < sizeHor / 2 + && Math.abs(dist.getYAbsolute() - element.getCoordinateOnScene().getYAbsolute()) < sizeVer / 2) { + jump(actions, element, dist); } else { - moveHelper.callDragAndDropByY(src.getYAbsolute(), dist.getYAbsolute(), -stepVert, - new Actions(driver), Keys.ARROW_UP, element.getInnerSeleniumElement()).perform(); + Predicate condY = x -> Math.abs(x.getYAbsolute() - dist.getYAbsolute()) <= sizeVer / 3; + if (src.getYAbsolute() < dist.getYAbsolute()) { + movement(actions, element, new OffsetObject(0, sizeVer / 4), condY); + } else { + movement(actions, element, new OffsetObject(0, -sizeVer / 4), condY); + } } + + jump(actions, element, dist); - if (!moveHelper.finalJump(element, dist).equals(dist)) { - move(element, dist); - } + (new WebDriverWait(driver, 20)) + .until((Predicate) webDriver -> { + try { + return element.getCoordinateOnScene().equals(dist); + } catch (ElementNotOnTheSceneException e) { + logger.error(e.getMessage()); + } + return false; + }); } @Override public void focus(final Coordinate coordinate) { + updateCanvasInfo(); int sizeHor = Double.valueOf($(By.id("SceneWindowHorSize")).innerHtml()).intValue(); int sizeVer = Double.valueOf($(By.id("SceneWindowVerSize")).innerHtml()).intValue(); @@ -87,15 +98,15 @@ public void focus(final Coordinate coordinate) { "canvas.scrollTop = " + Math.max(0, (coordinate.getYAbsolute() - sizeVer / 2)) + ";" ); } + updateCanvasInfo(); } - @Contract("_, _, _ -> !null") - public static SceneWindow getSceneWindow(Scene scene, WebDriver webDriver, String selector) { - return new SceneWindowImpl(scene, webDriver, selector); + @Contract("_ -> !null") + public static SceneWindow getSceneWindow(WebDriver webDriver) { + return new SceneWindowImpl(webDriver); } - @Override - public void updateCanvasInfo() { + private void updateCanvasInfo() { if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("var canvas = " + "document.getElementsByClassName(\"scene-wrapper\")[0]; " + @@ -108,30 +119,52 @@ public void updateCanvasInfo() { } } - // todo: make it waits real time until action is completed - @Override - public void sendKey(Keys key) { - $(selector).click(); - new Actions(driver).sendKeys(key).build().perform(); - try { - // wait hard coded time until action is completed - Thread.sleep(100); - } catch (InterruptedException e) { - logger.error(e.getMessage()); + private void movement(Actions actions, SceneElement element, OffsetObject offset, Predicate cond) { + (new WebDriverWait(driver, 40)) + .until((Predicate) webDriver -> { + try { + Coordinate current = element.getCoordinateOnScene(); + actions.moveToElement(element.getInnerSeleniumElement()).perform(); + actions.moveByOffset(offset.offsetX, offset.offsetY).perform(); + + focus(element.getCoordinateOnScene()); + if (element.getCoordinateOnScene().equals(current)) { + Random random = new Random(); + int signX = (int) Math.signum(offset.offsetX); + int signY = (int) Math.signum(offset.offsetY); + if (offset.offsetX != 0) { + offset.offsetX = signX * random.nextInt(Math.abs(offset.offsetX)); + } + if (offset.offsetY != 0) { + offset.offsetY = signY * random.nextInt(Math.abs(offset.offsetY)); + } + } + return cond.apply(element.getCoordinateOnScene()); + } catch (ElementNotOnTheSceneException e) { + logger.error(e.getMessage()); + } + return false; + }); + } + + private void jump(Actions actions, SceneElement element, Coordinate dist) throws ElementNotOnTheSceneException { + if (!element.getCoordinateOnScene().equals(dist)) { + focus(element.getCoordinateOnScene()); + actions.moveToElement(element.getInnerSeleniumElement()).moveByOffset( + dist.getXAbsolute() - element.getCoordinateOnScene().getXAbsolute(), + dist.getYAbsolute() - element.getCoordinateOnScene().getYAbsolute() + ).release().build().perform(); } } - @Override - public void updateSteps() { - updateCanvasInfo(); - $(selector).click(); - focus(new Coordinate(0, 0)); - updateCanvasInfo(); - sendKey(Keys.DOWN); - sendKey(Keys.RIGHT); - updateCanvasInfo(); - stepHor = Double.valueOf($(By.id("SceneWindowLeft")).innerHtml()).intValue(); - stepVert = Double.valueOf($(By.id("SceneWindowTop")).innerHtml()).intValue(); - logger.info("stepHor = " + stepHor + "; stepVert = " + stepVert); + private class OffsetObject { + private int offsetX; + + private int offsetY; + + OffsetObject(int offsetX, int offsetY) { + this.offsetX = offsetX; + this.offsetY = offsetY; + } } } \ No newline at end of file From d2235ef3a7283a00223348f9bec383b792a7db81 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Fri, 3 Mar 2017 04:19:19 +0300 Subject: [PATCH 37/40] Remove unnecessary changes --- .idea/compiler.xml | 4 --- auth-service/auth-service.iml | 23 ++++++------ dashboard-service/dashboard-service.iml | 19 +++++----- .../db-diagram-service/db-diagram-service.iml | 34 +++++++++--------- .../db-robot-store-service.iml | 34 +++++++++--------- .../db-user-service/db-user-service.iml | 36 +++++++++---------- editor-core/editor-core.iml | 10 +++--- editor-service/editor-service.iml | 31 ++++++++++------ 8 files changed, 100 insertions(+), 91 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 2f1f7afb..bb3e7ab5 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -28,10 +28,8 @@ - - @@ -44,13 +42,11 @@ - - diff --git a/auth-service/auth-service.iml b/auth-service/auth-service.iml index ffe883e0..d89f887a 100644 --- a/auth-service/auth-service.iml +++ b/auth-service/auth-service.iml @@ -34,9 +34,19 @@ + + + + + + + + + + @@ -48,6 +58,7 @@ + @@ -58,19 +69,11 @@ - - + - - - - - - - @@ -91,11 +94,9 @@ - - diff --git a/dashboard-service/dashboard-service.iml b/dashboard-service/dashboard-service.iml index 41da8daf..7c0486b6 100644 --- a/dashboard-service/dashboard-service.iml +++ b/dashboard-service/dashboard-service.iml @@ -42,10 +42,19 @@ + + + + + + + + + @@ -69,19 +78,12 @@ - - + - - - - - - @@ -92,7 +94,6 @@ - diff --git a/db-services/db-diagram-service/db-diagram-service.iml b/db-services/db-diagram-service/db-diagram-service.iml index 92f68a7d..fcd0f081 100644 --- a/db-services/db-diagram-service/db-diagram-service.iml +++ b/db-services/db-diagram-service/db-diagram-service.iml @@ -55,23 +55,23 @@ + - - - + - - + + + @@ -79,24 +79,27 @@ - + + + - - + + - - + + + + - @@ -107,31 +110,28 @@ - + + - + - - - - diff --git a/db-services/db-robot-store-service/db-robot-store-service.iml b/db-services/db-robot-store-service/db-robot-store-service.iml index 70ecb56b..71ce90e8 100644 --- a/db-services/db-robot-store-service/db-robot-store-service.iml +++ b/db-services/db-robot-store-service/db-robot-store-service.iml @@ -55,10 +55,10 @@ + - @@ -70,14 +70,14 @@ - - + - - + + + @@ -85,24 +85,27 @@ - + + + - - + + - - + + + + - @@ -113,31 +116,28 @@ - + + - + - - - - diff --git a/db-services/db-user-service/db-user-service.iml b/db-services/db-user-service/db-user-service.iml index 1a54fc5e..8b45b365 100644 --- a/db-services/db-user-service/db-user-service.iml +++ b/db-services/db-user-service/db-user-service.iml @@ -57,12 +57,12 @@ + + - - @@ -77,14 +77,14 @@ - - + - - + + + @@ -92,24 +92,27 @@ - + + + - - + + - - + + + + - @@ -120,31 +123,28 @@ - + + - + - - - - diff --git a/editor-core/editor-core.iml b/editor-core/editor-core.iml index 6c2502de..8d46b138 100644 --- a/editor-core/editor-core.iml +++ b/editor-core/editor-core.iml @@ -4,14 +4,14 @@ - + - - + + @@ -28,8 +28,10 @@ + + @@ -45,11 +47,9 @@ - - diff --git a/editor-service/editor-service.iml b/editor-service/editor-service.iml index adbddda2..f9cb9c49 100644 --- a/editor-service/editor-service.iml +++ b/editor-service/editor-service.iml @@ -7,6 +7,17 @@ + + + + + + + + + + + @@ -48,9 +59,17 @@ + + + + + + + + @@ -74,19 +93,12 @@ - - + - - - - - - @@ -97,7 +109,6 @@ - @@ -107,6 +118,7 @@ + @@ -120,7 +132,6 @@ - From fc2fa5240e1604d63b7629502fa3f4b8c23ae86c Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Mar 2017 23:25:34 +0300 Subject: [PATCH 38/40] Code refactor, java doc and style guide --- .travis.yml | 2 +- .../editorCore/controller/SceneController.ts | 65 ++++++++++--------- .../app/core/editorCore/model/Scroller.ts | 30 ++++----- .../java/com/qreal/wmp/uitesting/Page.java | 1 + .../com/qreal/wmp/uitesting/PageFactory.java | 1 + .../com/qreal/wmp/uitesting/PageLoader.java | 4 ++ .../qreal/wmp/uitesting/config/DevConfig.java | 2 +- .../wmp/uitesting/dia/pallete/Pallete.java | 2 +- .../uitesting/dia/pallete/PalleteElement.java | 2 + .../uitesting/dia/pallete/PalleteImpl.java | 1 + .../dia/property/PropertyEditor.java | 3 +- .../dia/property/PropertyEditorImpl.java | 1 + .../wmp/uitesting/dia/scene/Coordinate.java | 5 +- .../qreal/wmp/uitesting/dia/scene/Scene.java | 4 +- .../wmp/uitesting/dia/scene/SceneImpl.java | 14 ++-- .../uitesting/dia/scene/elements/Block.java | 16 ++++- .../uitesting/dia/scene/elements/Link.java | 9 +-- .../dia/scene/elements/SceneElementImpl.java | 13 ++-- .../dia/scene/providers/BlockProvider.java | 25 ++++--- .../dia/scene/providers/LinkProvider.java | 1 + .../dia/scene/window/SceneWindowImpl.java | 41 ++++++++---- .../ElementNotOnTheSceneException.java | 2 +- .../qreal/wmp/uitesting/pages/AuthPage.java | 1 + .../wmp/uitesting/pages/DashboardPage.java | 1 + .../qreal/wmp/uitesting/pages/EditorPage.java | 3 + .../uitesting/services/impl/AutherImpl.java | 1 + .../uitesting/services/impl/OpenerImpl.java | 1 + ...Test.java => ManipulatingDiagramTest.java} | 12 ++-- .../testspace/DiagramConstructingTest.java | 6 +- ui-testing/ui-testing.iml | 1 + 30 files changed, 167 insertions(+), 103 deletions(-) rename ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/{DiaTest.java => ManipulatingDiagramTest.java} (94%) diff --git a/.travis.yml b/.travis.yml index c7cd3268..b60f5b0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ script: - cd ../ui-testing - mvn test -P travis & - - sleep 900 + - sleep 1000 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts index 32f5707e..40f599d6 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts @@ -49,7 +49,7 @@ class SceneController { }); this.diagramEditorController.getGraph().on('change:position', (cell) => { - if (this.scroller.scroll) { + if (this.scroller.getScroll()) { cell.set('position', this.lastCellScrollPosition); } if (this.rightClickFlag) { @@ -291,25 +291,8 @@ class SceneController { private cellPointermoveListener(cellView, event, x, y): void { var element: DiagramElement = this.scene.getNodeById(cellView.model.id) || this.scene.getLinkById(cellView.model.id); - var sceneWrapper: HTMLDivElement = $(".scene-wrapper")[0]; - var boundingBox: any = sceneWrapper.getBoundingClientRect(); if (element instanceof DefaultDiagramNode) { - var node = this.scene.getNodeById(cellView.model.id); - this.borderUnCrossed(); - if (event.pageX + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.right) { - this.scroller.direction = Direction.Right; - this.borderCrossed(node, event); - } else if (event.pageX - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.left) { - this.scroller.direction = Direction.Left; - this.borderCrossed(node, event); - } else if (event.pageY + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.bottom) { - this.scroller.direction = Direction.Down; - this.borderCrossed(node, event); - } else if (event.pageY - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.top) { - this.scroller.direction = Direction.Up; - this.borderCrossed(node, event); - } - this.updateLastCellScrollPosition(event); + this.checkBorder(element, cellView, event) } this.clickFlag = false; } @@ -401,35 +384,57 @@ class SceneController { }); } + private checkBorder(element: DiagramElement, cellView, event) : void { + var sceneWrapper: HTMLDivElement = $(".scene-wrapper")[0]; + var boundingBox: any = sceneWrapper.getBoundingClientRect(); + + var node = this.scene.getNodeById(cellView.model.id); + this.borderUnCrossed(); + if (event.pageX + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.right) { + this.scroller.setDirection(Direction.Right); + this.borderCrossed(node, event); + } else if (event.pageX - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.left) { + this.scroller.setDirection(Direction.Left); + this.borderCrossed(node, event); + } else if (event.pageY + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.bottom) { + this.scroller.setDirection(Direction.Down); + this.borderCrossed(node, event); + } else if (event.pageY - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.top) { + this.scroller.setDirection(Direction.Up); + this.borderCrossed(node, event); + } + this.updateLastCellScrollPosition(event); + } + private borderCrossed(node: DiagramNode, event): void { - this.scroller.scroll = true; + this.scroller.setScroll(true); var that = this; - switch (this.scroller.direction) { + switch (this.scroller.getDirection()) { case Direction.Right: { - this.scroller.intervalId = setInterval(() => that.scrollRight(node, event), 150); + this.scroller.setIntervalId(setInterval(() => that.scrollRight(node, event), 150)); break; } case Direction.Left: { - this.scroller.intervalId = setInterval(() => that.scrollLeft(node, event), 150); + this.scroller.setIntervalId(setInterval(() => that.scrollLeft(node, event), 150)); break; } case Direction.Down: { - this.scroller.intervalId = setInterval(() => that.scrollBottom(node, event), 150); + this.scroller.setIntervalId(setInterval(() => that.scrollBottom(node, event), 150)); break; } case Direction.Up: { - this.scroller.intervalId = setInterval(() => that.scrollTop(node, event), 150); + this.scroller.setIntervalId(setInterval(() => that.scrollTop(node, event), 150)); break; } } } private borderUnCrossed(): void { - this.scroller.direction = Direction.None; - if (this.scroller.intervalId != -1) { - clearInterval(this.scroller.intervalId); - this.scroller.intervalId = -1; - this.scroller.scroll = false; + this.scroller.setDirection(Direction.None); + if (this.scroller.getIntervalId() != -1) { + clearInterval(this.scroller.getIntervalId()); + this.scroller.setIntervalId(-1); + this.scroller.setScroll(false); } } diff --git a/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts index 43694f6f..c6540611 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts @@ -4,39 +4,39 @@ enum Direction { class Scroller { - private _scroll: boolean; + private scroll: boolean; - private _intervalId: number; + private intervalId: number; - private _direction: Direction; + private direction: Direction; constructor() { this.scroll = false; this.direction = Direction.None; } - get direction(): Direction { - return this._direction; + public getDirection(): Direction { + return this.direction; } - set direction(value: Direction) { - this._direction = value; + public setDirection(value: Direction) { + this.direction = value; } - get intervalId(): number { - return this._intervalId; + public getIntervalId(): number { + return this.intervalId; } - set intervalId(value: number) { - this._intervalId = value; + public setIntervalId(value: number) { + this.intervalId = value; } - get scroll(): boolean { - return this._scroll; + public getScroll(): boolean { + return this.scroll; } - set scroll(value: boolean) { - this._scroll = value; + public setScroll(value: boolean) { + this.scroll = value; } } \ No newline at end of file diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java index 42165cae..ac6cbb79 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java @@ -1,5 +1,6 @@ package com.qreal.wmp.uitesting; +/** Describes WMP pages in browser. */ public enum Page { Auth("auth"), Dashboard("dashboard"), EditorRobots("robotsEditor"), EditorBPMN("bpmnEditor"); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java index 09525feb..2c2ef241 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** Returns page instance for requested uri. */ public class PageFactory { private static final Logger logger = LoggerFactory.getLogger(PageFactory.class); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java index ca218ab9..cfdb53e7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java @@ -4,6 +4,10 @@ import com.qreal.wmp.uitesting.services.Auther; import com.qreal.wmp.uitesting.services.Opener; +/** Loads page. + * It means, firstly, it opens uri by Opener service. + * Secondly, it returns page by PageFactory. + * */ public class PageLoader { private final PageFactory pageFactory; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java index 8599d2e0..5632aa9a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/config/DevConfig.java @@ -38,7 +38,7 @@ public WebDriver webDriver() { ChromeDriverManager.getInstance().setup(); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); - driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS); WebDriverRunner.setWebDriver(driver); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java index b3ce553e..52e1b1dd 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java @@ -9,7 +9,7 @@ public interface Pallete { /** - * Chose element from Pallete. + * Chooses an element from Pallete. * * @param elementName name of block * @return block diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java index 6c724a5c..d438b888 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java @@ -2,6 +2,8 @@ import com.codeborne.selenide.SelenideElement; + +/** Describes pallete's items. */ public class PalleteElement { private final SelenideElement inner; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java index 79cf26d5..f0846d64 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java @@ -9,6 +9,7 @@ import static com.codeborne.selenide.Selectors.withText; import static com.codeborne.selenide.Selenide.$; +/** {@inheritDoc} */ public class PalleteImpl implements Pallete { private static final String SELECTOR = "#palette-tab-content"; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java index ab23dbae..3307b0ca 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java @@ -3,7 +3,8 @@ import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.NoSuchElementException; -/** Describe Property Editor. */ +/** Describe Property Editor. + * When block is clicked, it could be configured by Property Editor. */ public interface PropertyEditor { /** Set property of element which on the focus. */ void setProperty(SelenideElement element, String propertyName, String propertyValue) throws NoSuchElementException; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java index 5c70f9be..1200616e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java @@ -13,6 +13,7 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; +/** {@inheritDoc} */ public class PropertyEditorImpl implements PropertyEditor { private static final String SELECTOR = "#property_table"; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java index cf19d42a..dc6b8de9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java @@ -5,6 +5,9 @@ import java.util.Optional; +/** Describes element's position on the Scene. + * Contains absolute coordinates of scene, which are written in 'transform' tag on the html representation. + * Also contains cell's position (the Scene is represented by a mesh of cells)*/ public class Coordinate { public static final String SELECTOR = "transform"; @@ -18,7 +21,7 @@ public class Coordinate { /** Returns coordinate of object on scene. */ @NotNull public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { - final String position = element.attr("transform"); + final String position = element.attr(SELECTOR); final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); return Optional.of( new Coordinate( diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java index 1bbbd00a..bf5008fb 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -13,10 +13,10 @@ public interface Scene { Block dragAndDrop(PalleteElement palleteElement); /** Drag element from scene or pallete and put it in cell of the scene. */ - Block dragAndDrop(PalleteElement element, int cell_x, int cell_y); + Block dragAndDrop(PalleteElement element, int cellX, int cellY); /** Move element from scene to the cell. */ - void moveToCell(Block block, int cell_x, int cell_y); + void moveToCell(Block block, int cellX, int cellY); /** Check if element exist on the scene. */ boolean exist(SceneElement element); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 70f7e4c2..03ceb95a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -55,7 +55,7 @@ private SceneImpl(WebDriver webDriver) { ); } sceneWindow = SceneWindowImpl.getSceneWindow(webDriver); - blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR); + blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR, this); linkProvider = LinkProvider.getLinkProvider(SELECTOR, webDriver); } @@ -66,15 +66,15 @@ public Block dragAndDrop(final PalleteElement element) { } @Override - public Block dragAndDrop(final PalleteElement element, int cell_x, int cell_y) { + public Block dragAndDrop(final PalleteElement element, int cellX, int cellY) { Block newBlock = dragAndDrop(element); - blockProvider.moveToCell(newBlock, cell_x, cell_y); + blockProvider.moveToCell(newBlock, cellX, cellY); return newBlock; } @Override - public void moveToCell(Block block, final int cell_x, final int cell_y) { - blockProvider.moveToCell(block, cell_x, cell_y); + public void moveToCell(Block block, int cellX, int cellY) { + blockProvider.moveToCell(block, cellX, cellY); } @SuppressWarnings("SimplifiableIfStatement") @@ -114,7 +114,7 @@ public void clean() { try { remove(linkProvider.getLinks().get(0)); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It's impossible to remove link, because it is not on the Scene."); } clean(); } else { @@ -122,7 +122,7 @@ public void clean() { try { remove(blockProvider.getBlocks().get(0)); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It's impossible to remove block, because it is not on the scene."); } clean(); } else { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java index def9e525..a94ff39d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java @@ -1,9 +1,12 @@ package com.qreal.wmp.uitesting.dia.scene.elements; +import com.qreal.wmp.uitesting.dia.scene.Scene; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.$; +/** Describes item, which is placed on the scene. + * Pallete have items. If we dragAndDrop these items to the Scene, we'll get Blocks. */ public class Block extends SceneElementImpl { public static final String CLASS_NAME = "element devs ImageWithPorts"; @@ -14,10 +17,13 @@ public class Block extends SceneElementImpl { private final SceneElement port; - public Block(String name, By by) { - super(by); + private final Scene scene; + + public Block(String name, By selector, Scene scene) { + super(selector); this.name = name; - this.port = new SceneElementImpl(By.id($(by).find(By.className(PORT_CLASS_NAME)).attr("id"))); + this.port = new SceneElementImpl(By.id($(selector).find(By.className(PORT_CLASS_NAME)).attr("id"))); + this.scene = scene; } public String getName() { @@ -27,4 +33,8 @@ public String getName() { public SceneElement getPort() { return port; } + + public void moveToCell(int cellX, int cellY) { + scene.moveToCell(this, cellX, cellY); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java index 6da6e550..6872a66d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java @@ -7,6 +7,7 @@ import static com.codeborne.selenide.Selenide.$; +/** Link describes relations between blocks. */ public class Link extends SceneElementImpl { public static final String CLASS_NAME = "link"; @@ -20,12 +21,12 @@ public class Link extends SceneElementImpl { private final SceneElement target; /** Describes link between two blocks. */ - public Link(String name, By by) { - super(by); + public Link(String name, By selector) { + super(selector); this.name = name; - SelenideElement source = $(by).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(1)")); + SelenideElement source = $(selector).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(1)")); this.source = new SceneElementImpl(By.id(source.attr("id"))); - SelenideElement target = $(by).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(2)")); + SelenideElement target = $(selector).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(2)")); this.target = new SceneElementImpl(By.id(target.attr("id"))); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java index fd0436cb..5203a26d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java @@ -7,21 +7,24 @@ import static com.codeborne.selenide.Selenide.$; +/** All Scene elements have selector by which we can clearly define their web instances. + * Also all scene elements have coordinates on the Scene. */ public class SceneElementImpl implements SceneElement { - private By by; + // Wrapper over an string selector. Used to search the element in HTML representation of current page. + private final By selector; - public SceneElementImpl(By by) { - this.by = by; + public SceneElementImpl(By selector) { + this.selector = selector; } /** Based on the Selenium element. */ public SelenideElement getInnerSeleniumElement() { - return $(by); + return $(selector); } public By getBy() { - return by; + return selector; } public Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java index e79e1b8a..d74ac86e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java @@ -2,6 +2,7 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.scene.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.window.SceneWindow; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; @@ -16,6 +17,7 @@ import static com.codeborne.selenide.Selenide.$$; +/** Encapsulates blocks operations. */ public class BlockProvider { private static final Logger logger = LoggerFactory.getLogger(BlockProvider.class); @@ -24,20 +26,23 @@ public class BlockProvider { private final String selector; + private final Scene scene; + private Set blocks = new HashSet<>(); - private BlockProvider(SceneWindow sceneWindow, String selector) { + private BlockProvider(SceneWindow sceneWindow, String selector, Scene scene) { this.sceneWindow = sceneWindow; this.selector = selector; + this.scene = scene; } /** Move element to cell with x and y coordinates. */ - public void moveToCell(final Block block, final int cell_x, final int cell_y) { - logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); + public void moveToCell(final Block block, final int cellX, final int cellY) { + logger.info("Move element {} to cell ({}, {})", block, cellX, cellY); try { - sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); + sceneWindow.move(block, new Coordinate(cellX * 25, cellY * 25)); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It is impossible to move element, which is not on the Scene"); } } @@ -49,7 +54,7 @@ public List getBlocks() { public Block getNewBlock() { final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); logger.info("Add element {} to scene", newEl); - Block block = new Block(newEl.attr("id"), By.id(newEl.attr("id"))); + Block block = new Block(newEl.attr("id"), By.id(newEl.attr("id")), scene); blocks.add(block); return block; } @@ -65,13 +70,13 @@ public boolean isEmpty() { public void recalculateBlocks() { blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream() .filter(x -> x.attr("class").contains(Block.CLASS_NAME)) - .map(x -> new Block(x.attr("id"), By.id(x.attr("id")))) + .map(x -> new Block(x.attr("id"), By.id(x.attr("id")), scene)) .collect(Collectors.toSet()); } - @Contract("_, _ -> !null") - public static BlockProvider getBlockProvider(SceneWindow sceneWindow, String selector) { - return new BlockProvider(sceneWindow, selector); + @Contract("_, _, _ -> !null") + public static BlockProvider getBlockProvider(SceneWindow sceneWindow, String selector, Scene scene) { + return new BlockProvider(sceneWindow, selector, scene); } /** Return new element of the scene. */ diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java index e82240f4..8e193643 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java @@ -16,6 +16,7 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; +/** Encapsulates links operations. */ public class LinkProvider { private static final Logger logger = LoggerFactory.getLogger(LinkProvider.class); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 76554a7e..3e8e79e7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -47,26 +47,32 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn Actions actions = new Actions(driver); actions.clickAndHold(element.getInnerSeleniumElement()); - if (Math.abs(dist.getXAbsolute() - element.getCoordinateOnScene().getXAbsolute()) < sizeHor / 2 - && Math.abs(dist.getYAbsolute() - element.getCoordinateOnScene().getYAbsolute()) < sizeVer / 2) { + if (isDistanceLessThenBarrier( + dist, + element.getCoordinateOnScene(), + new OffsetObject(sizeHor / 2, sizeVer / 2))) { + jump(actions, element, dist); } else { - Predicate condX = x -> Math.abs(x.getXAbsolute() - dist.getXAbsolute()) <= sizeHor / 3; + java.util.function.Predicate condX = x -> + isDistanceLessThenBarrier(x.getXAbsolute(), dist.getXAbsolute(), sizeHor / 3); + if (src.getXAbsolute() < dist.getXAbsolute()) { - movement(actions, element, new OffsetObject(sizeHor / 4, 0), condX); + innerMove(actions, element, new OffsetObject(sizeHor / 4, 0), condX); } else { - movement(actions, element, new OffsetObject(-sizeHor / 4, 0), condX); + innerMove(actions, element, new OffsetObject(-sizeHor / 4, 0), condX); } } if (Math.abs(dist.getXAbsolute() - element.getCoordinateOnScene().getXAbsolute()) < sizeHor / 2 && Math.abs(dist.getYAbsolute() - element.getCoordinateOnScene().getYAbsolute()) < sizeVer / 2) { jump(actions, element, dist); } else { - Predicate condY = x -> Math.abs(x.getYAbsolute() - dist.getYAbsolute()) <= sizeVer / 3; + java.util.function.Predicate condY = x -> + isDistanceLessThenBarrier(x.getYAbsolute(), dist.getYAbsolute(), sizeVer / 3); if (src.getYAbsolute() < dist.getYAbsolute()) { - movement(actions, element, new OffsetObject(0, sizeVer / 4), condY); + innerMove(actions, element, new OffsetObject(0, sizeVer / 4), condY); } else { - movement(actions, element, new OffsetObject(0, -sizeVer / 4), condY); + innerMove(actions, element, new OffsetObject(0, -sizeVer / 4), condY); } } @@ -77,7 +83,7 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn try { return element.getCoordinateOnScene().equals(dist); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It is impossible to move element, which is not on the Scene"); } return false; }); @@ -119,7 +125,9 @@ private void updateCanvasInfo() { } } - private void movement(Actions actions, SceneElement element, OffsetObject offset, Predicate cond) { + private void innerMove(Actions actions, SceneElement element, + OffsetObject offset, java.util.function.Predicate cond) { + (new WebDriverWait(driver, 40)) .until((Predicate) webDriver -> { try { @@ -139,9 +147,9 @@ private void movement(Actions actions, SceneElement element, OffsetObject offset offset.offsetY = signY * random.nextInt(Math.abs(offset.offsetY)); } } - return cond.apply(element.getCoordinateOnScene()); + return cond.test(element.getCoordinateOnScene()); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It is impossible to move element, which is not on the Scene"); } return false; }); @@ -167,4 +175,13 @@ private class OffsetObject { this.offsetY = offsetY; } } + + private boolean isDistanceLessThenBarrier(double fst, double snd, double barrier) { + return Math.abs(fst - snd) <= barrier; + } + + private boolean isDistanceLessThenBarrier(Coordinate fst, Coordinate snd, OffsetObject barrier) { + return isDistanceLessThenBarrier(fst.getXAbsolute(), snd.getXAbsolute(), barrier.offsetX) && + isDistanceLessThenBarrier(fst.getYAbsolute(), snd.getYAbsolute(), barrier.offsetY); + } } \ No newline at end of file diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java index c264ebbc..53197584 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java @@ -3,7 +3,7 @@ public class ElementNotOnTheSceneException extends Exception { public ElementNotOnTheSceneException() { - super("It is impossible to get Coordinate of element, which is not on the Scene"); + super("It is impossible to get Coordinates of element, which is not on the Scene"); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java index f068daf9..656f42de 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java @@ -1,4 +1,5 @@ package com.qreal.wmp.uitesting.pages; +/** Describes Authorization page of the WMP project. */ public class AuthPage { } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java index cd87621b..bc24f6f3 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java @@ -1,4 +1,5 @@ package com.qreal.wmp.uitesting.pages; +/** Describes Dashboard page of the WMP project. */ public class DashboardPage { } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java index 680cd697..8af803b4 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java @@ -4,6 +4,9 @@ import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; +/** Describes Editor page of the WMP project. + * Includes such components as Scene, Pallete and PropertyEditor. + */ public class EditorPage { private final Scene scene; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java index f1d3529f..382c52bf 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java @@ -11,6 +11,7 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.open; +/** {@inheritDoc} */ public class AutherImpl implements Auther { /** Use properties from pages.properies file. */ diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java index f93fcd15..a5ebf771 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java @@ -11,6 +11,7 @@ import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; +/** {@inheritDoc} */ public class OpenerImpl implements Opener { /** Uses properties from pages.properies file. */ diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java similarity index 94% rename from ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java rename to ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java index 295c31fa..bc651933 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java @@ -25,9 +25,9 @@ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class DiaTest { +public class ManipulatingDiagramTest { - private static final Logger logger = LoggerFactory.getLogger(DiaTest.class); + private static final Logger logger = LoggerFactory.getLogger(ManipulatingDiagramTest.class); @Autowired private PageLoader pageLoader; @@ -75,7 +75,7 @@ public void addLink() { final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward"), 4, 7); Link link = scene.addLink(initNode, motor); Link link2 = scene.addLink(motor, finalNode); - scene.moveToCell(motor, 72, 64); + motor.moveToCell(72, 64); assert scene.exist(link); assert scene.exist(link2); } @@ -93,11 +93,11 @@ public void propertyEditor() { public void moveElement() { final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); try { - scene.moveToCell(motor, 40, 40); + motor.moveToCell(40, 40); assert motor.getCoordinateOnScene().getXCell() == 40 && motor.getCoordinateOnScene().getYCell() == 40; - scene.moveToCell(motor, 72, 64); + motor.moveToCell(72, 64); assert motor.getCoordinateOnScene().getXCell() == 72 && motor.getCoordinateOnScene().getYCell() == 64; - scene.moveToCell(motor, 0, 0); + motor.moveToCell(0, 0); assert motor.getCoordinateOnScene().getXCell() == 0 && motor.getCoordinateOnScene().getYCell() == 0; } catch (ElementNotOnTheSceneException e) { logger.error(e.getMessage()); diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 49a4e318..2729a36e 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -66,9 +66,9 @@ public void digramFiveNodes() { @Test public void moveSomeNodes() { - scene.moveToCell(elements.get(1), 20, 20); - scene.moveToCell(elements.get(0), 20, 10); - scene.moveToCell(elements.get(1), 0, 20); + elements.get(1).moveToCell(20, 20); + elements.get(0).moveToCell(20, 10); + elements.get(1).moveToCell(0, 20); assert allExist(); } diff --git a/ui-testing/ui-testing.iml b/ui-testing/ui-testing.iml index 9aa516a1..4c9c646c 100644 --- a/ui-testing/ui-testing.iml +++ b/ui-testing/ui-testing.iml @@ -21,6 +21,7 @@ + From bb65fb9c04372b6b3d816a95c32e54ca58543939 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Wed, 22 Mar 2017 00:45:32 +0300 Subject: [PATCH 39/40] Merge branch 'master' into diagram-gui # Conflicts: # editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts # ui-testing/ui-testing.iml --- .../editorCore/controller/SceneController.ts | 35 +++---- .../app/core/editorCore/model/Scroller.ts | 4 +- .../dia/scene/window/SceneWindowImpl.java | 2 +- ui-testing/ui-testing.iml | 96 +++++++++++-------- 4 files changed, 78 insertions(+), 59 deletions(-) diff --git a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts index 40e4c2cd..f1f9a098 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts @@ -10,6 +10,7 @@ import {DiagramElement} from "../model/DiagramElement"; import {SubprogramNode} from "../model/SubprogramNode"; import {Property} from "../model/Property"; import {NodeType} from "../model/NodeType"; +import {Scroller, Direction} from "../model/Scroller"; import {DiagramElementListener} from "./DiagramElementListener"; import {SceneCommandFactory} from "../model/commands/SceneCommandFactory"; import {DiagramEditorController} from "./DiagramEditorController"; @@ -461,38 +462,38 @@ export class SceneController { this.borderUnCrossed(); if (event.pageX + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.right) { this.scroller.setDirection(Direction.Right); - this.borderCrossed(node, event); + this.borderCrossed(node, event, cellView); } else if (event.pageX - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.left) { this.scroller.setDirection(Direction.Left); - this.borderCrossed(node, event); + this.borderCrossed(node, event, cellView); } else if (event.pageY + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.bottom) { this.scroller.setDirection(Direction.Down); - this.borderCrossed(node, event); + this.borderCrossed(node, event, cellView); } else if (event.pageY - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.top) { this.scroller.setDirection(Direction.Up); - this.borderCrossed(node, event); + this.borderCrossed(node, event, cellView); } this.updateLastCellScrollPosition(event); } - private borderCrossed(node: DiagramNode, event): void { + private borderCrossed(node: DiagramNode, event, view): void { this.scroller.setScroll(true); var that = this; switch (this.scroller.getDirection()) { case Direction.Right: { - this.scroller.setIntervalId(setInterval(() => that.scrollRight(node, event), 150)); + this.scroller.setIntervalId(setInterval(() => that.scrollRight(node, event, view), 150)); break; } case Direction.Left: { - this.scroller.setIntervalId(setInterval(() => that.scrollLeft(node, event), 150)); + this.scroller.setIntervalId(setInterval(() => that.scrollLeft(node, event, view), 150)); break; } case Direction.Down: { - this.scroller.setIntervalId(setInterval(() => that.scrollBottom(node, event), 150)); + this.scroller.setIntervalId(setInterval(() => that.scrollBottom(node, event, view), 150)); break; } case Direction.Up: { - this.scroller.setIntervalId(setInterval(() => that.scrollTop(node, event), 150)); + this.scroller.setIntervalId(setInterval(() => that.scrollTop(node, event, view), 150)); break; } } @@ -507,36 +508,36 @@ export class SceneController { } } - private scrollRight(node: DiagramNode, event) : void { + private scrollRight(node: DiagramNode, event, view) : void { var sceneWrapper : HTMLDivElement = ( $(".scene-wrapper")[0]); sceneWrapper.scrollLeft += this.scene.getGridSize() * this.scene.getZoom(); if (node.getX() + 3 * this.scene.getGridSize() <= DiagramScene.WIDTH) { this.updateLastCellScrollPosition(event); - node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom(), view); } } - private scrollLeft(node: DiagramNode, event) : void { + private scrollLeft(node: DiagramNode, event, view) : void { ( $(".scene-wrapper")[0]).scrollLeft -= this.scene.getGridSize() * this.scene.getZoom(); if (node.getX() >= this.scene.getGridSize()) { this.updateLastCellScrollPosition(event); - node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom(), view); } } - private scrollBottom(node: DiagramNode, event) : void { + private scrollBottom(node: DiagramNode, event, view) : void { ( $(".scene-wrapper")[0]).scrollTop += this.scene.getGridSize() * this.scene.getZoom(); if (node.getY() + 3 * this.scene.getGridSize() <= DiagramScene.HEIGHT) { this.updateLastCellScrollPosition(event); - node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom(), view); } } - private scrollTop(node: DiagramNode, event) : void { + private scrollTop(node: DiagramNode, event, view) : void { ( $(".scene-wrapper")[0]).scrollTop -= this.scene.getGridSize() * this.scene.getZoom(); if (node.getY() >= this.scene.getGridSize()) { this.updateLastCellScrollPosition(event); - node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom()); + node.setPosition(this.lastCellScrollPosition.x, this.lastCellScrollPosition.y, this.scene.getZoom(), view); } } diff --git a/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts index c6540611..f19bc18a 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts @@ -1,8 +1,8 @@ -enum Direction { +export enum Direction { Up, Down, Left, Right, None } -class Scroller { +export class Scroller { private scroll: boolean; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 3e8e79e7..adee0086 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -78,7 +78,7 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn jump(actions, element, dist); - (new WebDriverWait(driver, 20)) + (new WebDriverWait(driver, 40)) .until((Predicate) webDriver -> { try { return element.getCoordinateOnScene().equals(dist); diff --git a/ui-testing/ui-testing.iml b/ui-testing/ui-testing.iml index fe03b019..62ae7fcf 100644 --- a/ui-testing/ui-testing.iml +++ b/ui-testing/ui-testing.iml @@ -1,5 +1,5 @@ - + @@ -12,52 +12,70 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2995bc21b6de63578ad8337fd9c20aa5eb56064e Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Thu, 27 Apr 2017 16:27:41 +0300 Subject: [PATCH 40/40] Code refactor --- .travis.yml | 3 +- .../java/com/qreal/wmp/uitesting/Page.java | 39 ++++++++++++++++--- .../com/qreal/wmp/uitesting/PageFactory.java | 4 +- .../com/qreal/wmp/uitesting/PageLoader.java | 18 +++------ .../Pallete.java => palette/Palette.java} | 10 ++--- .../uitesting/dia/palette/PaletteElement.java | 25 ++++++++++++ .../PaletteImpl.java} | 14 +++---- .../uitesting/dia/pallete/PalleteElement.java | 25 ------------ .../dia/property/PropertyEditor.java | 6 ++- .../wmp/uitesting/dia/scene/Coordinate.java | 6 ++- .../qreal/wmp/uitesting/dia/scene/Scene.java | 10 ++--- .../wmp/uitesting/dia/scene/SceneImpl.java | 15 ++++--- .../uitesting/dia/scene/elements/Block.java | 6 ++- .../dia/scene/elements/SceneElementImpl.java | 6 ++- .../dia/scene/providers/BlockProvider.java | 3 +- .../qreal/wmp/uitesting/pages/EditorPage.java | 14 +++---- .../qreal/wmp/uitesting/services/Auther.java | 2 +- .../wmp/uitesting/innertests/AuthTest.java | 20 +++++++--- .../innertests/ManipulatingDiagramTest.java | 22 +++++------ .../testspace/DiagramConstructingTest.java | 14 +++---- 20 files changed, 150 insertions(+), 112 deletions(-) rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{pallete/Pallete.java => palette/Palette.java} (50%) create mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/PaletteElement.java rename ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/{pallete/PalleteImpl.java => palette/PaletteImpl.java} (68%) delete mode 100644 ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java diff --git a/.travis.yml b/.travis.yml index b60f5b0d..466ae517 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,8 +68,7 @@ script: - sleep 30 - cd ../ui-testing - - mvn test -P travis & - - sleep 1000 + - mvn test -P travis notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java index ac6cbb79..834358bd 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java @@ -1,16 +1,43 @@ package com.qreal.wmp.uitesting; /** Describes WMP pages in browser. */ +@SuppressWarnings("unchecked") public enum Page { - Auth("auth"), Dashboard("dashboard"), EditorRobots("robotsEditor"), EditorBPMN("bpmnEditor"); - private String identify; + Auth("auth") { + @Override + public T getInstance(PageFactory pageFactory) { + return (T) pageFactory.getAuthPage(); + } + }, + Dashboard("dashboard") { + @Override + public T getInstance(PageFactory pageFactory) { + return (T) pageFactory.getDashboardPage(); + } + }, + EditorRobots("robotsEditor") { + @Override + public T getInstance(PageFactory pageFactory) { + return (T) pageFactory.getEditorPage(); + } + }, + EditorBPMN("bpmnEditor") { + @Override + public T getInstance(PageFactory pageFactory) { + return (T) pageFactory.getEditorPage(); + } + }; - Page(String identify) { - this.identify = identify; + private String name; + + Page(String name) { + this.name = name; } - public String getIdentify() { - return identify; + public String getName() { + return name; } + + public abstract T getInstance(PageFactory pageFactory); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java index 2c2ef241..fcf2381c 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java @@ -1,6 +1,6 @@ package com.qreal.wmp.uitesting; -import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; +import com.qreal.wmp.uitesting.dia.palette.PaletteImpl; import com.qreal.wmp.uitesting.dia.property.PropertyEditorImpl; import com.qreal.wmp.uitesting.dia.scene.SceneImpl; import com.qreal.wmp.uitesting.pages.AuthPage; @@ -26,7 +26,7 @@ public EditorPage getEditorPage() { logger.info("Editor page was created"); return new EditorPage( SceneImpl.getScene(webDriver), - PalleteImpl.getPallete(), + PaletteImpl.getPalette(), PropertyEditorImpl.getPropertyEditor() ); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java index cfdb53e7..eb94332e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java @@ -4,10 +4,11 @@ import com.qreal.wmp.uitesting.services.Auther; import com.qreal.wmp.uitesting.services.Opener; -/** Loads page. +/** + * Loads page. * It means, firstly, it opens uri by Opener service. * Secondly, it returns page by PageFactory. - * */ + */ public class PageLoader { private final PageFactory pageFactory; @@ -24,25 +25,18 @@ public PageLoader(PageFactory pageFactory, Opener opener, Auther auther) { /** Loads and returns requested page with default authentication. */ public T load(Page page) { - opener.open(page.getIdentify()); + opener.open(page.getName()); return getPage(page); } /** Loads and returns requested page with login and password. */ public T load(Page page, String username, String password) throws WrongAuthException { auther.auth(username, password); - opener.open(page.getIdentify()); + opener.open(page.getName()); return getPage(page); } - @SuppressWarnings("unchecked") private T getPage(Page page) { - switch (page) { - case Auth: return (T) pageFactory.getAuthPage(); - case Dashboard: return (T) pageFactory.getDashboardPage(); - case EditorBPMN: return (T) pageFactory.getEditorPage(); - case EditorRobots: return (T) pageFactory.getEditorPage(); - default: return null; - } + return page.getInstance(pageFactory); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/Palette.java similarity index 50% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/Palette.java index 52e1b1dd..111c0f43 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/Palette.java @@ -1,18 +1,18 @@ -package com.qreal.wmp.uitesting.dia.pallete; +package com.qreal.wmp.uitesting.dia.palette; import org.openqa.selenium.NoSuchElementException; /** - * Describes Pallete. + * Describes Palette. * For any manipulating with it. */ -public interface Pallete { +public interface Palette { /** - * Chooses an element from Pallete. + * Chooses an element from Palette. * * @param elementName name of block * @return block */ - PalleteElement getElement(String elementName) throws NoSuchElementException; + PaletteElement getElement(String elementName) throws NoSuchElementException; } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/PaletteElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/PaletteElement.java new file mode 100644 index 00000000..6ae9e640 --- /dev/null +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/PaletteElement.java @@ -0,0 +1,25 @@ +package com.qreal.wmp.uitesting.dia.palette; + +import com.codeborne.selenide.SelenideElement; + + +/** Describes palette's items. */ +public class PaletteElement { + + private final SelenideElement innerSeleniumELement; + + private final String name; + + public PaletteElement(SelenideElement innerSeleniumELement) { + this.innerSeleniumELement = innerSeleniumELement; + name = innerSeleniumELement.attr("data-type"); + } + + public SelenideElement getInnerSeleniumELement() { + return innerSeleniumELement; + } + + public String getName() { + return name; + } +} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/PaletteImpl.java similarity index 68% rename from ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java rename to ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/PaletteImpl.java index f0846d64..8f3d1ef3 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/palette/PaletteImpl.java @@ -1,4 +1,4 @@ -package com.qreal.wmp.uitesting.dia.pallete; +package com.qreal.wmp.uitesting.dia.palette; import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.By; @@ -10,19 +10,19 @@ import static com.codeborne.selenide.Selenide.$; /** {@inheritDoc} */ -public class PalleteImpl implements Pallete { +public class PaletteImpl implements Palette { private static final String SELECTOR = "#palette-tab-content"; - private static final Logger logger = LoggerFactory.getLogger(PalleteImpl.class); + private static final Logger logger = LoggerFactory.getLogger(PaletteImpl.class); - public PalleteElement getElement(final String elementName) throws NoSuchElementException { + public PaletteElement getElement(final String elementName) throws NoSuchElementException { final SelenideElement element = $(By.cssSelector(SELECTOR)).find(withText(elementName)); logger.info("Get element {} from Palette", element); - return new PalleteElement(element); + return new PaletteElement(element); } - public static Pallete getPallete() { - return new PalleteImpl(); + public static Palette getPalette() { + return new PaletteImpl(); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java deleted file mode 100644 index d438b888..00000000 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.qreal.wmp.uitesting.dia.pallete; - -import com.codeborne.selenide.SelenideElement; - - -/** Describes pallete's items. */ -public class PalleteElement { - - private final SelenideElement inner; - - private final String name; - - public PalleteElement(SelenideElement inner) { - this.inner = inner; - name = inner.attr("data-type"); - } - - public SelenideElement getInner() { - return inner; - } - - public String getName() { - return name; - } -} diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java index 3307b0ca..1d96ef40 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java @@ -3,8 +3,10 @@ import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.NoSuchElementException; -/** Describe Property Editor. - * When block is clicked, it could be configured by Property Editor. */ +/** + * Describe Property Editor. + * When block is clicked, it could be configured by Property Editor. + */ public interface PropertyEditor { /** Set property of element which on the focus. */ void setProperty(SelenideElement element, String propertyName, String propertyValue) throws NoSuchElementException; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java index dc6b8de9..d6d08559 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java @@ -5,9 +5,11 @@ import java.util.Optional; -/** Describes element's position on the Scene. +/** + * Describes element's position on the Scene. * Contains absolute coordinates of scene, which are written in 'transform' tag on the html representation. - * Also contains cell's position (the Scene is represented by a mesh of cells)*/ + * Also contains cell's position (the Scene is represented by a mesh of cells) + */ public class Coordinate { public static final String SELECTOR = "transform"; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java index bf5008fb..778dfe85 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -1,6 +1,6 @@ package com.qreal.wmp.uitesting.dia.scene; -import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; +import com.qreal.wmp.uitesting.dia.palette.PaletteElement; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; @@ -9,11 +9,11 @@ import java.util.List; public interface Scene { - /** Drag element from scene or pallete and put it on the center of scene. */ - Block dragAndDrop(PalleteElement palleteElement); + /** Drag element from scene or palette and put it on the center of scene. */ + Block dragAndDrop(PaletteElement paletteElement); - /** Drag element from scene or pallete and put it in cell of the scene. */ - Block dragAndDrop(PalleteElement element, int cellX, int cellY); + /** Drag element from scene or palette and put it in cell of the scene. */ + Block dragAndDrop(PaletteElement element, int cellX, int cellY); /** Move element from scene to the cell. */ void moveToCell(Block block, int cellX, int cellY); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 03ceb95a..e8361775 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -3,8 +3,8 @@ import com.codeborne.selenide.Condition; import com.codeborne.selenide.SelenideElement; import com.google.common.base.Predicate; -import com.qreal.wmp.uitesting.dia.pallete.PalleteElement; -import com.qreal.wmp.uitesting.dia.pallete.PalleteImpl; +import com.qreal.wmp.uitesting.dia.palette.PaletteElement; +import com.qreal.wmp.uitesting.dia.palette.PaletteImpl; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.elements.Link; import com.qreal.wmp.uitesting.dia.scene.elements.SceneElement; @@ -28,13 +28,13 @@ /** * Describes Scene of Editor. - * Can add rm and manipulate with objects on that area. + * Can add, rm and manipulate with objects on that area. */ public class SceneImpl implements Scene { private static final String SELECTOR = ".scene-wrapper"; - private static final Logger logger = LoggerFactory.getLogger(PalleteImpl.class); + private static final Logger logger = LoggerFactory.getLogger(PaletteImpl.class); private final WebDriver webDriver; @@ -47,7 +47,6 @@ public class SceneImpl implements Scene { /** For actions such as mouse move we need driver of current page. */ private SceneImpl(WebDriver webDriver) { this.webDriver = webDriver; - // For actions such as mouse move we need driver of current page. if (webDriver instanceof JavascriptExecutor) { ((JavascriptExecutor) webDriver).executeScript( createDiv("SceneWindowLeft") + createDiv("SceneWindowTop") + @@ -60,13 +59,13 @@ private SceneImpl(WebDriver webDriver) { } @Override - public Block dragAndDrop(final PalleteElement element) { - element.getInner().dragAndDropTo(SELECTOR); + public Block dragAndDrop(final PaletteElement element) { + element.getInnerSeleniumELement().dragAndDropTo(SELECTOR); return blockProvider.getNewBlock(); } @Override - public Block dragAndDrop(final PalleteElement element, int cellX, int cellY) { + public Block dragAndDrop(final PaletteElement element, int cellX, int cellY) { Block newBlock = dragAndDrop(element); blockProvider.moveToCell(newBlock, cellX, cellY); return newBlock; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java index a94ff39d..0b593b86 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java @@ -5,8 +5,10 @@ import static com.codeborne.selenide.Selenide.$; -/** Describes item, which is placed on the scene. - * Pallete have items. If we dragAndDrop these items to the Scene, we'll get Blocks. */ +/** + * Describes item, which is placed on the scene. + * Palette have items. If we dragAndDrop these items to the Scene, we'll get Blocks. + */ public class Block extends SceneElementImpl { public static final String CLASS_NAME = "element devs ImageWithPorts"; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java index 5203a26d..7d0d99d4 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java @@ -7,8 +7,10 @@ import static com.codeborne.selenide.Selenide.$; -/** All Scene elements have selector by which we can clearly define their web instances. - * Also all scene elements have coordinates on the Scene. */ +/** + * All Scene elements have selector by which we can clearly define their web instances. + * Also all scene elements have coordinates on the Scene. + */ public class SceneElementImpl implements SceneElement { // Wrapper over an string selector. Used to search the element in HTML representation of current page. diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java index d74ac86e..c098da99 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java @@ -40,7 +40,8 @@ private BlockProvider(SceneWindow sceneWindow, String selector, Scene scene) { public void moveToCell(final Block block, final int cellX, final int cellY) { logger.info("Move element {} to cell ({}, {})", block, cellX, cellY); try { - sceneWindow.move(block, new Coordinate(cellX * 25, cellY * 25)); + sceneWindow.move(block, + new Coordinate(cellX * Coordinate.POINT_IN_CELL, cellY * Coordinate.POINT_IN_CELL)); } catch (ElementNotOnTheSceneException e) { logger.error("It is impossible to move element, which is not on the Scene"); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java index 8af803b4..e3422a40 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java @@ -1,23 +1,23 @@ package com.qreal.wmp.uitesting.pages; -import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.palette.Palette; import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; /** Describes Editor page of the WMP project. - * Includes such components as Scene, Pallete and PropertyEditor. + * Includes such components as Scene, Palette and PropertyEditor. */ public class EditorPage { private final Scene scene; - private final Pallete pallete; + private final Palette palette; private final PropertyEditor propertyEditor; - public EditorPage(Scene scene, Pallete pallete, PropertyEditor propertyEditor) { + public EditorPage(Scene scene, Palette palette, PropertyEditor propertyEditor) { this.scene = scene; - this.pallete = pallete; + this.palette = palette; this.propertyEditor = propertyEditor; } @@ -25,8 +25,8 @@ public Scene getScene() { return scene; } - public Pallete getPallete() { - return pallete; + public Palette getPalette() { + return palette; } public PropertyEditor getPropertyEditor() { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java index ead0f7ab..99656a36 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/Auther.java @@ -5,7 +5,7 @@ /** Used for authentication in current browser session. */ public interface Auther { - /** Realizes authentication to the wmp. + /** Implements authentication to the wmp. * * @param username login * @param password password diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java index 6e402412..5759ade8 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/AuthTest.java @@ -23,12 +23,16 @@ @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class AuthTest { + private static final String WRONG_LOGIN = "lbltfn16vup5boj7o1ju"; + + private static final String WRONG_PASSWORD = "8epo7li9uq5vs3wujpm4"; + @Autowired private Auther auther; @Autowired private Opener opener; - + /** * Try to login with correct username and password. * Should redirect to OAuth page. @@ -53,11 +57,8 @@ public void authTest() { public void authWrongTest() { opener.cleanOpen("auth"); assert inAuthPage(); - final char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); - final String wrongLogin = RandomStringUtils.random(20, alphabet); - final String wrongPassword = RandomStringUtils.random(20, alphabet); try { - auther.auth(wrongLogin, wrongPassword); + auther.auth(WRONG_LOGIN, WRONG_PASSWORD); } catch (WrongAuthException e) { System.err.println(e.getMessage()); } @@ -111,4 +112,13 @@ public void bpmnEditorTest() { private boolean inAuthPage() { return $(byText("Sign in to continue to Auth")).exists(); } + + /** To generate random login and password. */ + public static void main(String[] args) { + final char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); + final String wrongLogin = RandomStringUtils.random(20, alphabet); + final String wrongPassword = RandomStringUtils.random(20, alphabet); + System.out.println(wrongLogin); + System.out.println(wrongPassword); + } } diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java index bc651933..407b2209 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java @@ -3,7 +3,7 @@ import com.qreal.wmp.uitesting.Page; import com.qreal.wmp.uitesting.PageLoader; import com.qreal.wmp.uitesting.config.AppInit; -import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.palette.Palette; import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; @@ -32,7 +32,7 @@ public class ManipulatingDiagramTest { @Autowired private PageLoader pageLoader; - private Pallete pallete; + private Palette palette; private Scene scene; @@ -43,21 +43,21 @@ public class ManipulatingDiagramTest { public void openEditor() { EditorPage editorPage = pageLoader.load(Page.EditorRobots); scene = editorPage.getScene(); - pallete = editorPage.getPallete(); + palette = editorPage.getPalette(); propertyEditor = editorPage.getPropertyEditor(); } - /** Drag element from pallete and drop on the scene. */ + /** Drag element from palette and drop on the scene. */ @Test public void dragAndDrop() { - final Block initialNode = scene.dragAndDrop(pallete.getElement("Initial Node")); + final Block initialNode = scene.dragAndDrop(palette.getElement("Initial Node")); assert scene.exist(initialNode); } /** Remove element from scene. */ @Test public void remove() { - final Block sceneElement = scene.dragAndDrop(pallete.getElement("Initial Node")); + final Block sceneElement = scene.dragAndDrop(palette.getElement("Initial Node")); assert scene.exist(sceneElement); try { scene.remove(sceneElement); @@ -70,9 +70,9 @@ public void remove() { /** Add two elements and link them. */ @Test public void addLink() { - final Block initNode = scene.dragAndDrop(pallete.getElement("Initial Node"), 4, 4); - final Block finalNode = scene.dragAndDrop(pallete.getElement("Final Node"), 4, 70); - final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward"), 4, 7); + final Block initNode = scene.dragAndDrop(palette.getElement("Initial Node"), 4, 4); + final Block finalNode = scene.dragAndDrop(palette.getElement("Final Node"), 4, 70); + final Block motor = scene.dragAndDrop(palette.getElement("Motors Forward"), 4, 7); Link link = scene.addLink(initNode, motor); Link link2 = scene.addLink(motor, finalNode); motor.moveToCell(72, 64); @@ -83,7 +83,7 @@ public void addLink() { /** Set property 'Ports' of motor forward item to '123' and checks that all is correct. */ @Test public void propertyEditor() { - final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); + final Block motor = scene.dragAndDrop(palette.getElement("Motors Forward")); propertyEditor.setProperty(motor.getInnerSeleniumElement(), "Ports", "123"); assert propertyEditor.getProperty(motor.getInnerSeleniumElement(), "Ports").equals("123"); } @@ -91,7 +91,7 @@ public void propertyEditor() { /** Move element to cell. */ @Test public void moveElement() { - final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); + final Block motor = scene.dragAndDrop(palette.getElement("Motors Forward")); try { motor.moveToCell(40, 40); assert motor.getCoordinateOnScene().getXCell() == 40 && motor.getCoordinateOnScene().getYCell() == 40; diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 2729a36e..cb68505a 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -3,7 +3,7 @@ import com.qreal.wmp.uitesting.Page; import com.qreal.wmp.uitesting.PageLoader; import com.qreal.wmp.uitesting.config.AppInit; -import com.qreal.wmp.uitesting.dia.pallete.Pallete; +import com.qreal.wmp.uitesting.dia.palette.Palette; import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; @@ -42,20 +42,20 @@ public class DiagramConstructingTest { public void openEditor() { EditorPage editorPage = pageLoader.load(Page.EditorRobots); scene = editorPage.getScene(); - Pallete pallete = editorPage.getPallete(); + Palette palette = editorPage.getPalette(); propertyEditor = editorPage.getPropertyEditor(); elements = new ArrayList<>(); links = new ArrayList<>(); - elements.add(scene.dragAndDrop(pallete.getElement("Initial Node"), 4, 4)); - elements.add(scene.dragAndDrop(pallete.getElement("Motors Forward"), 10, 4)); + elements.add(scene.dragAndDrop(palette.getElement("Initial Node"), 4, 4)); + elements.add(scene.dragAndDrop(palette.getElement("Motors Forward"), 10, 4)); links.add(scene.addLink(elements.get(0), elements.get(1))); - elements.add(scene.dragAndDrop(pallete.getElement("Painter Color"), 16, 4)); + elements.add(scene.dragAndDrop(palette.getElement("Painter Color"), 16, 4)); links.add(scene.addLink(elements.get(1), elements.get(2))); - elements.add(scene.dragAndDrop(pallete.getElement("Timer"), 22, 4)); + elements.add(scene.dragAndDrop(palette.getElement("Timer"), 22, 4)); links.add(scene.addLink(elements.get(2), elements.get(3))); - elements.add(scene.dragAndDrop(pallete.getElement("Final Node"), 28, 4)); + elements.add(scene.dragAndDrop(palette.getElement("Final Node"), 28, 4)); links.add(scene.addLink(elements.get(3), elements.get(4))); }