Website Testing using Python

In order to run this example, you need to integrate Automa into Python. It is real easy! Simply follow the steps described here.

The following code can be used to test whether downloading Automa from our website works fine. Note that you need the Firefox browser in order to run it:

from automa.api import *
from os.path import expanduser, exists, join, pardir, getsize
import unittest
 
class TestAutomaWebsite(unittest.TestCase):
    def setUp(self):
        start("Firefox", '-safe-mode', '-new-window', "http://www.getautoma.com")
        click('Start in Safe Mode')
 
    def test_download(self):
        # get downloads directory
        automa_zip_path = join(expanduser('~'), 'Downloads', 'Automa.zip')
        self.assertFalse(
            exists(automa_zip_path),
            'Please move Automa.zip from your Downloads directory to a '
            'different location.'
        )
 
        # assert that the website is up and running and has been loaded
        wait_until(Image("automa_logo.png").exists, timeout_secs=10)
        self.assertTrue(Image("automa_logo.png").exists())
        click("Download")
 
        Config.auto_wait_enabled = False
        write("John", into="Name")
        press(TAB)
        write("BugFree Software")
        press(TAB)
        write("john@getautoma.com")
        press(TAB, TAB, TAB)
 
        # if zip is not selected, then select it
        zip_radio_button = RadioButton("ZIP")
        if not zip_radio_button.is_selected():
            click(zip_radio_button)
 
        Config.auto_wait_enabled = True
        click("Accept and download")
 
        # if Firefox opens window asking what to do with the file..
        download_dialog = Window("Opening Automa.zip")
        wait_until(
            lambda: download_dialog.exists() 
                 or Text("Registration Complete").exists(), 
            timeout_secs=10
        )  
 
        if download_dialog.exists():
            switch_to(download_dialog)
            click("Save File")
            click("OK")
 
        # make sure that the correct page is displayed
        self.assertTrue(Text("Registration Complete").exists())
 
        # check that Automa.zip has been created
        self.assertTrue(exists(automa_zip_path))
 
        # wait for the download to finish
        wait_until(lambda: getsize(automa_zip_path) != 0)
        press(CTRL + 'j')
        wait_until(lambda: not Text('Scanning for viruses').exists())
        press(ALT + F4)
 
    def tearDown(self):
        # close Firefox
        click("Firefox", "Exit")
 
if __name__ == '__main__':
    unittest.main()
TestAutomaDownload.zip

Images used:

automa_logo.png:

To run the test script, download the above .zip file and unpack it to some directory, say C:/DownloadTest. Provided you have integrated Automa into Python as explained here, you can then run the example script using the python executable from the Windows command prompt: