Automate a form which consists textboxes, dropdow, clicking checkboxes, etc in each iteration

Asked by sravani

I need to automate a form which consists textboxes, dropdown, clicking different checkboxes in each iteration using sikuli ide. i'm able to automate the textboxes with different values by reading lines from text file and performing similar action (Clicking same text box in each iteration (while running the for loop)) in the script. But my requirement is to click different images (i.e clicking different check box) in each iteration. Please suggest a solution with an example. Thank you

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

If possible, post a screenshot of the form somewhere and describe your workflow in more detail.

If not possible or wanted, you might send the information silently to my mail at: https://launchpad.net/~raimund-hocke

I will give you some hints then.

Revision history for this message
sravani (sranu3333) said :
#2

The form which I need to be tested will look like below:

First Name : Text box
Last Name : Text box
Firm : Text box
State : Dropdown box
Question : Yes [Check Box], No [Check Box]
Again some text fields........

I'm using sikuli IDE, where i'm taking images for clicking them, and automating that script through for loop
My script looks like below

test = []
f = open("C:\\test.txt","r")
for line in f.readlines(0):
    (a, b, c, d, e) = line.strip().split()
    test.append([a.strip(), b.strip(), c.strip(), d.strip(), e.strip()])
    click("1386860853482.png") ------Image of a text box
    type(a)
    click("1386860853485.png")------Image of a text box
    type(b)
    click("1386860853487.png")------Image of a text box
    type(c)
    type("\t")
    type(Key.DOWN*5) ----------------------------------Selecting an option from dropdown
    click("1386860853485.png") -------------------------------Image of a "YES" Check box
    click("1386860853488.png")------Image of a text box
    type(d)
    click("1386860853489.png")------Image of a text box
    type(e)

I'm able to automate this script with similar action like selecting same option in dropdown box and clicking one "Yes" check box. My question is when the sikuli read a line from a text file it should click "Yes Check box" and while reading some other line it should click "No image check box". Is there any way to do this like using if-else loop - while reading some lines it should click one image, and while reading some other lines it should click other image.

I have seen "https://answers.launchpad.net/sikuli/+question/238004" which looks like my requirement. But it was not clear. I'm having some questions like

Given in the Above Question: I want to be able to pass certain parameters to sikuli script such as images to be clicked on or text to be typed from a "config" file
My Question: can we store image names and text to be entered in one config file
if so where should be place our images

Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

-1. filling a form ...
should not be done by searching images if tabbing through the form is possible.
You only need to search the starting point (first field) and then go through by only tabbing.
Even the starting point might be calculated relative to some known region (e.,g. the App window or some logo or headline).
... and with tabbing instead of searching, your workflow will be much faster and more reliable.

... but if you use searching "field-images" instead of
   click("1386860853482.png") ------Image of a text box
    type(a)
this does the same:
    type("1386860853482.png", a)
because internally first the image is found, then it is clicked to get the focus and the the type takes place.

As a general advice: restrict the search region as much as possible, to make your searches faster and more robust against false positives:
w = App.focusedWindow() # the region w now is the area of the frontmost window
w.type("1386860853482.png", a) # would only search in the region w

... there are many more options to restrict the search area

--2. your script: not using the stripped values

test = []
f = open("C:\\test.txt","r")
for line in f.readlines(0):
    (a, b, c, d, e) = line.strip().split()
    test.append([a.strip(), b.strip(), c.strip(), d.strip(), e.strip()])
    click("1386860853482.png") ------Image of a text box
    type(a)

... you should use test[0] instead of a to use the stripped value

--3. your script: put the payload in a def and selecting YES or NO

def fillForm(testCase, useBoxYes = true):
    click("1386860853482.png") ------Image of a text box
    type(testCase[0])
    click("1386860853485.png")------Image of a text box
    type(testCase[1])
    click("1386860853487.png")------Image of a text box
    type(testCase[2])
    type("\t")
    type(Key.DOWN*5) ----------------------------------Selecting an option from drop down

    if useBoxYes:
        click("1386860853485.png") -------------------------------Image of a "YES" Check box
    else:
        click("image of NO checkbox.png") -------------------------------Image of a "NO" Check box

    click("1386860853488.png")------Image of a text box
    type(testCase[3])
    click("1386860853489.png")------Image of a text box
    type(testCase[4])

... and the loop (with a pythonized change for the filling of test ;-)
f = open("C:\\test.txt","r")
for line in f.readlines(0):
    test = line.strip().split()
    test = [e.strip() for e in test]
    fillForm(test) # will fill and click YES
    #fillForm(test, false) # will fill and click NO

using a def for the fill case has another advantage:
you can do manual onetime tests easily:
fillForm(("atext", "btext", "ctext", "dtext", "etext"), false)

before going in production with the file.

--3. image names as parameter
generally no problem:
where there is an image you might put a variable containing a valid image file name.

So the above decision wether to click yes or no could be done this way (supposing YES or NO as a sixth field in the file)

def fillForm(testCase):
    click("1386860853482.png") ------Image of a text box
    type(testCase[0])
    click("1386860853485.png")------Image of a text box
    type(testCase[1])
    click("1386860853487.png")------Image of a text box
    type(testCase[2])
    type("\t")
    type(Key.DOWN*5) ----------------------------------Selecting an option from drop down

    click(testCase[5]) # click the given image

    click("1386860853488.png")------Image of a text box
    type(testCase[3])
    click("1386860853489.png")------Image of a text box
    type(testCase[4])

... and the loop
f = open("C:\\test.txt","r")
imgYES = "1386860853485.png"
imgNO = "image of NO checkbox.png"
for line in f.readlines(0):
    test = line.strip().split()
    test = [e.strip() for e in test]
    if test[5] == "NO":
        test[5] = imgNO
    else:
        test[5] = imgYES
    fillForm(test)

Revision history for this message
sravani (sranu3333) said :
#5

Thanks RaiMan, that solved my question.