Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ Roles are ALWAYS defined at the begining of the cases. You have to write always
18. [wait_for_page_to_load](#wait_for_page_to_load)
19. [collection_visible_for](#collection_visible_for)
20. [wait_not_visible](#wait_not_visible)
21. [execute_script](#execute_script)

## Only Browser

Expand Down Expand Up @@ -599,6 +600,23 @@ Waits until the element specified is not visible.
Id: //div[contains(text(), "http")]
Time: 10

### <a id="execute_script"></a>execute_script

Executes a specific script. For Selenium, the script value can be raw JavaScript, while for Appium, this can be the name of a defined driver script. Parameters can also be provided as an optional value.

Example for Selenium (set a console property):

- Type: execute_script
Role: role1 (Optional. if not specified will use the first one defined in the case Roles)
Value: window.localStorage.logLevel = '0'

Example for Appium (launch Chrome on Android)

- Type: execute_script
Role: role1 (Optional. if not specified will use the first one defined in the case Roles)
Value: "mobile: launchApp"
Params: { appId: com.android.chrome }

## Only Browser

### <a id="clear_field"></a>clear_field
Expand Down
4 changes: 4 additions & 0 deletions lib/core/case_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ def log_step(role, action)
log_info("Role: '#{role}', Action: '#{action["Type"]}', " +
"Coords: Start -> X:'#{action["StartX"]}', Y: '#{action["StartY"]}' - " +
"End -> X:'#{action["EndX"]}', Y: '#{action["EndY"]}'")
elsif action["Type"] == "execute_script" && action.key?("Params")
log_info("Role: '#{role}', Action: '#{action["Type"]}', " +
"Value: '#{convert_value(action["Value"])}', " +
"Params: '#{convert_value(action["Params"])}'")
else
if action["Strategy"] && action["Value"]
log_info("Role: '#{role}', Action: '#{action["Type"]}', " +
Expand Down
16 changes: 16 additions & 0 deletions lib/core/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@ def update_settings(action)
@driver.update_settings(convert_yaml(action["Value"]))
end

# executes a custom script, which can be either raw JavaScript code (for browsers)
# or the name of a defined driver script. Parameters can also be provided
# Accepts:
# Value
# Params
def execute_script(action)
script_command = convert_value(action["Value"])
if action.key?("Params")
raw_params = action["Params"]
params = raw_params.is_a?(Hash) ? convert_yaml(raw_params) : convert_value(raw_params)
@driver.execute_script(script_command, params)
else
@driver.execute_script(script_command)
end
end

# starts recording test execution. Whole desktop is recorded if 'udid' is not
# set.
# Accepts:
Expand Down