Projekt

Obecné

Profil

« Předchozí | Další » 

Revize af4bd766

Přidáno uživatelem Tomáš Šimandl před téměř 6 roky(ů)

Repaired Seleninum tests - DetailsTest

Zobrazit rozdíly:

sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/DetailsTest.java
7 7
import org.openqa.selenium.By;
8 8
import org.openqa.selenium.WebDriver;
9 9
import org.openqa.selenium.WebElement;
10
import org.openqa.selenium.interactions.Actions;
11

  
12
import java.util.Arrays;
13
import java.util.List;
14 10

  
15 11
public class DetailsTest {
16 12

  
17 13
    static WebDriver browser;
18 14

  
19
    public static final String VISIBLE_Q_TIP_XPATH = "//div[contains(@class, 'qtip') and @aria-hidden='false']";
20

  
21 15
    @BeforeAll
22 16
    public static void initTest() {
23 17
        SeleniumUtil.prepareConfigFile("emptyConfig.json");
......
27 21

  
28 22
    @Test
29 23
    public void vertexDetail(){
30
        checkQTip(
31
                vertexQTip("vertex1"),
32
                "V1 (3)",
33
                Arrays.asList("D: E", "B: W", "A: Q")
34
        );
35

  
36
        checkQTip(
37
                vertexQTip("vertex2"),
38
                "V2 (2)",
39
                Arrays.asList("D: E", "C: Q", "B: W")
40
        );
41

  
42
        checkQTip(
43
                vertexQTip("vertex3"),
44
                "V3 (1)",
45
                Arrays.asList("D: Q", "C: W", "A: E")
46
        );
24
        checkPopover(vertexPopover("V1"),"V1 (3)\nD: E\nB: W\nA: Q");
25

  
26
        checkPopover(vertexPopover("V2"),"V2 (2)\nD: E\nC: Q\nB: W");
27

  
28
        checkPopover(vertexPopover("V3"),"V3 (1)\nD: Q\nC: W\nA: E");
47 29
    }
48 30

  
49 31
    @Test
50 32
    public void edgeDetail() {
51
        checkQTip(
52
                edgeQTip("e1"),
53
                "Edge Details",
54
                Arrays.asList(
55
                        "edgeArchetype1", "D : E", "C : W"
56
                )
57
        );
58

  
59
        checkQTip(
60
                edgeQTip("e2"),
61
                "Edge Details",
62
                Arrays.asList(
63
                        "edgeArchetype1", "D : E", "B : W", "A : Q",
64
                        "edgeArchetype2", "D : D", "B : S", "A : A"
65
                )
66
        );
67

  
68
        checkQTip(
69
                edgeQTip("e3"),
70
                "Edge Details",
71
                Arrays.asList(
72
                        "edgeArchetype2", "C : T", "B : R"
73
                )
74
        );
75
    }
76

  
33
        checkPopover(edgePopover("1"),"Edge details\nedgeArchetype1\nD: E\nC: W");
77 34

  
78
    private WebElement edgeQTip(String edgeElementId) {
79
        WebElement arrow = browser.findElement(By.id(edgeElementId))
80
                .findElement(By.className("arrow"));
35
        checkPopover(edgePopover("2"),"Edge details\nedgeArchetype1\nD: E\nB: W\nA: Q\nedgeArchetype2\nD: D\nB: S\nA: A");
81 36

  
82
        return getQTipElement(arrow);
37
        checkPopover(edgePopover("3"),"Edge details\nedgeArchetype2\nC: T\nB: R");
83 38
    }
84 39

  
85
    private WebElement vertexQTip(String vertexElementId) {
86
        WebElement archetypeIcon = browser.findElement(By.id(vertexElementId))
87
                .findElement(By.className("archetype"));
88

  
89
        return getQTipElement(archetypeIcon);
90
    }
91 40

  
92
    private WebElement getQTipElement(WebElement toClick) {
93
        SeleniumUtil.svgClick(toClick);
41
    private WebElement edgePopover(String edgeId) {
42
        WebElement arrow = browser.findElement(By.cssSelector("[data-id='edges']"))
43
                .findElement(By.cssSelector("[data-id='" + edgeId + "']"))
44
                .findElement(By.className("arrow"));
94 45

  
95
        return browser.findElement(By.xpath(VISIBLE_Q_TIP_XPATH));
46
        SeleniumUtil.svgClick(arrow);
47
        return browser.findElement(By.className("edge-popover"));
96 48
    }
97 49

  
98
    private void checkQTip(WebElement qTipElement, String expectedTitle, List<String> expectedAttributes) {
99
        QTip qtip = new QTip(qTipElement);
100

  
101
        System.out.println("Title: " + qtip.getTitle());
102
        Assertions.assertEquals(expectedTitle, qtip.getTitle());
50
    private WebElement vertexPopover(String vertexElementName) {
51
        WebElement archetypeIcon = browser.findElement(By.cssSelector("[data-id='vertices']"))
52
                .findElement(By.cssSelector("[data-name='" + vertexElementName + "']"))
53
                .findElement(By.className("archetype-icon"));
103 54

  
104
        List<String> attributes = qtip.getAttributes();
105
        System.out.println("Attributes:");
106
        for (String attr : attributes) {
107
            System.out.println(attr);
108
        }
109
        Assertions.assertEquals(expectedAttributes, attributes);
55
        SeleniumUtil.svgClick(archetypeIcon);
56
        return browser.findElement(By.className("vertex-popover"));
57
    }
110 58

  
111
        qtip.close();
112
        Assertions.assertFalse(qtip.isVisible());
59
    private void checkPopover(WebElement popoverElement, String expectedText) {
60
        String text = popoverElement.getText();
61
        Assertions.assertEquals(expectedText, text);
113 62
    }
114 63

  
115 64
    @AfterAll
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/QTip.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.openqa.selenium.By;
4
import org.openqa.selenium.WebElement;
5

  
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
public class QTip {
10
    private WebElement qtip;
11

  
12
    public QTip(WebElement qtip) {
13
        this.qtip = qtip;
14
    }
15

  
16
    public boolean isVisible() {
17
        return qtip.isDisplayed();
18
    }
19

  
20
    public String getTitle() {
21
        return qtip.findElement(By.className("qtip-title")).getText();
22
    }
23

  
24
    public List<String> getAttributes() {
25
        List<WebElement> attributes = qtip.findElements(By.tagName("li"));
26
        List<String> result = new ArrayList<String>();
27

  
28
        for (WebElement attribute : attributes) {
29
            result.add(attribute.getText());
30
        }
31

  
32
        return result;
33
    }
34

  
35
    public void close() {
36
        qtip.findElement(By.className("qtip-close")).click();
37
    }
38
}

Také k dispozici: Unified diff