Skip to content

Commit

Permalink
Merge pull request Blazemeter#1045 from Blazemeter/feat/action/python…
Browse files Browse the repository at this point in the history
…-code

raw python code in actions
  • Loading branch information
undera authored Jan 16, 2019
2 parents 39a6549 + fac4b03 commit 3c655cb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bzt/modules/python/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ def gen_action(self, action_config, indent=None):
elif atype == "script" and tag == "eval":
cmd = 'self.driver.execute_script(self.template(%r))' % selector
action_elements.append(self.gen_statement(cmd, indent=indent))
elif atype == "rawcode":
lines = param.split('\n')
for line in lines:
action_elements.append(self.gen_statement(line, indent=indent))
elif atype == 'go':
if selector and not param:
cmd = "self.driver.get(self.template(%r))" % selector.strip()
Expand Down Expand Up @@ -749,11 +753,11 @@ def _parse_action(self, action_config):
actions = "|".join(['click', 'doubleClick', 'mouseDown', 'mouseUp', 'mouseMove', 'select', 'wait', 'keys',
'pause', 'clear', 'assert', 'assertText', 'assertValue', 'submit', 'close', 'script',
'editcontent', 'switch', 'switchFrame', 'go', 'echo', 'type', 'element', 'drag',
'storeText', 'storeValue', 'store', 'open', 'screenshot'
'storeText', 'storeValue', 'store', 'open', 'screenshot', 'rawCode'
])

tag = "|".join(self.TAGS) + "|For|Cookies|Title|Window|Eval|ByIdx|String"
expr = re.compile("^(%s)(%s)?(\((.*)\))?$" % (actions, tag), re.IGNORECASE)
expr = re.compile("^(%s)(%s)?(\(([\S\s]*)\))?$" % (actions, tag), re.IGNORECASE)
res = expr.match(name)
if not res:
msg = "Unsupported action: %s" % name
Expand Down
6 changes: 6 additions & 0 deletions site/dat/docs/Nose.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Supported features:
- selectBy* Select value in drop down list
- submitBy* Send data of form by any its element
- scriptEval Execute JS command
- rawCode Insert python code as-is
- echoString(text) Print text string on the Nose output execution
- waitBy*
- clickBy*
Expand Down Expand Up @@ -159,6 +160,11 @@ scenarios:
- submitByName(myInputName)
- waitByID(myObjectToAppear): visible
- scriptEval("alert('This is Sparta');")
- rawCode: print('It\'s Python') # insert as-is into script file
- rawCode: |
for i in range(10): # multiline example
if i % 2 == 0:
print(i)
assert: # assert executed after actions
- contains:
- blazemeter # list of search patterns
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/modules/selenium/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def test_build_script(self):
"closeWindow('that_window')",
"submitByName(\"toPort\")",
"scriptEval(\"alert('This is Sparta');\")",
{"rawCode": "for i in range(10):\n if i % 2 == 0:\n print(i)"},
{"dragByID(address)": "elementByName(toPort)"},
"switchFrameByName('my_frame')",
"switchFrameByIdx(1)",
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/selenium/generated_from_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def test_requests(self):
self.wnd_mng.close(self.template('that_window'))
self.driver.find_element(By.NAME, self.template('toPort')).submit()
self.driver.execute_script(self.template("alert('This is Sparta');"))
for i in range(10):
if i % 2 == 0:
print(i)
ActionChains(self.driver).drag_and_drop(self.driver.find_element(By.ID, self.template('address')), self.driver.find_element(By.NAME, self.template('toPort'))).perform()
self.frm_mng.switch(self.driver.find_element(By.NAME, self.template('my_frame')))
self.frm_mng.switch(1)
Expand Down

0 comments on commit 3c655cb

Please sign in to comment.