sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #22861
Re: [Question #241041]: Automate a form which consists textboxes, dropdow, clicking checkboxes, etc in each iteration
Question #241041 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/241041
RaiMan proposed the following answer:
-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)
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.