Python script to automate web app flow, can be used for automated testing, playing a sequence of steps in chrome. It can also download content.
Take a look at setup/setup.txt
While testing web apps or buying some stuff over internet in a limited time or consider any web activity, a user interacts in a similar fashion. He clicks, refreshes, types some input, hits submit. So why not write these steps in plain english and let the automater execute the steps.
Well there is some syntax required for the automator to understand the command, but's its simple. Let's consider a simple task to type hello world in google search, hit enter and click on images in the results.
open google search https://www.google.com/
set search string "hello world" with xpath //INPUT[@class='gLFyf gsfi']
click search with xpath (//INPUT[@value='Google Search'])[2]
click images with xpath //A[@class='q qs'][text()='Images']
Commands and syntax:
- open
- syntax -->
open
messageurl
- message can be any string
- messages make instructions meaningful
- syntax -->
- set
- used while entering some input like username, password or search string
- syntax -->
set
messagekeyword_to_be_set
with
xpath
xpath_value
xpath
can be replaced byclass
orid
xpath_value
can be replaced byclass_value
orid_value
- click
- syntax -->
click
messagewith
xpath
xpath_value
- syntax -->
- sleep
- syntax -->
sleep
sleep_duration_in_secs
- this adds a sleep for the specified duration
- Eg. sleep 10
- syntax -->
- run
- syntax -->
run
mode
- the supported modes are headless (withput ui) and the browser
- Eg. run headless
- syntax -->
- refresh
- syntax -->
refresh
- refreshes page
- syntax -->
- APP_HOME = "/home/rishav/work/pycharmProjects/app_automation" {project home directory}
- SCRIPTS_DIR = path.join(APP_HOME, "automater_scripts") {directory to store intruction sequences}
- DOWNLOAD_DIR = "downloads" {directory to store downloaded content}
- LOGS_DIR = "logs" {directory name to save logs}
- DRIVER = 'chromedriver' {tested driver}
This plugin helps in knowing the relative xpaths of elements --> https://chrome.google.com/webstore/detail/relative-xpath-helper/eanaofphbanknlngejejepmfomkjaiic