Skip to content

Commit

Permalink
Critical Fix in nodelocator
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-verma committed Mar 19, 2022
1 parent cc684c1 commit f3a3651
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELIST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Future Themes (In-Progress or Planned):

1.2.19
------
- CRITICAL FIX: Xml.node_locator call retained attr dict values in successive calls. Fixed.

1.2.18
------
Expand Down
16 changes: 16 additions & 0 deletions arjuna-samples/arjex/test/pkg/parsing/xml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is a part of Arjuna
# Copyright 2015-2021 Rahul Verma

# Website: www.RahulVerma.net

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
30 changes: 30 additions & 0 deletions arjuna-samples/arjex/test/pkg/parsing/xml/check_xml_01_basics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is a part of Arjuna
# Copyright 2015-2021 Rahul Verma

# Website: www.RahulVerma.net

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# The tests are based on tests for jsonpath-rw-ext in https://github.com/wolverdude/GenSON

from arjuna import *
from arjuna.tpi.parser.yaml import Yaml

@test
def check_xml_nodelocator_01(request):
l1 = Xml.node_locator(tags="form", id="login-form")
print(l1)
l2 = Xml.node_locator(tags="input", name="requestId")
print(l2)
l3 = Xml.node_locator(tags="input", name="csrf-token")
print(l3)
2 changes: 1 addition & 1 deletion arjuna/tpi/parser/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from io import StringIO
from lxml.html import soupparser

from .xml import XmlNode, Xml
from .xml import XmlNode, Xml, NodeLocator

class HtmlNode(XmlNode):
'''
Expand Down
14 changes: 8 additions & 6 deletions arjuna/tpi/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class NodeLocator:
'''

def __init__(self, *, tags: 'strOrSequence'=None, text=None, attrs={}, **attr_kwargs):

if tags is None and text is None and not attrs and not attr_kwargs:
raise Exception("You must provided tags and/or attributes for finding nodes.")

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

attrs.update(attr_kwargs)
lattrs = {}
lattrs.update(attr_kwargs)

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

def __str__(self):
return "XPath: {}".format(self.__xpath)


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


@track("trace")
class XmlNode:
'''
Expand Down Expand Up @@ -386,7 +388,7 @@ def find(self, *node_locators, strict: bool=False) -> 'XmlNode':
return matches[0]
else:
if strict:
raise Exception("Element could not be found with Node Locators: >><<".format([str(n) for n in node_locators]))
raise Exception("Element could not be found with Node Locators: >>{}<<".format([str(n) for n in node_locators]))
else:
return None

Expand Down

0 comments on commit f3a3651

Please sign in to comment.