Jump to content

Usage of parameters to script with Adlibregister


Recommended Posts

Hi All ,

I'm new to this forum and to AutoIT as well. I'm basically testing a web application through selenium RC , using Eclipse and Java for this purpose.

I'm using AutoIt script to download and save a excel file . This script takes 2 params, title and operation, but on using this recently some of my files get corrupted and not able to open.

I'm confidently able to say that when file comes out of AutoIT it is corrupt because, I debugged till the point of just opening the 'File Download' Dialog and then saved a file manually and was able to see that the file was downloaded correctly, but trying the same with AutoIt the file was corrupted.

1) Can anyone please tell me if this ia a common issue.

2) Thinking that this problem araised because I open and close AutoIt for every testcase, this could abruptly stop the thread or so....I tried to tweak the code so that AutoIT is started at the satrt of the script and as and when it spots a File Download it has to immediately download the file and also iterating it for every 2 secs, but I was not able to do it.

I used AdlibRegister to do this.

Unable to post my code within the Code layout. Pasting below

AutoItSetOption("WinTitleMatchMode","2") ; set the select mode to select using substring

While 1

If $CmdLine[0] < 2 then

; Arguments are not enough

msgbox(0,"Error","Supply all the arguments, Dialog title,Run/Save/Cancel and Path to save(optional)")

Exit

Else

AdlibRegister("SaveDialog",2000)

EndIf

WEnd

Func SaveDialog

; wait Until dialog box appears

WinWaitActive($CmdLine[1]) ; match the window with substring

$title = WinGetTitle($CmdLine[1]) ; retrives whole window title

WinActivate($title)

If (StringCompare($CmdLine[2],"Open",0) = 0) Then

WinActivate($title)

ControlClick($title,"","Button1")

EndIf

If (StringCompare($CmdLine[2],"Save",0) = 0) Then

WinWaitActive($title)

ControlClick($title,"","Button2")

; Wait for the new dialogbox to open

Sleep(2)

WinWait("Save As")

$title = WinGetTitle("Save As")

;$title = WinGetTitle("[active]")

If($CmdLine[0] = 2) Then

;click on the save button

Sleep(1000)

WinWaitActive($title)

;ControlSetText($title,"","ToolbarWindow323","Address: Desktop")

ControlSend("$title","","ToolbarWindow323","Address: Desktop")

Sleep(1000)

Send("{Enter}")

ControlClick($title,"&Save","Button1")

$title = WinGetTitle("Export Data - Windows Internet Explorer")

sleep(2)

WinWaitActive($title)

sleep(2)

WinClose("Export Data - Windows Internet Explorer","");

Else

;Set path and save file

WinWaitActive($title)

ControlSetText($title,"","Edit1",$CmdLine[3])

ControlClick($title,"&Save","Button1")

$title = WinGetTitle("Export Data - Windows Internet Explorer")

sleep(2)

WinWaitActive($title)

sleep(2)

WinClose("Export Data - Windows Internet Explorer","");

EndIf

EndIf

If (StringCompare($CmdLine[2],"Cancel",0) = 0) Then

WinWaitActive($title)

ControlClick($title,"","Button3")

EndIf

EndFunc

Please suggest if there are any mistakes in my code and how I should make it work the way I want it to...Thanks in advance

Link to comment
Share on other sites

Why complicate matters when you can use InetGet?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thanks Alot for the reply but, InetGet as I see is actually for downloading the file directly and file is already existing in the web page.

Here the file is getting generated newly (after report has things fetched from the db).

I Actually click on a button that generates the file and then the File Download dialog appears, from which i can download.

Please let me know if there's another way to do this. Thanks again.

Link to comment
Share on other sites

What is the website exactly?

Edit: Added question mark!

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

ramasai,

You are using adlib incorrectly because:

- your registering it in a tight loop so it cannot finish an iteration before the timer is reset

- even if you fix the tight loop the adlib is not likely to finish within the iteration specified because of sleep's and dialog waits

As to the file corruption, I'm going to guess that you have multiple operations to the same file (because of the adlib problem above) and given the right sequence will corrupt the file.

A better technique would be:

- run loop to detect that the file needs to be generated

- do whatever you do to generate it

- wait till your file is generated then continue your detection loop

When you answer guiness's question you may get better/clearer advice.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...