Features

Applescript

Applescript (or osascript) is a scripting language which comes by default on macOS.
It allows for automating various (native) macOS applications and can be used in combination with Selenium WebDriver
via TestingBot's custom tb:osascript command.

In the example below, you'll find a simple Applescript example which will open Safari and enable automation.

Copy code
tell application "Safari"
launch
activate
tell application "System Events"
  set v to (value of attribute "AXMenuItemMarkChar" of
  menu item "Allow Remote Automation" of menu "Develop" of
  menu bar item "Develop" of menu bar 1 of application process "Safari")
  if v is missing value then
        click menu item "Allow Remote Automation" of
        menu "Develop" of menu bar item "Develop" of menu bar 1 of application process "Safari"
      else
        log "OK"
  end if
end tell
quit
end tell

Running Applescript during a Selenium WebDriver test

TestingBot has created a custom command, tb:osascript, which you can use to pass in your specific Applescript at any point during your (macOS) WebDriver test.

For example, you can use Applescript to automate a native dialog appearing during your test, such as a file upload dialog from the browser.

You can specify multiple different Applescripts at any point during your test. The session will wait until the script has ended, before proceeding to the other WebDriver commands.

Copy code
applescript_content = <<-EOF
 display alert "Success!"
EOF
driver.execute_script("tb:osascript", { script: applescript_content })
Copy code
String appleScriptContent = "display alert \"Success!\"";
Map<String, Object> osaMap = new HashMap<>();
osaMaposaMap.put("script", appleScriptContent);
((JavascriptExecutor) driver).executeScript("tb:osascript", osaMap);
Copy code
$osaScript = 'display alert "Success!"';
$driver->executeScript("tb:osascript", [ "script" => $osaScript ]);
Copy code
osaScriptContent = "display alert \"Success!\""
driver.execute_script("tb:osascript", {
  "script": osaScriptContent
})
Copy code
browser.execute('tb:osascript', { 
  "script": 'display alert "Success!"'
})
Copy code
((IJavaScriptExecutor)driver).ExecuteScript("tb:osascript", "{\"script\":\"display alert \"Success!\"\"}}");