Skip to content

Instantly share code, notes, and snippets.

@dandydanny
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save dandydanny/240652d42daec8933e38 to your computer and use it in GitHub Desktop.

Select an option

Save dandydanny/240652d42daec8933e38 to your computer and use it in GitHub Desktop.
AutoIt3 Script to aid manual testing of SV2 Surveys
;Script Name: SV2 Flex Survey Filler
;Author: Daniel Lu
;Dependencies: AutoIt 3
; Windows 7, 1280x960 resolution, Windows Classic Theme
; Mozilla Firefox
;Version History: 0.5 - Added variable for governing transition wait time and mouse speed
; 0.4 - Added systray balloon tips to show script execution state
; 0.3 - Added image capture
; 0.2 - Replaced some hard-wired timers with color
; comparison for detecting slide change
; 0.1 - Initial release
#include <ScreenCapture.au3>
#include <Date.au3>
;Globals hellz yeah
Global $snapDir = "snaps\"
Global $browserPath = "C:\Program Files\Mozilla Firefox\firefox.exe"
Global $surveyUrl
Global $pixelColor
Global $pixelColor1
Global $pixelColor2
Global $keyStrokeDeplay = 100
Global $sliderBlue = 4880534
Global $bgGrey = 8882055
Global $containerWhite = 16185078
Global $pureWhite = 16777215
Global $buttonYellow = 15585335
Global $sliderStart = 640
Global $sliderEnd = 850
Global $mouseSpeed = 1
Global $smallDelay = 100
Global $transitionDelay = 500
;Press ESC to terminate script
HotKeySet("{ESC}", "EscTerminate")
$surveyUrl = InputBox( "SV2 Flex Survey Helper", "Please enter survey URL (without trackerID):", _
"http://sv2a-qacore.foodomain.com/service01/survey-app.html?t=kFRXoAq&p=pnt&trackerId=")
;Respondent #5 --------------------------------------------------------
Local $respondentNumber = "1005tn"
Local $intender = True
Local $covey = False
Local $coveyFollowOn = False
Local $surveyUrlWithNumber = $surveyUrl & $respondentNumber
Local $verbatimString = "FiveMaleEightythreeLowincomeAsianNochildren"
Local $brandRecString = $verbatimString & $respondentNumber
Local $zipTag = 90000 + $respondentNumber
Shellexecute($browserPath, $surveyUrlWithNumber)
;continue only if demo question page is shown
;checking for grey background and off-white container
While 1
;MouseMove(300,710,$mouseSpeed)
$pixelColor1 = PixelGetColor(300,710)
;MouseMove(430,710,$mouseSpeed)
$pixelColor2 = PixelGetColor(430,710)
If ($pixelColor1 = $bgGrey) and ($pixelColor2 = $containerWhite) Then
ExitLoop
EndIf
Wend
Sleep($transitionDelay) ;allow for tranisition to complete
;Demographic Questions Page
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "a1 - Demographic questions", 10, 1)
;Male
MouseMove(351,269,$mouseSpeed)
Sleep($smallDelay)
MouseClick("left",351,269,2)
MouseMove(351,364,$mouseSpeed) ;move mouse into next position
Sleep($smallDelay)
;1983
MouseClick("left",351,364,1)
Sleep($keyStrokeDeplay)
Send("{PGDN 6}")
Sleep($keyStrokeDeplay)
Send("{DOWN 2}")
Sleep($keyStrokeDeplay)
Send("{ENTER 1}")
MouseMove(351,430,$mouseSpeed) ;move mouse into next position
Sleep($smallDelay)
;Low Income
MouseClick("left",351,430,1)
MouseMove(351,550,$mouseSpeed)
Sleep($smallDelay)
;Ethnicity (Asian)
MouseClick("left",351,550,1)
Sleep($keyStrokeDeplay)
Send("{DOWN 4}")
Sleep($keyStrokeDeplay)
Send("{ENTER 1}")
MouseMove(351,618,$mouseSpeed) ;move mouse into next position
Sleep($smallDelay)
;No Children
MouseClick("left",351,618,1)
Sleep($keyStrokeDeplay)
Send("{DOWN 2}")
Sleep($keyStrokeDeplay)
Send("{ENTER 1}")
MouseMove(351,684,$mouseSpeed) ;move mouse into next position
Sleep($smallDelay)
;Zip Code
MouseClick("left",351,684,1)
Sleep($keyStrokeDeplay)
Send($zipTag)
Sleep($smallDelay)
MouseMove(894,715,$mouseSpeed)
;Demographic response screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-a1.png")
;Go on button
MouseClick("left",894,715,1)
Sleep($transitionDelay)
;Instructions Page---------------------------------
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "a2 - Survey instructions", 10, 1)
;Check if instruction page is ready by checking slider color = light blue
MouseMove(610,220,$mouseSpeed)
While 1
$pixelColor = PixelGetColor(610,220)
If $pixelColor = $sliderBlue Then
ExitLoop
EndIf
Wend
MouseClickDrag("left",$sliderStart,225,$sliderEnd,225,$mouseSpeed)
;Instructions screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-a2.png")
;Next button
MouseMove(894,647,$mouseSpeed)
Sleep($smallDelay)
MouseClick("left",894,647,1)
Sleep($transitionDelay)
;Video Page-----------------------------------------
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "a3 - Video page", 15, 1)
;Wait for yellow play button to become visible
$proced = False
While 1
$pixelColor = PixelGetColor(680,380)
If $pixelColor = $buttonYellow Then
ExitLoop
EndIf
Wend
;Play button
Sleep(1000) ;wait for video to become ready
MouseMove(628,324,$mouseSpeed)
MouseClick("left",628,324,2)
Sleep(2000)
;Video page screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-a3.png")
;First set-----------------------------------------
;Check if first set page is displayed by checking location
;occupied by volume slider is no longer white
;=========================================================================aqui
MouseMove(850,525,$mouseSpeed)
$proced = False
While 1
$pixelColor = PixelGetColor(850,525)
If $pixelColor <> $pureWhite Then
ExitLoop
EndIf
Wend
;Enough delay to allow for page transition to complete
Sleep($transitionDelay)
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "a4 - Syndicate questions (first set)", 10, 1)
MouseMove(640,195,$mouseSpeed)
MouseClickDrag("left",$sliderStart,195,$sliderEnd,195,$mouseSpeed)
Sleep($smallDelay)
MouseClickDrag("left",$sliderStart,320,$sliderEnd,320,$mouseSpeed)
Sleep($smallDelay)
MouseClickDrag("left",$sliderStart,440,$sliderEnd,440,$mouseSpeed)
MouseMove(900,525,$mouseSpeed)
Sleep($smallDelay)
;First set screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-a4.png")
;Next button
MouseClick("left",900,525,1)
Sleep($transitionDelay)
;Second set-----------------------------------------
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "a5 - Syndicated questions (second set)", 10, 1)
MouseMove(640,195,$mouseSpeed)
MouseClickDrag("left",$sliderStart,195,$sliderEnd,195,$mouseSpeed)
Sleep($smallDelay)
MouseClickDrag("left",$sliderStart,320,$sliderEnd,320,$mouseSpeed)
Sleep($smallDelay)
MouseClickDrag("left",$sliderStart,440,$sliderEnd,440,$mouseSpeed)
MouseMove(900,525,$mouseSpeed)
Sleep($smallDelay)
;Second set screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-a5.png")
;Next button
MouseClick("left",900,525,1)
Sleep($transitionDelay)
;Third set-----------------------------------------
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "a6 - Syndicated questions (third set) + verbatim", 10, 1)
MouseMove(640,195,$mouseSpeed)
MouseClickDrag("left",$sliderStart,195,$sliderEnd,195,$mouseSpeed)
MouseMove(350,300,$mouseSpeed) ;move mouse into next position
Sleep($smallDelay)
MouseClick("left",350,300,1)
Sleep($smallDelay)
MouseMove(350,540,$mouseSpeed) ;move mouse into next position
MouseClick("left",350,540,2)
Sleep($keyStrokeDeplay)
Send($verbatimString)
MouseMove(900,600,$mouseSpeed)
Sleep($smallDelay)
;Third set screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-a6.png")
;Next button
MouseClick("left",900,600,1)
MouseMove(351,136,$mouseSpeed)
Sleep($transitionDelay)
;Personal Experience--------------------------------
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "a7 - Persoal experience + brand recognition", 10, 1)
MouseClick("left",351,136,1)
MouseMove(345,335,$mouseSpeed) ;move mouse into next position
Sleep($smallDelay)
MouseClick("left",345,335,2)
Sleep($keyStrokeDeplay)
Send($brandRecString)
MouseMove(900,525,$mouseSpeed)
Sleep($smallDelay)
;Personal experience screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-a7.png")
;Next button
MouseClick("left",900,525,1)
MouseMove(351,153,$mouseSpeed) ;move mouse into next position
Sleep($transitionDelay)
;Intender-----------------------------------------
IF $intender = True THEN
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "i1 - Intender", 10, 1)
MouseClick("left",351,153,1)
MouseMove(900,525,$mouseSpeed)
Sleep($smallDelay)
;Intender screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-i1.png")
;Next button
MouseClick("left",900,525,1)
Sleep($transitionDelay)
EndIf
;Capcha-----------------------------------------
;Display Systray Balloon Tip
TrayTip("SV2 Survey Helper", "c1 - Captcha (match number using slider, then click next)", 10, 1)
MouseMove(635,342,$mouseSpeed)
;Captcha screenshot
_ScreenCapture_Capture($snapDir & $respondentNumber & "-c1.png")
sleep(5000)
;TODO: implement OCR
Func EscTerminate()
MsgBox(0, "Terminate", "Script terminated. Press OK to close the opened browser window.")
WinClose("AMx :: Survey2 :: App - Mozilla Firefox")
Exit
EndFunc ;==>Terminate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment