Skip to content

Commit f3a3651

Browse files
committed
Critical Fix in nodelocator
1 parent cc684c1 commit f3a3651

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

CHANGELIST.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Future Themes (In-Progress or Planned):
2121

2222
1.2.19
2323
------
24+
- CRITICAL FIX: Xml.node_locator call retained attr dict values in successive calls. Fixed.
2425

2526
1.2.18
2627
------
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is a part of Arjuna
2+
# Copyright 2015-2021 Rahul Verma
3+
4+
# Website: www.RahulVerma.net
5+
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is a part of Arjuna
2+
# Copyright 2015-2021 Rahul Verma
3+
4+
# Website: www.RahulVerma.net
5+
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# The tests are based on tests for jsonpath-rw-ext in https://github.com/wolverdude/GenSON
19+
20+
from arjuna import *
21+
from arjuna.tpi.parser.yaml import Yaml
22+
23+
@test
24+
def check_xml_nodelocator_01(request):
25+
l1 = Xml.node_locator(tags="form", id="login-form")
26+
print(l1)
27+
l2 = Xml.node_locator(tags="input", name="requestId")
28+
print(l2)
29+
l3 = Xml.node_locator(tags="input", name="csrf-token")
30+
print(l3)

arjuna/tpi/parser/html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from io import StringIO
2323
from lxml.html import soupparser
2424

25-
from .xml import XmlNode, Xml
25+
from .xml import XmlNode, Xml, NodeLocator
2626

2727
class HtmlNode(XmlNode):
2828
'''

arjuna/tpi/parser/xml.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class NodeLocator:
5757
'''
5858

5959
def __init__(self, *, tags: 'strOrSequence'=None, text=None, attrs={}, **attr_kwargs):
60-
6160
if tags is None and text is None and not attrs and not attr_kwargs:
6261
raise Exception("You must provided tags and/or attributes for finding nodes.")
6362

@@ -66,10 +65,11 @@ def __init__(self, *, tags: 'strOrSequence'=None, text=None, attrs={}, **attr_kw
6665
if text:
6766
attr_conditions.append("contains(text(), '{}')".format(text))
6867

69-
attrs.update(attr_kwargs)
68+
lattrs = {}
69+
lattrs.update(attr_kwargs)
7070

71-
if attrs:
72-
for attr, value in attrs.items():
71+
if lattrs:
72+
for attr, value in lattrs.items():
7373
if value is None:
7474
attr_conditions.append("@{}".format(attr))
7575
else:
@@ -89,6 +89,9 @@ def search_node(self, node: 'XmlNode') -> tuple:
8989
'''
9090
return (XmlNode(n) for n in node.xpath(self.__xpath))
9191

92+
def __str__(self):
93+
return "XPath: {}".format(self.__xpath)
94+
9295

9396
def _process_child_html(in_str):
9497
processed = "\n".join([l for l in in_str.splitlines() if l.strip()])
@@ -105,7 +108,6 @@ def _empty_or_none(in_str):
105108
else:
106109
return in_str is None
107110

108-
109111
@track("trace")
110112
class XmlNode:
111113
'''
@@ -386,7 +388,7 @@ def find(self, *node_locators, strict: bool=False) -> 'XmlNode':
386388
return matches[0]
387389
else:
388390
if strict:
389-
raise Exception("Element could not be found with Node Locators: >><<".format([str(n) for n in node_locators]))
391+
raise Exception("Element could not be found with Node Locators: >>{}<<".format([str(n) for n in node_locators]))
390392
else:
391393
return None
392394

0 commit comments

Comments
 (0)