0

I am trying to write a test on python on Squish IDE to test a QT application. I was able to record the test using Squish , but i am not sure how to write the same by hand ?

Below is the recorded test

def main():
    startApplication("hmi")
    mouseClick(waitForObject(":Setup_Text"), 18, 5, 0, Qt.LeftButton)
    activateItem(waitForObjectItem(":_QMenu", "Monitor setup       X"))
    mouseClick(waitForObject(":_Rectangle"), 33, 31, 0, Qt.LeftButton)
    activateItem(waitForObjectItem(":_QMenu", "ECG                X"))
    mouseClick(waitForObject(":_Rectangle_2"), 65, 66, 0, Qt.LeftButton)
    sendEvent("QCloseEvent", waitForObject(":_QDeclarativeView"))

5 Answers 5

2

Personally I use classes to define PageObjects (taking the idea from cucumber/selenium), wrappers to define the functions of widgets and decorators for login in and loading the module to be tested. this gives maximum re use of code and minimal maintenance overhead.

It also means that tests can be created prior to any code being written, as long as devs understand to name widgets sensibly and pre define them.

from globals.widgets.QPushButton import QPushButtonWrapper # simple click functions
from globals.toolbars.sometoolbar import SomeToolBar

class SomeFormPO(PageObject): #PageObject has some "lazy ok and cancel methods"

    def __init__(self):
        name = <symbolic name>
        PageObject.__init__(self, name)

        self.some_tool_bar = SomeToolBar() # contains defines for toolbar e.g.
         #  self.some_button = QPushButtonWrapper(<symbolic name of button>)
        

then in your test:

from globals.path.login.login import LoginDecorator
from globals.path.pages import SomeFormPO


def main():
    """
    sensible test details

    """
    log_docstring(main)
    run()


@LoginDecorator
def run():

    some_form = SomeFormPO()

    test.verify(some_form.visible(), "some form is visible")
    some_form.some_tool_bar.some_button.click()
    

This is not the place to fully describe the methods, however you if read :-

you will gain an understanding of the principles used.

Sign up to request clarification or add additional context in comments.

Comments

1

You'll need to set a breakpoint after the startApplication line. Put a snooze(5) right under it.

Once the program breaks, after a few seconds the Application Objects window will populate with the object map/hierarchy. From this hierarchical structure, you access objects in a linear manner. Every time you expand an object to see it's children, that's one level deeper.

Example, let's say I'm looking at the Application Objects window and all I see is a clickable right-pointing arrow labeled: -> MainDeclarativeView

Then I click on it and it expands:

| MainDeclarativeView

-> SomeButton

I access SomeButton and its properties like so:

myButton = findObject(":MainDeclarativeView.SomeButton")

Note the colon in front of MainDeclarativeView and the period specifying that SomeButton is a child object of MainDeclarativeView. Now, if you do:

mouseClick(myButton)

You will click it. You can also put a waitForObject in as the parameter to findObject, then put the ":Main...." within the waitForObject, but in my experience it hasn't made a difference. If the object can't be seen in the Application Objects menu, it can't be found and assigned to a variable as an object.

From this point on, you can access SomeButton's properties through myButton, e.g.

showMeX = myButton.x

Hope that helps

Comments

0

Use screenshot verification points to help you identify what is what. They will (eventually) populate in a separate tab on the Spy page if you click on an object's checkbox in the application objects window.

1 Comment

Personally I would avoid screen shot verification points, these are fundamentally 'brittle'. Any change in the UI will 'break' the test.
0

You can also inspect elements and get their real/symbolic names. This is (easy spoken) the way Squish identifies the objects.

To inspect elements you pause your running test. Squish IDE will open again and in the upper right corner you find the tab Test Debugging. Switch into this view and you will find the Application Objects in the lower left corner. With pressing a checkbox the selected object will be displayed. You can also right-click on the object and copy the real/symbolic name.

When you select an object you can also read its properties and methods. Usually it is displayed in the window right next to Application Context.

Comments

0

you can write it on your own,

Inside Start application enter your application name in line 1, in line 2 - remove the (18, 5, 0, Qt.LeftButton). It will be like this:

startApplication("hmi")
mouseClick(waitForObject(":Setup_Text"))

Explore the squish API available on the web. You can write it on your own.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.