Skip to content

Commit

Permalink
WithX identifiers can be used with With.locator() call.
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-verma committed Mar 10, 2020
1 parent eeec865 commit 5ea010b
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 265 deletions.
2 changes: 2 additions & 0 deletions CHANGELIST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Following is the list of critical additions and updates for a given released ver
- BrowserName enum has been changed to contain only Chrome and Firefox as these are the current supported browsers.
- withx in GNS files supports string, list and dictionary entries in YAML and maps them to vargs and kwargs in formatting the value of withx entry referred by a label.
- Separated current Yaml parsing as Yaml and YamlFile classes in arjuna.core.yaml module.
- Introduced WithX class to handle WithX parsing and processing.
- Provision to add Withx identifiers which can be referred to from any GNS file. These are included in the `<Project Root>/guiauto/withx/withx.yaml` file.
- A WithX identifier defined in `withx.yaml` can be used programmatically. It can be thought of as a method which Arjuna defines at run-time with the signature `With.locator(*args, **kwargs)` and can be called from any part of your code.

0.9.7
-----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

withx:
nav_link1:
lnav_link1:
wtype: xpath
value: "//li[contains(*//text(), '{}')]"

nav_link2:
lnav_link2:
wtype: xpath
value: "//{}[contains(*//text(), '{}')]"

nav_link3:
lnav_link3:
wtype: xpath
value: "//li[contains(*//text(), '{lname}')]"

Expand All @@ -18,18 +18,18 @@ labels:
link: Settings

posts:
nav_link1: Posts
lnav_link1: Posts

media:
nav_link2:
lnav_link2:
- li
- Media

pages:
nav_link3:
lnav_link3:
lname: Pages

comments:
nav_link4:
nav_link:
lname: Comments

2 changes: 1 addition & 1 deletion arjuna-samples/arjex_with_adv/guiauto/withx/withx.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nav_link4:
nav_link:
wtype: xpath
value: "//li[contains(*//text(), '{lname}')]"
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'''
This file is a part of Arjuna
Copyright 2015-2020 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.
'''

from arjuna import *
from arjex_with_adv.lib.gom.app import WordPress

@for_test
def dashboard(request):
# Setup
wordpress = WordPress()
home = wordpress.launch()
dashboard = home.login_with_default_creds()
yield dashboard

# Teadown
dashboard.top_nav.logout()
wordpress.quit()

@test
def check_withx_using_with(request, dashboard):
dashboard.left_nav.element(With.nav_link(lname="Media")).click()
4 changes: 2 additions & 2 deletions arjuna/configure/impl/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from arjuna.core.reader.hocon import HoconFileReader, HoconStringReader, HoconConfigDictReader

from arjuna.core.enums import ArjunaOption
from .validator import ConfigValidator
from .validator import Validator
from .config import Config, ArjunaConfig, UserConfig

class ConfigCreator:
Expand Down Expand Up @@ -145,7 +145,7 @@ def pass_through(self, input):

def get_setu_option_validator(self, conf_name):
validator_name = ConfigCreator.SETU_CONF_DESC_MAP[conf_name]
return validator_name, getattr(ConfigValidator, validator_name.lower())
return validator_name, getattr(Validator, validator_name.lower())

def get_user_option_validator(self, conf_name):
return "pass_through", self.pass_through
Expand Down
2 changes: 1 addition & 1 deletion arjuna/configure/impl/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from arjuna.core.enums import *
from arjuna.core.types.constants import *

class ConfigValidator:
class Validator:
VNREGEX = r'^([a-zA-Z][a-zA-Z_0-9]{2,50})$'
VNREGEX_TEXT = '''
An Arjuna name must be a string of length 3-50 starting with a letter, followed by letters, digits or _ (underscore).
Expand Down
1 change: 0 additions & 1 deletion arjuna/core/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
class Yaml:

def __init__(self, ydict):
print(ydict)
self.__ydict = ydict
self.__sections = tuple(self.__ydict.keys())
self.__ydict = CIStringDict(self.__ydict)
Expand Down
3 changes: 2 additions & 1 deletion arjuna/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ def init(self, project_root_dir, cli_config, run_id, *, static_rid, run_conf):
self.__localizer = Localizer.load_all(self.__ref_config)

from arjuna.core.yaml import YamlFile
from arjuna.interact.gui.auto.finder.withx import WithX
fpath = self.ref_config.value(ArjunaOption.GUIAUTO_WITHX_YAML)
self.__common_withx_ref = YamlFile(fpath)
self.__common_withx_ref = WithX(YamlFile(fpath).as_map())

return self.ref_config

Expand Down
45 changes: 45 additions & 0 deletions arjuna/interact/gui/auto/finder/withx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from arjuna.core.adv.types import CIStringDict
from arjuna.configure.impl.validator import Validator

class WithX:

def __init__(self, xdict={}):
self.__xdict = CIStringDict()
for k,v in xdict.items():
try:
self.__xdict[Validator.arjuna_name(k)] = {"wtype" : xdict[k]["wtype"].strip().upper(), "value" : xdict[k]["value"].strip()}
except Exception as e:
print(e)
print(xdict)
raise Exception(f"Invalid WithX name >>{k}<<.")

def has_locator(self, name):
return name in self.__xdict

def format_args(self, name, *vargs, **kwargs):
if not self.has_locator(name):
raise Exception("No WithX locator with name {} found.".format(name))
fmt = self.__xdict[name]
try:
return fmt["wtype"], fmt["value"].format(*vargs, **kwargs)
except Exception as e:
from arjuna import Arjuna
Arjuna.get_logger().error(f"Error in processing withx {name} : {fmt} for vargs {vargs} and kwargs {kwargs}")
raise

def format(self, name, loc_obj):
vargs = None
kwargs = None
if type(loc_obj) is str:
vargs = [loc_obj]
kwargs = dict()
elif type(loc_obj) in {list, tuple}:
vargs = loc_obj
kwargs = dict()
elif type(loc_obj) is dict:
vargs = []
kwargs = loc_obj
return self.format_args(name, *vargs, **kwargs)



Loading

0 comments on commit 5ea010b

Please sign in to comment.