Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8f452e2f

Přidáno uživatelem Pavel Fidranský před asi 6 roky(ů)

added Selenium-based UI tests created as part of the ASWI project

Zobrazit rozdíly:

sources/src/test/java/cz/zcu/kiv/imiger/tests/backend/GraphFilterTest.java
1
package cz.zcu.kiv.imiger.tests.backend;
2

  
3
import cz.zcu.kiv.offscreen.api.EdgeInterface;
4
import cz.zcu.kiv.offscreen.api.GraphInterface;
5
import cz.zcu.kiv.offscreen.graph.EdgeImpl;
6
import cz.zcu.kiv.offscreen.graph.GraphManager;
7
import cz.zcu.kiv.offscreen.graph.SubedgeInfo;
8
import cz.zcu.kiv.offscreen.graph.loader.GraphJSONDataLoader;
9
import cz.zcu.kiv.offscreen.graph.loader.JSONConfigLoader;
10
import org.junit.jupiter.api.Assertions;
11
import org.junit.jupiter.api.BeforeAll;
12
import org.junit.jupiter.api.Test;
13

  
14
import java.io.File;
15
import java.io.IOException;
16
import java.util.ArrayList;
17
import java.util.List;
18

  
19
public class GraphFilterTest {
20

  
21
    private static String testDirectory;
22

  
23
    private static GraphManager graphManager;
24

  
25
    @BeforeAll
26
    static void initTest() {
27
        testDirectory = System.getProperty("user.dir") + "\\..\\test";
28

  
29
        File graphFile = new File(testDirectory + "\\data\\test1.json");
30

  
31
        try {
32
            graphManager = new GraphJSONDataLoader(graphFile).LoadData();
33
        } catch (IOException e) {
34
            e.printStackTrace();
35
        }
36
    }
37

  
38
    @Test
39
    void testFilter1a() {
40
        GraphInterface graph = createGraph("test1a.json");
41

  
42
        List<String> vertexIds = new ArrayList<>();
43
        vertexIds.add("32");
44
        vertexIds.add("9");
45
        vertexIds.add("1");
46
        vertexIds.add("2");
47

  
48
        List<EdgeInterface> edges = new ArrayList<>();
49

  
50
        List<SubedgeInfo> subedgeInfos = new ArrayList<>();
51
        subedgeInfos.add(createTestSubEdge(117));
52
        edges.add(createTestEdge("1", "32", subedgeInfos));
53

  
54
        subedgeInfos = new ArrayList<>();
55
        subedgeInfos.add(createTestSubEdge(10));
56
        edges.add(createTestEdge("1", "9", subedgeInfos));
57

  
58
        subedgeInfos = new ArrayList<>();
59
        subedgeInfos.add(createTestSubEdge(8));
60
        edges.add(createTestEdge("2", "9", subedgeInfos));
61

  
62
        graphContains(graph, vertexIds, edges);
63
    }
64

  
65
    @Test
66
    void testFilter1b() {
67
        GraphInterface graph = createGraph("test1b.json");
68

  
69
        List<String> vertexIds = new ArrayList<>();
70
        vertexIds.add("2");
71
        vertexIds.add("9");
72
        vertexIds.add("18");
73

  
74
        List<EdgeInterface> edges = new ArrayList<>();
75

  
76
        List<SubedgeInfo> subedgeInfos = new ArrayList<>();
77
        subedgeInfos.add(createTestSubEdge(9));
78
        edges.add(createTestEdge("9", "2", subedgeInfos));
79

  
80
        subedgeInfos = new ArrayList<>();
81
        subedgeInfos.add(createTestSubEdge(86));
82
        edges.add(createTestEdge("18", "2", subedgeInfos));
83

  
84
        graphContains(graph, vertexIds, edges);
85
    }
86

  
87
    @Test
88
    void testFilter1c() {
89
        GraphInterface graph = createGraph("test1c.json");
90

  
91
        List<String> vertexIds = new ArrayList<>();
92
        vertexIds.add("2");
93
        vertexIds.add("18");
94
        vertexIds.add("32");
95

  
96
        List<EdgeInterface> edges = new ArrayList<>();
97

  
98
        List<SubedgeInfo> subedgeInfos = new ArrayList<>();
99
        subedgeInfos.add(createTestSubEdge(79));
100
        edges.add(createTestEdge("2", "18", subedgeInfos));
101

  
102
        subedgeInfos = new ArrayList<>();
103
        subedgeInfos.add(createTestSubEdge(86));
104
        edges.add(createTestEdge("18", "2", subedgeInfos));
105

  
106
        graphContains(graph, vertexIds, edges);
107
    }
108

  
109
    @Test
110
    void testFilter1d() {
111
        GraphInterface graph = createGraph("test1d.json");
112

  
113
        List<String> vertexIds = new ArrayList<>();
114
        vertexIds.add("1");
115
        vertexIds.add("9");
116
        vertexIds.add("32");
117

  
118
        List<EdgeInterface> edges = new ArrayList<>();
119

  
120
        List<SubedgeInfo> subedgeInfos = new ArrayList<>();
121
        subedgeInfos.add(createTestSubEdge(10));
122
        edges.add(createTestEdge("1", "9", subedgeInfos));
123

  
124
        subedgeInfos = new ArrayList<>();
125
        subedgeInfos.add(createTestSubEdge(117));
126
        edges.add(createTestEdge("1", "32", subedgeInfos));
127

  
128
        graphContains(graph, vertexIds, edges);
129
    }
130

  
131
    @Test
132
    void testFilter1e() {
133
        GraphInterface graph = createGraph("test1e.json");
134

  
135
        List<String> vertexIds = new ArrayList<>();
136
        vertexIds.add("1");
137
        vertexIds.add("32");
138
        vertexIds.add("9");
139

  
140
        List<EdgeInterface> edges = new ArrayList<>();
141

  
142
        List<SubedgeInfo> subedgeInfos = new ArrayList<>();
143
        subedgeInfos.add(createTestSubEdge(11));
144
        edges.add(createTestEdge("9", "1", subedgeInfos));
145

  
146
        subedgeInfos = new ArrayList<>();
147
        subedgeInfos.add(createTestSubEdge(117));
148
        edges.add(createTestEdge("1", "32", subedgeInfos));
149

  
150
        graphContains(graph, vertexIds, edges);
151
    }
152

  
153
    @Test
154
    void testFilter1f() {
155
        GraphInterface graph = createGraph("test1f.json");
156

  
157
        List<String> vertexIds = new ArrayList<>();
158
        vertexIds.add("1");
159
        vertexIds.add("2");
160
        vertexIds.add("18");
161

  
162
        List<EdgeInterface> edges = new ArrayList<>();
163

  
164
        List<SubedgeInfo> subedgeInfos = new ArrayList<>();
165
        subedgeInfos.add(createTestSubEdge(86));
166
        edges.add(createTestEdge("18", "2", subedgeInfos));
167

  
168
        graphContains(graph, vertexIds, edges);
169
    }
170

  
171
    private GraphInterface createGraph(String configFilename) {
172
        String configLocation = testDirectory + "\\config";
173
        JSONConfigLoader configLoader = new JSONConfigLoader(graphManager, configLocation);
174
        JSONConfigLoader.configFilename = configFilename;
175
        return graphManager.createGraph(configLoader);
176
    }
177

  
178
    private SubedgeInfo createTestSubEdge(int id) {
179
        SubedgeInfo subedge = new SubedgeInfo(0, null);
180
        subedge.id = id;
181

  
182
        return subedge;
183
    }
184

  
185
    private EdgeInterface createTestEdge(String from, String to, List<SubedgeInfo> subedges) {
186
        EdgeInterface edge = new EdgeImpl(0, from, to, false, "");
187
        edge.setSubedgeInfo(subedges);
188

  
189
        return edge;
190
    }
191

  
192
    /**
193
     *
194
     * @param graph - Graph object to test.
195
     * @param vertexIds - vertices, that graph must contain in order to pass the test.
196
     * @param edges - edges, that graph must contain in order to pass the test.
197
     */
198
    private void graphContains(GraphInterface graph, List<String> vertexIds, List<EdgeInterface> edges) {
199
        Assertions.assertEquals(graph.getVertices().size(), vertexIds.size());
200
        Assertions.assertEquals(graph.getEdges().size(), edges.size());
201

  
202
        // Vertices
203
        for (String vertexId : graph.getVertices().keySet()) {
204
            Assertions.assertTrue(vertexIds.contains(vertexId));
205
        }
206

  
207
        // Edges
208
        for (EdgeInterface edge : graph.getEdges()) {
209
            Assertions.assertTrue(edges.contains(edge));
210

  
211
            EdgeInterface edgeCmp = edges.get(edges.indexOf(edge));
212
            Assertions.assertEquals(edge.getSubedgeInfo().size(), edgeCmp.getSubedgeInfo().size());
213

  
214
            for (SubedgeInfo subedgeInfo : edge.getSubedgeInfo()) {
215
                Assertions.assertTrue(containsSubedgeWithId(subedgeInfo, edgeCmp.getSubedgeInfo()));
216
            }
217
        }
218
    }
219

  
220
    /**
221
     * Checks if list of subedges contains subedge with id.
222
     * @param subedgeInfo - Subedge from graph to compare.
223
     * @param subedgeInfos - List of subedges that the graph must contain.
224
     * @return true if subedges that should be present contain id of subedge.
225
     */
226
    private boolean containsSubedgeWithId(SubedgeInfo subedgeInfo, List<SubedgeInfo> subedgeInfos) {
227
        for (SubedgeInfo s : subedgeInfos) {
228
            if (s.id == subedgeInfo.id) {
229
                return true;
230
            }
231
        }
232

  
233
        return false;
234
    }
235
}
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/ArchetypeIconConfigTest.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.junit.jupiter.api.AfterAll;
4
import org.junit.jupiter.api.Assertions;
5
import org.junit.jupiter.api.BeforeAll;
6
import org.junit.jupiter.api.Test;
7
import org.openqa.selenium.By;
8
import org.openqa.selenium.NoSuchElementException;
9
import org.openqa.selenium.WebDriver;
10
import org.openqa.selenium.WebElement;
11
import org.opentest4j.AssertionFailedError;
12

  
13
public class ArchetypeIconConfigTest {
14
    static WebDriver browser;
15

  
16
    @BeforeAll
17
    public static void initTest() {
18
        SeleniumUtil.prepareConfigFile("archetypeIconConfigTest.json");
19
        browser = SeleniumUtil.init();
20
        SeleniumUtil.loadGraphData("archetypeIconTest.json");
21
    }
22

  
23
    @Test
24
    public void SpecifiedIcon1(){
25
        locateTestingArchetypeIcon("vertex1");
26
    }
27

  
28
    @Test
29
    public void SpecifiedIcon2(){
30
        Assertions.assertThrows(NoSuchElementException.class,
31
                () -> checkUnspecifiedArchetypeSymbol("vertex1", "S"));
32

  
33
        System.out.println("Default value not found on the vertex with specified archetype icon.");
34
    }
35

  
36
    @Test
37
    public void UnspecifiedIcon1(){
38
        Assertions.assertThrows(NoSuchElementException.class,
39
                () -> locateTestingArchetypeIcon("vertex2"));
40

  
41
        System.out.println("Element not found.");
42
    }
43

  
44
    @Test
45
    public void UnspecifiedIcon2(){
46
        Assertions.assertThrows(NoSuchElementException.class,
47
                () -> locateTestingArchetypeIcon("vertex3"));
48

  
49
        System.out.println("Element not found.");
50
    }
51

  
52
    @Test
53
    public void UnspecifiedIcon3(){
54
        checkUnspecifiedArchetypeSymbol("vertex2", "U");
55
    }
56

  
57
    @Test
58
    public void UnspecifiedIcon4(){
59
        checkUnspecifiedArchetypeSymbol("vertex3", "☺");
60
    }
61

  
62
    /**
63
     * Utility method for checking of the presence of the specified icon element
64
     * @param elementId Id of the element in which the search is done
65
     */
66
    private void locateTestingArchetypeIcon(String elementId) {
67
        WebElement icon = browser.findElement(By.id(elementId))
68
                .findElement(By.className("archetype"));
69

  
70
        System.out.println("Trying to locate an element with class 'testingArchetypeIcon'");
71
        icon.findElement(By.className("testingArchetypeIcon"));
72
        System.out.println("Element found.");
73
    }
74

  
75
    /**
76
     * Utility method for checking whether specified element contains the default archetype icon
77
     * @param elementId Id of the element in which the test is done
78
     * @param expectedText Expected text present in the icon
79
     */
80
    private void checkUnspecifiedArchetypeSymbol(String elementId, String expectedText) {
81
        WebElement icon = browser.findElement(By.id(elementId))
82
                .findElement(By.className("archetype"));
83

  
84
        System.out.println("Checking text of unspecified archetype icon");
85
        Assertions.assertEquals(expectedText, icon.findElement(By.tagName("text")).getText(),
86
                "Text of unspecified icon is different from the expected.");
87
        System.out.println("Default text found.");
88
    }
89

  
90

  
91
    @AfterAll
92
    public static void finishTest() {
93
        SeleniumUtil.clear();
94
    }
95
}
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/AssociatedArchetypeTest.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.junit.jupiter.api.AfterAll;
4
import org.junit.jupiter.api.Assertions;
5
import org.junit.jupiter.api.BeforeAll;
6
import org.junit.jupiter.api.Test;
7
import org.openqa.selenium.By;
8
import org.openqa.selenium.NoSuchElementException;
9
import org.openqa.selenium.WebDriver;
10
import org.openqa.selenium.WebElement;
11

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

  
15
public class AssociatedArchetypeTest {
16
    static WebDriver browser;
17

  
18
    @BeforeAll
19
    public static void initTest() {
20
        SeleniumUtil.prepareConfigFile("emptyConfig.json");
21
        browser = SeleniumUtil.init();
22
        SeleniumUtil.loadGraphData("associatedArchetypeTest.json");
23
    }
24

  
25
    @Test
26
    public void visibilityOfAllIcons() {
27
        checkVisibilityOfIcons("vertex1", Arrays.asList("2", "4"));
28

  
29
        checkVisibilityOfIcons("vertex2",Arrays.asList("1"));
30

  
31
        checkVisibilityOfIcons("vertex3",Arrays.asList("1"));
32

  
33
        checkVisibilityOfIcons("vertex4",Arrays.asList("1", "3"));
34

  
35
        checkVisibilityOfIcons("vertex5",Arrays.asList("4"));
36
    }
37

  
38
    @Test
39
    public void vertexHighlighting() {
40
        //associated vertices to V1
41
        checkHighlightedVertices("archetype1_1", Arrays.asList("vertex2", "vertex3"));
42
        checkHighlightedVertices("archetype1_3", Arrays.asList("vertex4"));
43

  
44
        //associated vertices to V2
45
        checkHighlightedVertices("archetype2_0", Arrays.asList("vertex1"));
46

  
47
        //associated vertices to V3
48
        checkHighlightedVertices("archetype3_0", Arrays.asList("vertex1"));
49

  
50
        //associated vertices to V4
51
        checkHighlightedVertices("archetype4_0", Arrays.asList("vertex1"));
52
        checkHighlightedVertices("archetype4_2", Arrays.asList("vertex5"));
53

  
54
        //associated vertices to V5
55
        checkHighlightedVertices("archetype5_3", Arrays.asList("vertex4"));
56
    }
57

  
58
    /**
59
     * Check if all the expected associated archetype icons are present
60
     * @param elementId Id of the vertex in the DOM
61
     * @param expectedArchetypeIconTexts Texts of all the associated archetype icons that are expected to occur
62
     */
63
    private void checkVisibilityOfIcons(String elementId, List<String> expectedArchetypeIconTexts) {
64
        System.out.println("Checking element " + elementId);
65
        WebElement vertex = browser.findElement(By.id(elementId));
66

  
67
        List<WebElement> associatedArchetypeIcons = vertex.findElements(By.className("associatedArchetype"));
68

  
69
        System.out.println("Associated archetypes: \n");
70
        Assertions.assertEquals(associatedArchetypeIcons.size(), expectedArchetypeIconTexts.size());
71

  
72
        for (int i = 0; i < expectedArchetypeIconTexts.size(); i++) {
73
            WebElement icon = associatedArchetypeIcons.get(i);
74
            System.out.println("Icon id: " + icon.getAttribute("id"));
75

  
76
            String archetypeIconText = icon.findElement(By.tagName("text")).getText();
77
            System.out.println("Icon text: " + archetypeIconText +"\n");
78

  
79
            Assertions.assertEquals(expectedArchetypeIconTexts.get(i), archetypeIconText);
80
        }
81
    }
82

  
83
    /**
84
     * Check if all the expected vertices are highlighted when clicking on the associated archetype icon
85
     * @param associatedArchetypeIconId Id of the associated archetype icon in the DOM
86
     * @param expectedHighlightedVertexIds Ids of all the vertices that are expected to be highlighted
87
     */
88
    private void checkHighlightedVertices(String associatedArchetypeIconId, List<String> expectedHighlightedVertexIds) {
89
        System.out.println("\nChecking associated vertices for archetype icon with id: " + associatedArchetypeIconId);
90
        WebElement associatedArchetypeIcon = browser.findElement(By.id(associatedArchetypeIconId));
91
        SeleniumUtil.svgClick(associatedArchetypeIcon);
92

  
93
        List<WebElement> highlightedVertices = browser.findElements(By.className("colorHighlightArchetype"));
94

  
95
        System.out.println("Number of highlighted vertices: " + highlightedVertices.size());
96
        Assertions.assertEquals(expectedHighlightedVertexIds.size(), highlightedVertices.size());
97

  
98
        for(int i = 0; i < highlightedVertices.size(); i++) {
99
            WebElement vertex = highlightedVertices.get(i);
100
            String id = vertex.getAttribute("id");
101

  
102
            System.out.println(id);
103

  
104
            Assertions.assertEquals(expectedHighlightedVertexIds.get(i), id);
105
        }
106

  
107
        SeleniumUtil.svgClick(associatedArchetypeIcon);
108
    }
109

  
110
    @AfterAll
111
    public static void finishTest() {
112
        SeleniumUtil.clear();
113
    }
114
}
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/AutomaticGroupingTest.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.junit.jupiter.api.AfterAll;
4
import org.junit.jupiter.api.Assertions;
5
import org.junit.jupiter.api.BeforeAll;
6
import org.junit.jupiter.api.Test;
7
import org.openqa.selenium.By;
8
import org.openqa.selenium.NoSuchElementException;
9
import org.openqa.selenium.WebDriver;
10
import org.openqa.selenium.WebElement;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
public class AutomaticGroupingTest {
16
    static WebDriver browser;
17

  
18
    @BeforeAll
19
    public static void initTest() {
20
        SeleniumUtil.prepareConfigFile("automaticGroupingConfigTest.json");
21
        browser = SeleniumUtil.init();
22
        SeleniumUtil.loadGraphData("automaticGroupingTest.json");
23
    }
24

  
25
    @Test
26
    public void groups1(){
27
        String groupName = "FirstGroupArchetype";
28
        List<String> verticesIds = new ArrayList<>();
29
        verticesIds.add("li1");
30
        verticesIds.add("li3");
31

  
32
        checkGroupExisting(browser, groupName, verticesIds);
33
        System.out.println("Group: " + groupName + " was not found.");
34
    }
35

  
36
    private void checkGroupExisting(WebDriver browser, String groupName, List<String> verticesIds){
37
        WebElement group = browser.findElement(By.className("component group_vertices"));
38
        System.out.println("Trying to locate vertexes in group");
39
        for(String id : verticesIds){
40
            group.findElement(By.id(id));
41
        }
42

  
43
        System.out.println("Vertexes found.");
44
    }
45

  
46
    @AfterAll
47
    public static void finishTest() {
48
        SeleniumUtil.clear();
49
    }
50
}
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/DetailsTest.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.junit.jupiter.api.AfterAll;
4
import org.junit.jupiter.api.Assertions;
5
import org.junit.jupiter.api.BeforeAll;
6
import org.junit.jupiter.api.Test;
7
import org.openqa.selenium.By;
8
import org.openqa.selenium.WebDriver;
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

  
15
public class DetailsTest {
16

  
17
    static WebDriver browser;
18

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

  
21
    @BeforeAll
22
    public static void initTest() {
23
        SeleniumUtil.prepareConfigFile("emptyConfig.json");
24
        browser = SeleniumUtil.init();
25
        SeleniumUtil.loadGraphData("detailTest.json");
26
    }
27

  
28
    @Test
29
    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
        );
47
    }
48

  
49
    @Test
50
    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

  
77

  
78
    private WebElement edgeQTip(String edgeElementId) {
79
        WebElement arrow = browser.findElement(By.id(edgeElementId))
80
                .findElement(By.className("arrow"));
81

  
82
        return getQTipElement(arrow);
83
    }
84

  
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

  
92
    private WebElement getQTipElement(WebElement toClick) {
93
        SeleniumUtil.svgClick(toClick);
94

  
95
        return browser.findElement(By.xpath(VISIBLE_Q_TIP_XPATH));
96
    }
97

  
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());
103

  
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);
110

  
111
        qtip.close();
112
        Assertions.assertFalse(qtip.isVisible());
113
    }
114

  
115
    @AfterAll
116
    public static void finishTest() {
117
        SeleniumUtil.clear();
118
    }
119
}
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/GroupStatsChangingTest.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.junit.jupiter.api.AfterAll;
4
import org.junit.jupiter.api.Assertions;
5
import org.junit.jupiter.api.BeforeAll;
6
import org.junit.jupiter.api.Test;
7
import org.openqa.selenium.By;
8
import org.openqa.selenium.WebDriver;
9
import org.openqa.selenium.WebElement;
10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14

  
15
public class GroupStatsChangingTest {
16
    static WebDriver browser;
17

  
18
    @BeforeAll
19
    public static void initTest() {
20
        SeleniumUtil.prepareConfigFile("emptyConfig.json");
21
        browser = SeleniumUtil.init();
22
        SeleniumUtil.loadGraphData("associatedArchetypeTest.json");
23
        for(int i = 0; i<=5;i++)
24
            SeleniumUtil.svgClick(browser.findElement(By.id("zoomOut")));
25
    }
26

  
27
    @Test
28
    public void ChangingStats() {
29
        String groupId = "";
30
        switchExludeMode();
31
        WebElement firstEcludedVertex = browser.findElement(By.id("vertex3"));
32

  
33
        SeleniumUtil.svgClick(firstEcludedVertex);
34
        System.out.println("Exclude vertex3 to group as first vertex of group");
35

  
36
        excludeToExistingGroup("vertex2");
37
        System.out.println("Exclude vertex2 to group");
38

  
39
        //get data-id of fgroup
40
        groupId = browser.findElement(By.className("group_vertices")).getAttribute("data-id");
41

  
42
        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("2","0","0","0")));
43

  
44
        excludeToExistingGroup("vertex1");
45
        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("2","2","0","2")));
46
        System.out.println("Exclude vertex1 to group");
47

  
48
        System.out.println("Remove vertex2 to group");
49
        removeVertexFromGroup("li2");
50
        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("1","2","0","2")));
51

  
52
        System.out.println("Switch off stats for vertex1");
53
        toogleVertexInGroup("li1");
54
        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("1","0","0","0")));
55

  
56
        System.out.println("Switch off stats for vertex3");
57
        toogleVertexInGroup("li3");
58
        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("0","0","0","0")));
59

  
60
        System.out.println("Switch on stats for vertex1");
61
        toogleVertexInGroup("li3");
62
        excludeToExistingGroup("vertex2");
63
        compareExpectedValues(groupId, new ArrayList<String>(Arrays.asList("2","0","0","0")));
64

  
65
        //finaly test just one vertex in group
66
        String archetypePrefix = "v_archetype_4_";
67
        switchExludeMode();
68
        WebElement singleEcludedVertex = browser.findElement(By.id("vertex4"));
69
        System.out.println("Exclude vertex4 to group as first vertex of group");
70
        SeleniumUtil.svgClick(singleEcludedVertex);
71

  
72
        System.out.println("Checking group statistics");
73
        String actualValue1 = browser.findElement(By.id(archetypePrefix + "0")).findElement(By.tagName("text")).getText();
74
        String actualValue2 = browser.findElement(By.id(archetypePrefix + "2")).findElement(By.tagName("text")).getText();
75
        Assertions.assertEquals(actualValue1, "2");
76
        Assertions.assertEquals(actualValue2, "1");
77

  
78
        System.out.println("Expected: 2 - Real: " + actualValue1);
79
        System.out.println("Expected: 1 - Real: " + actualValue2);
80

  
81
    }
82

  
83
    /**
84
     * Turn on exclude mode for vertex exclude
85
     */
86
    private void switchExludeMode(){
87
        browser.findElement(By.id("remove")).click();
88
        try {
89
            Thread.sleep(1000);
90
        } catch (InterruptedException e) {
91
            e.printStackTrace();
92
        }
93
    }
94

  
95
    /**
96
     * Exclude vertex from graph to group
97
     * @param vertexId id of vertex to exclude
98
     */
99
    private void excludeToExistingGroup(String vertexId){
100
        WebElement secondExcludedVertex = browser.findElement(By.id(vertexId));
101
        SeleniumUtil.svgContexClick(secondExcludedVertex);
102
        WebElement selectedGroup = browser.findElement(By.className("component_color"));
103
        SeleniumUtil.svgClick(selectedGroup);
104
    }
105

  
106
    /**
107
     * Remove vertex from group back to graph
108
     * @param vertexId id of vertex
109
     */
110
    private void removeVertexFromGroup(String vertexId){
111
        WebElement removeVertex = browser.findElement(By.id(vertexId)).findElement(By.className("deleteItemGroup"));
112
        SeleniumUtil.svgClick(removeVertex);
113
    }
114

  
115
    /**
116
     * Toogle stats for vertex
117
     * @param vertexId id of vertex
118
     */
119
    private void toogleVertexInGroup(String vertexId){
120
        WebElement removeVertex = browser.findElement(By.id(vertexId)).findElement(By.className("toggleStat"));
121
        SeleniumUtil.svgClick(removeVertex);
122
    }
123

  
124
    /**
125
     * comparison of real values with expected values
126
     * @param groupId id of group
127
     * @param expectedValues list of expected values
128
     */
129
    private void compareExpectedValues(String groupId, ArrayList<String> expectedValues){
130
        System.out.println("Checking group statistics");
131
        String archetypePrefix = "g_archetype_" + groupId + "_";
132

  
133
        List<String> actualValues = new ArrayList<String>();
134

  
135
        for(int i = 0; i< expectedValues.size(); i++) {
136
            String archetypePos = i+"";
137
            String actualValue = browser.findElement(By.id(archetypePrefix + archetypePos)).findElement(By.tagName("text")).getText();
138
            actualValues.add(actualValue);
139
        }
140

  
141
        for(int i = 0; i< expectedValues.size(); i++) {
142
            Assertions.assertEquals(actualValues.get(i), expectedValues.get(i));
143
            System.out.println("Expected: " + expectedValues.get(i) + " - Real: " + actualValues.get(i));
144
        }
145
    }
146

  
147
    @AfterAll
148
    public static void finishTest() {
149
        SeleniumUtil.clear();
150
    }
151
}
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
}
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/SampleTest.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.junit.jupiter.api.Assertions;
4
import org.junit.jupiter.api.AfterAll;
5
import org.junit.jupiter.api.BeforeAll;
6
import org.junit.jupiter.api.Test;
7
import org.openqa.selenium.By;
8
import org.openqa.selenium.WebDriver;
9
import org.openqa.selenium.WebElement;
10
import org.openqa.selenium.firefox.FirefoxDriver;
11
import org.openqa.selenium.support.ui.ExpectedConditions;
12
import org.openqa.selenium.support.ui.WebDriverWait;
13

  
14
public class SampleTest {
15
    static WebDriver browser;
16

  
17
    @BeforeAll
18
    public static void initTest() {
19
        browser = SeleniumUtil.init();
20
    }
21
    @Test
22
    public void Test(){
23
        WebElement fileInput = browser.findElement(By.id("hidden_input"));
24
        fileInput.sendKeys(System.getProperty("user.dir") + "\\..\\data\\aswi2017falsum.json" );
25
        browser.findElement(By.className("load")).click();
26

  
27
        WebDriverWait wait = new WebDriverWait(browser, 20);
28
        wait.until(ExpectedConditions.presenceOfElementLocated(By.className("vertices")));
29

  
30
        System.out.println(browser.findElement(By.id("vertex1")).getAttribute("data-id"));
31

  
32
        //Assertions.assertTrue(header.getText().equals("Interactive Multimodal Graph Explorer"));
33
    }
34

  
35
    @AfterAll
36
    public static void finishTest() {
37
        SeleniumUtil.clear();
38
    }
39

  
40
}
sources/src/test/java/cz/zcu/kiv/imiger/tests/frontend/SeleniumUtil.java
1
package cz.zcu.kiv.imiger.tests.frontend;
2

  
3
import org.openqa.selenium.By;
4
import org.openqa.selenium.WebDriver;
5
import org.openqa.selenium.WebElement;
6
import org.openqa.selenium.firefox.FirefoxDriver;
7
import org.openqa.selenium.interactions.Actions;
8
import org.openqa.selenium.support.ui.ExpectedConditions;
9
import org.openqa.selenium.support.ui.WebDriverWait;
10

  
11
import java.io.IOException;
12
import java.nio.file.Files;
13
import java.nio.file.Path;
14
import java.nio.file.Paths;
15

  
16
public class SeleniumUtil {
17
    /**
18
     * Path to the gecko driver.
19
     * Please change to your location
20
     */
21
    private static final String GECKO_PATH = "C:\\aswi-git\\geckodriver.exe";
22

  
23
    private static final String URL = "http://localhost:8080/VisualizationTool";
24

  
25
    private static final int DATA_LOAD_TIMEOUT = 20;
26

  
27
    private static WebDriver browser;
28

  
29
    public static WebDriver init() {
30
        System.setProperty("webdriver.gecko.driver", GECKO_PATH);
31
        browser = new FirefoxDriver();
32
        browser.get(URL);
33
        return browser;
34
    }
35

  
36
    public static void loadGraphData(String filename) {
37
        WebElement fileInput = browser.findElement(By.id("hidden_input"));
38
        fileInput.sendKeys(System.getProperty("user.dir") + "\\..\\test\\data\\" + filename );
39
        browser.findElement(By.className("load")).click();
40

  
41
        WebDriverWait wait = new WebDriverWait(browser, DATA_LOAD_TIMEOUT);
42
        wait.until(ExpectedConditions.presenceOfElementLocated(By.className("vertices")));
43

  
44
        try {
45
            Thread.sleep(1000);
46
        } catch (InterruptedException e) {
47
            e.printStackTrace();
48
        }
49
    }
50

  
51
    public static void prepareConfigFile(String configFile) {
52
        try {
53
            Files.deleteIfExists(Paths.get(System.getProperty("user.home") + "\\Documents\\aswi\\test\\config\\config.json"));
54
            Files.createLink(Paths.get(System.getProperty("user.home") + "\\Documents\\aswi\\test\\config\\config.json"),
55
                    Paths.get(System.getProperty("user.dir") + "\\..\\test\\config\\" + configFile));
56
        } catch (IOException e) {
57
            e.printStackTrace();
58
        }
59
    }
60

  
61
    public static void svgClick(WebElement toClick) {
62
        Actions builder = new Actions(browser);
63
        builder.click(toClick).build().perform();
64

  
65
        try {
66
            Thread.sleep(1000);
67
        } catch (InterruptedException e) {
68
            e.printStackTrace();
69
        }
70
    }
71

  
72
    /**
73
     * Right mouse click
74
     * @param toClick element for click
75
     */
76
    public static void svgContexClick(WebElement toClick) {
77
        Actions builder = new Actions(browser);
78
        builder.contextClick(toClick).build().perform();
79

  
80
        try {
81
            Thread.sleep(1000);
82
        } catch (InterruptedException e) {
83
            e.printStackTrace();
84
        }
85
    }
86

  
87
    public static void clear() {
88
        browser.close();
89
    }
90
}

Také k dispozici: Unified diff