Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import re
2import yaml
4update_style_schema = yaml.safe_load("""
5allOf:
6 - type: object
7 - "$ref": "#/definitions/common/locator"
8""")
11def Base_update_style(self, param):
12 """
13 - name: red background
14 update_style:
15 id: element1
16 "background-color": red
17 - name: dismiss heading
18 update_style:
19 tag: h1
20 display: none
21 """
22 newstyle = self.removelocator(param)
23 for elem in self.findmany(param):
24 self.log.debug("update style %s <- %s", elem.id, newstyle)
25 for k, v in newstyle.items():
26 script = "".join([
27 "arguments[0].style[", repr(k), "]=", repr(v), ";",
28 "return arguments[0];"
29 ])
30 self.execute(script, elem)
33update_content_schema = yaml.safe_load("""
34allOf:
35 - type: object
36 properties:
37 pattern: {type: string}
38 replacement: {type: string}
39 regexp: {type: boolean}
40 flag:
41 type: string
42 enum: [i, g]
43 - "$ref": "#/definitions/common/locator"
44""")
47def Base_update_content(self, param):
48 """
49 - name: mask some number
50 update_content:
51 pattern: "[0-9]"
52 replacement: "*"
53 regexp: true
54 id: element1
55 """
56 pattern = param.get("pattern")
57 replacement = param.get("replacement")
58 regexp = param.get("regexp", False)
59 flag = param.get("flag", "g")
60 if pattern is None or replacement is None:
61 raise Exception("invalid parameter: %s" % (param))
62 if regexp:
63 # check regexp
64 re.compile(pattern)
65 # OK
66 script = "".join([
67 "arguments[0].innerHTML=arguments[0].innerHTML.replace(/",
68 pattern, "/", flag, ",", repr(replacement), ");"
69 "return arguments[0];"
70 ])
71 else:
72 script = "".join([
73 "arguments[0].innerHTML=arguments[0].innerHTML.replace(",
74 repr(pattern), ",", repr(replacement), ");"
75 "return arguments[0];"
76 ])
77 for elem in self.findmany(param):
78 self.execute(script, elem)
81update_attribute_schema = yaml.safe_load("""
82allOf:
83 - "$ref": "#/definitions/common/locator"
84 - type: object
85 properties:
86 replacement: {type: object}
87""")
90def Base_update_attribute(self, param):
91 """
92 - name: link redirection
93 update_attribute:
94 tag: a
95 href: http://example.com/
96 - name: rename
97 update_attribute:
98 id: element1
99 replacement:
100 id: new-element1
101 class: null # remove attribute
102 """
103 newattr = self.removelocator(param)
104 if len(newattr) == 0:
105 newattr = param.get("replacement", {})
106 for elem in self.findmany(param):
107 self.log.debug("update style %s <- %s", elem.id, newattr)
108 for k, v in newattr.items():
109 if v is None:
110 script = "".join([
111 "arguments[0].removeAttribute(", repr(k), ");",
112 "return arguments[0];"
113 ])
114 else:
115 script = "".join([
116 "arguments[0].setAttribute(", repr(k), ",", repr(v), ");",
117 "return arguments[0];"
118 ])
119 self.execute(script, elem)