Automa Blog

Showing posts tagged with: automa website, Show all

Automa 1.5.1: Window switching

We just released a new version of our next generation GUI automation tool Automa. In addition to several small improvements and bug fixes, it includes a new command switch_to that lets you switch to a given window.

In its basic form, switch_to takes a string argument that identifies the window to be switched to by its title:

switch_to("Notepad")
switch_to("Chrome")

If multiple windows with a matching title exist, a WindowAmbiguousError is raised. If none exist, a WindowNotFoundError is raised.

A simple example of the basic form of switch_to is given below. It starts Notepad and the Windows Calculator, performs some calculations in the Calculator and copies and pastes the result into Notepad:

 
start("Notepad")
start("Calculator")
press(1, ADD, 2, ENTER)
press(CTRL + 'c')
switch_to("Notepad")
press(CTRL + 'v')
press(CTRL + 's')

The second form of switch_to takes a Window as its argument. This type of object is now returned by the start command:

>>> start("Calculator")
Window("Calculator")

The result Window("Calculator") tells us that a window with title Calculator was opened. If you store this object in a variable, you can switch to it later using switch_to:

calculator = start("Calculator")
 
# Perform some other operations that may switch away from Calc...
 
# Switch back to Calc:
switch_to(calculator)

Of course, if you never switch away from the windows you operate with, you do not need to use switch_to - Automa remembers the window your last command operated with and switches to it automatically, if required. switch_to is only necessary when you need to handle multiple open windows at the same time. The following example shows a case where that is necessary:

notepad_1 = start("Notepad")
notepad_2 = start("Notepad")
switch_to(notepad_1)
write("Hello World!")
press(CTRL + 'a', CTRL + 'c')
switch_to(notepad_2)
press(CTRL + 'v')

As always, you can download the current version of Automa from our download page. Since Automa does not require installation, it also doesn't require un-installation: To upgrade from a previous version, simply to download (and possibly unzip) the latest release. Happy automating! :-)

Website testing using Python and Automa

After each release, we download the newest version of Automa from our website, in exactly the same way as our users would do. We then quickly launch it to make sure everything works. We do this to make sure that the newest version of our product was deployed to the server and that it is not corrupted in any way.

The steps required to download the file can be easily automated using.. Automa! And, by using Python's unittest library, we can add some assertions to make sure that the website is working correctly and that the file was indeed downloaded. Today I quickly wrote the appropriate test script which I would like to share.

In order to start, you need to download Automa ZIP archive and extract it somewhere to your disk (for example, extract contents of Automa.zip into C:\Automa). Then edit (or add) the PYTHONPATH environment variable so that it contains the path to the library.zip file (for example,  PYTHONPATH=C:\Automa\library.zip). This allows importing and using the Automa API in your Python scripts:

from automa.api import *

Then, in any text editor (for example, notepad) you can write a test script which uses Automa's API, save it with the *.py extension and run using Python interpreter. In order to test the downloading of Automa works fine, I wrote the following test case:

from automa.api import *
from os.path import expanduser, exists, join
import unittest
 
class TestAutomaWebsite(unittest.TestCase):
    def setUp(self):
        start("firefox")
 
    def test_download(self):
        # get downloads directory
        zip_path = join(expanduser("~"), "Downloads", "Automa.zip")
        self.assertFalse(exists(zip_path ))
 
        click(Image("location.png"))
        write("http://www.getautoma.com/")
        press(ENTER)
 
        # assert that the website is up and running and has been loaded
        self.assertTrue(Image("automa_logo.png").exists)
        click("Download")
        click(Image("name_field.png"))
        write("Tytus")
        press(TAB)
        write("BugFree Software")
        press(TAB)
        write("tytus@getautoma.com")
 
        # if zip is not selected, then select it
        zip_radio_button = Image("zip_radio_button.png")
        if (zip_radio_button.exists):
            click(zip_radio_button)
        click(Image("download_button.png"))
 
        # if Firefox opens window asking what to do with the file..
        if (Image("download_window.png").exists):
            click("Save File")
            click("OK")
 
        # close the "Downloads" window
        press(ALT + F4)
 
        # make sure that the correct page is displayed
        self.assertTrue(Image("registration_complete.png"))
 
        # check that Automa.zip has been downloaded
        self.assertTrue(exists(zip_path))
 
    def tearDown(self):
        # close Firefox
        press(ALT + F4)
 
if __name__ == "__main__":
    unittest.main()

As you can see, I used multiple *.png images in the test script. With Automa, you always have the choice of using either the image-based or text-based automation. Normally, the text-based automation is preferred as it is more robust and test scripts do not break if GUI elements change visually. However, in some cases, for example when it is difficult to refer to UI elements by text (for example, when they don't have any label assigned to them), you can always fall back to *.png images. In the above script I used the following images:

location.png:location.png
automa_logo.png:automa_logo.png
name_field.png:name_field.png
zip_radio_button.png:zip_radio_button.png
download_button.png:download_button.png
download_window.png:download_window.png
registration_complete.png:registration_complete.png

In order to run the test script, I saved it together with all the images in one directory and run the python interpreter from the command prompt:

Test Run Success

And this is it! After running this automated test script I am sure that our website is up and running and that Automa.zip can be downloaded without any issues. You can try it yourself by downloading the archive below which contains the test_automa_download.py script together with all the images.

TestAutomaDownload.zip

Happy testing and automating! As always, we'd be very happy to hear what you think about our tool in the comments below :-)

Our website has moved

The first version of our website and this blog was hosted on Weebly. Weebly makes it extremely easy to create a web appearance, with several professional looking templates, good SEO support, a nice blogging integration and an extremely powerful WYSIWIG editor. However, while very easy to use due to its WYSIWIG approach, Weebly does not allow for any custom server-side functionality. Since we require such functionality for instance in our Download section, we decided to move away from Weebly to our own dedicated server. In doing so, we also changed the design of our homepage to a more corporate style - this is yet another point where Weebly did not quite fit our needs: While most of the templates it offers look very nice, they all feel more like made for private individuals rather than commercial organizations. Here's a screenshot of our old (Weebly) site:

Old Version of getautoma.com

We hope you like the change!

Automa: The Movie

It's been a while since we updated this blog, but there's a good reason and we're pretty excited about it: We've been busy preparing a first preview release of Automa and are almost finished. To shorten the final stretch of the wait and whet your appetite a little, we put a little video of Automa in action on our starting page. Do check it out and as always let us know any comments you might have either here or on our contact page :-)

Website now live!

Our website is now live and will keep evolving over the coming weeks. If you would like to know who we are, take a look at the Company. section. If you're interested Automatest, the world's smartest GUI testing tool, click on Automatest.