-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
xpath_test.go
116 lines (100 loc) · 4.71 KB
/
xpath_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package biloba_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/biloba"
)
var _ = DescribeTable("Xpath DSL",
func(path biloba.XPath, expectedId string) {
b.Navigate(fixtureServer + "/xpath.html")
Ω(path).Should(b.HaveProperty("id", expectedId))
},
func(path biloba.XPath, _ string) string {
return path.String()
},
//empty and specific tag variants
Entry(nil, b.XPath().WithAttr("type", "number"), "age-input"),
Entry(nil, b.XPath("input").WithAttr("type", "number"), "age-input"),
Entry(nil, b.XPath("input").HasAttr("disabled"), "phone-input"),
//WithClass combined with different tags
Entry(nil, b.XPath().WithClass("highlight"), "age-label"),
Entry(nil, b.XPath("label").WithClass("highlight"), "age-label"),
Entry(nil, b.XPath("input").WithClass("highlight"), "age-input"),
//WithID
Entry(nil, b.XPath("input").WithID("hometown-input"), "hometown-input"),
//attr start/contain
Entry(nil, b.XPath("input").WithAttrStartsWith("id", "hometown"), "hometown-input"),
Entry(nil, b.XPath("input").WithAttrContains("id", "wn-in"), "hometown-input"),
//text start/contain
Entry(nil, b.XPath().WithText("Hometown:"), "hometown-label"),
Entry(nil, b.XPath().WithTextStartsWith("Hometown"), "hometown-label"),
Entry(nil, b.XPath().WithTextContains("ometow"), "hometown-label"),
//with class
Entry(nil, b.XPath("div").WithClass("fish"), "aquarium"),
Entry(nil, b.XPath("div").WithClass("otter"), "aquarium"),
Entry(nil, b.XPath("div").WithClass("octopus"), "aquarium"),
//boolean logic
Entry(nil, b.XPath("div").WithAttr("name", "habitat").WithClass("tiger"), "zoo"),
Entry(nil, b.XPath("div").WithAttr("name", "habitat"), "aquarium"),
Entry(nil, b.XPath("div").WithAttr("name", "habitat").Not(
b.XPredicate().WithClass("otter"),
), "zoo"),
Entry(nil, b.XPath("div").And(
b.XPredicate().WithAttr("name", "habitat"),
b.XPredicate().WithClass("bear"),
), "zoo"),
Entry(nil, b.XPath("div").And(
b.XPredicate().WithAttr("name", "habitat"),
).Or(
b.XPredicate().WithClass("octopus"),
b.XPredicate().WithClass("bear"),
), "aquarium"),
Entry(nil, b.XPath("div").Or(
b.XPredicate().And(
b.XPredicate().WithClass("red"),
b.XPredicate().WithText("Error"),
),
b.XPredicate().And(
b.XPredicate().WithClass("orange"),
b.XPredicate().WithText("Warning"),
),
).Not(b.XPredicate().HasAttr("fire-drill")), "orange-flag"),
//indexing
Entry(nil, b.XPath("div").WithAttr("name", "habitat").First(), "aquarium"),
Entry(nil, b.XPath("div").WithAttr("name", "habitat").Nth(2), "zoo"),
Entry(nil, b.XPath("div").WithAttr("name", "habitat").Last(), "rainforest"),
Entry(nil, b.XPath("div").WithClass("habitats").Descendant().First(), "common-habitats"),
Entry(nil, b.XPath("div").WithClass("habitats").Descendant().Nth(4), "obscure-habitats"),
Entry(nil, b.XPath("div").WithClass("habitats").Descendant().Last(), "all-microbiota"),
// navigating the tree
// - descendant
Entry(nil, b.XPath("div").WithID("reference").Descendant(), "all-habitats"),
Entry(nil, b.XPath("div").WithID("reference").Descendant().WithAttr("name", "habitat"), "aquarium"),
Entry(nil, b.XPath("div").WithID("reference").Descendant("ul"), "all-microbiota"),
Entry(nil, b.XPath("div").WithID("reference").Descendant().WithAttr("color", "blue"), "common-habitats"),
// - child
Entry(nil, b.XPath("div").WithID("reference").Child(), "all-habitats"),
Entry(nil, b.XPath("div").WithID("reference").Child("ul"), "all-languages"),
// - parent
Entry(nil, b.XPath("li").WithID("critters").Parent(), "all-microbiota"),
Entry(nil, b.XPath("li").WithText("Engli\"sh").Parent(), "all-languages"),
// - ancestor
Entry(nil, b.XPath("li").WithID("critters").Ancestor(), "critters"),
Entry(nil, b.XPath("li").WithID("critters").AncestorNotSelf(), "all-microbiota"),
Entry(nil, b.XPath("li").WithID("critters").Ancestor("div"), "all-habitats"),
Entry(nil, b.XPath("li").WithID("critters").Ancestor("div").Nth(2), "reference"),
// - siblings
Entry(nil, b.XPath().WithID("zoo").FollowingSibling(), "obscure-habitats"),
Entry(nil, b.XPath().WithID("zoo").FollowingSibling("ul"), "all-microbiota"),
Entry(nil, b.XPath("li").WithID("english").FollowingSibling("li"), "spanish"),
Entry(nil, b.XPath("li").WithID("english").FollowingSibling("li").Last(), "arabic"),
Entry(nil, b.XPath("li").WithID("english").PrecedingSibling("li"), "french"),
Entry(nil, b.XPath("li").WithID("english").PrecedingSibling("li").Last(), "swedish"),
// - whith child matching
Entry(nil, b.XPath("ul").WithChildMatching(b.RelativeXPath("li").WithText("Francais")), "all-languages"),
Entry(nil, b.XPath("ul").WithChildMatching(
b.RelativeXPath("li").Or(
b.XPredicate().WithText("Francais"),
b.XPredicate().WithText("Germs"),
)), "all-microbiota"),
)