Automating a Standalone Java AUT and a Web Browser From a Single Test Case

Last edited on

Introduction

This article explains the necessary steps for automating a web browser and a Java desktop application from the same test case.

Custom-builds of Squish Java+Web

If you want to automate a Java stand-alone application in addition to a web browser, we recommend that you ask for a custom build of Squish for Web+Java. This build will have support for browser configurations in server settings, as well as AUT configuration in the Test Suite settings, and you can request a 64-bit or 32-bit build to match your installation of Java properly.

Creating a Java test suite

In our first example, we create a test suite that is for the Java toolkit (we have to choose one). Generally, you must store the application context of each AUT so that you can switch back to it later. Switching application contexts is done with setApplicationContext().

Also, before starting the second application we wish to automate, since it is using a different toolkit from the test suite, it is necessary to call testSettings.setWrappersForApplication() on it. In the case of web applications, the name of the web browser application is __squish_webhook.

For example in a Python script:

def main():

    # Save the context for later
    ctx_java = startApplication("AddressBookSwing.jar")
    # Automate Java application here
    clickButton(waitForObject(names.address_Book_JButton))
    mouseClick(waitForObjectItem(names.open_JList, "MyAddresses.adr"), 50, 8, 0, Button.Button1)
    doubleClick(waitForObjectItem(names.open_JList, "MyAddresses.adr"), 50, 8, 0, Button.Button1)
    #...

    testSettings.setWrappersForApplication("__squish__webhook", ["Web"])
    ctx_web = startApplication("__squish__webhook")
    startBrowser("https://www.froglogic.com")
    # Automate Web application here
    activateBrowserTab(waitForObject(names.automated_GUI_Testing_and_Code_Coverage_froglogic_BrowserTab))
    mouseClick(waitForObject(names.automated_GUI_Testing_and_Code_Coverage_froglogic_Squish_A))
    #...

    # Switch back to the java context
    setApplicationContext(ctx_java)
    mouseClick(waitForObjectItem(names.address_Book_MyAddresses_adr_JTable, "10/1"), 83, 5, 0, Button.Button1)
    # ...

    # Switch back to the web context:
    setApplicationContext(ctx_web)
    mouseClick(waitForObject(names.automated_GUI_Testing_Squish_GUI_Tester_froglogic_img_src_https_www_froglogic_com_wp_content_uploads_2020_07_icon_editions_svg_class_menu_image_menu_image_title_after_alt_Editions_A))
    # ...

Now, by placing breakpoints in the right spot, you can record snippets on your java or your web application.

Creating a web test suite

If the test suite is created for the web toolkit, then we must call testSettings.setWrappersForApplication() on the standalone Java application. We can obtain and save the ctx_web = currentApplicationContext() after we call startBrowser().

def main():
    startBrowser("www.froglogic.com")
    ctx_web = currentApplicationContext()
    # automate web application here
    mouseClick(waitForObject(names.automated_GUI_Testing_and_Code_Coverage_froglogic_confirm_cookies_DIV), 75, 32)
    mouseClick(waitForObject(names.automated_GUI_Testing_and_Code_Coverage_froglogic_Squish_A))
    mouseClick(waitForObject(names.automated_GUI_Testing_Squish_GUI_Tester_froglogic_img_src_https_www_froglogic_com_wp_content_uploads_2020_07_icon_features_svg_class_menu_image_menu_image_title_after_alt_Features_A))
    mouseClick(waitForObject(names.squish_GUI_Tester_Features_BDD_Visual_Verifications_Hybrid_froglogic_Behavior_Driven_Development_BDD_Testing_A))

    testSettings.setWrappersForApplication("AddressBookSwing.jar", ["Java"])
    ctx_java = startApplication("AddressBookSwing.jar")

    # automate Java application here:
    clickButton(waitForObject(names.address_Book_JButton))
    mouseClick(waitForObjectItem(names.open_JList, "MyAddresses.adr"), 37, 8, 0, Button.Button1)
    doubleClick(waitForObjectItem(names.open_JList, "MyAddresses.adr"), 37, 8, 0, Button.Button1)


    setApplicationContext(ctx_web)
    mouseClick(waitForObject(names.behavior_Driven_Development_BDD_Testing_froglogic_Recording_and_Playback_A))
    # do more testing against the web page
    # ...

    setApplicationContext(ctx_java)
    mouseClick(waitForObjectItem(names.address_Book_MyAddresses_adr_JTable, "10/1"), 145, 14, 0, Button.Button1)
    # Do more testing against the Java AUT
    # ...

Further information