pottapitot

Cisco ASDM Java Web Start - Autoitv3 help

3 posts in this topic

Hello all,

I just started using Autoit and I am really looking into automating many functions.

I am trying to automate the login for Cisco ASDM using Java Web Start. I have uploaded the images of the sequence of how the prompts generate during the login process.

Below is the script I have created

ShellExecute("C:\ProgramData\Oracle\Java\javapath\javaws.exe", '"https://<ip address>/admin/public/asdm.jnlp"')
WinWaitActive("[CLASS:Security Warning]", "", 10)
Send("{TAB 2}{ENTER}")

WinWaitActive("[CLASS:Authentication Required]", "", 5)
ControlSend("Authentication Required", "", "", "username{TAB}password{TAB 2}{ENTER}")

WinWaitActive("[CLASS:Security Warning]", "", 5)
Send("{TAB 3}{ENTER}")

WinWaitActive("[CLASS:Authentication Required]", "", 5)
ControlSend("Authentication Required", "", "", "{TAB 4}{ENTER}")

WinWaitActive("[CLASS:Cisco ASDM-IDM Launcher]", "", 5)
ControlSend("Cisco ASDM-IDM Launcher", "", "", "username{TAB}password{TAB}{ENTER}")

Following which it logs into the ASDM

I am not sure it there is a better way to do this. The problem I am facing here is the below

1) There is a 8th screen that looks like image 5 which can sometimes load before any of the other screens open if the other screens take time to load. The screen contains the title bar loading application and contains a progress bar. Because of this the above code will terminate early due to time delay.

2) The time it takes for each screen to load can sometimes be 10 secs (worst case) to immediate. Because of this the above code will terminate early due to time delay.

3) If I want to use the code for another ADSM, screens 2,3, 6 may not always load since it can be trusted and certificate is valid. 

How can I change the code to accomodate this? Any help would be greatly appreciated.

 
Thanks,
Pitot

1.png

2.png

3.png

4.png

5.png

6.png

7.png

Share this post


Link to post
Share on other sites



@pottapitot, welcome to AutoIt and to the forum.

unfortunately, you stumbled upon one of the caveats of AutoIt - it is very difficult and tricky to automate Java apps. there is a way surely, but i see in this article that "Cisco ASDM can run as a local application or as a Java Web Start application". if you are able to use the local application instead of the Java one, things will get a lot easier. (frankly, i think the last sentence is universally true... ;))

if you are forced to use the Java Web Start app, then what you can consider is this:

redesign your script not to wait for this or that window to appear sequentially; instead, wait for all windows in parallel, and whichever becomes active, handle it.

this covers any scenario of some windows not appearing or appearing in different order. however this, in its simple form, does not cover a scenario in which you need to handle the same window differently in different occasions. you need to handle that by "remembering" on which step of the said window process you are every time this window is being handled.

 

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@orbs Thanks for your reply. I have changed it as per your suggestion and it works for the 6 devices which I access through ASDM.

Func cisco_asdm_login($username, $password, $ip)

    Opt("SendKeyDelay", 15) ;15 milliseconds
    ShellExecute("C:\ProgramData\Oracle\Java\javapath\javaws.exe", '"https://"' & $ip & '"/admin/public/asdm.jnlp"')

    Sleep(1000)
    Local $aList = WinList()

    While 1
        ; Loop through the array displaying only visable windows with a title.
        For $i = 1 To $aList[0][0]

            Local $hWnd = $aList[$i][1]

            If $aList[$i][0] = "Security Warning" And BitAND(WinGetState($aList[$i][1]), 2) Then

                Local $aClientSize = WinGetClientSize($hWnd)

                If $aClientSize[0] = 550 And $aClientSize[1] = 219 Then
                    ControlSend($hWnd, "", "", "{TAB 2}{ENTER}")
                ElseIf $aClientSize[0] = 548 And $aClientSize[1] = 342 Then
                    ControlSend($hWnd, "", "", "{TAB 3}{SPACE}{ENTER}")
                ElseIf $aClientSize[0] = 548 And $aClientSize[1] = 311 Then
                    ControlSend($hWnd, "", "", "{TAB 2}{SPACE}{ENTER}")
                EndIf

            ElseIf $aList[$i][0] = "Authentication Required" And BitAND(WinGetState($aList[$i][1]), 2) Then
                ControlSend($hWnd, "", "", $username & "{TAB}" & $password & "{ENTER}")

            ElseIf $aList[$i][0] = "Security Information" And BitAND(WinGetState($aList[$i][1]), 2) Then

                Local $aClientSize = WinGetClientSize($hWnd)

                If $aClientSize[0] = 517 And $aClientSize[1] = 287 Then
                    ControlSend($hWnd, "", "", "{ENTER}")
                EndIf

            ElseIf StringInStr($aList[$i][0], "Cisco ASDM") > 0 And BitAND(WinGetState($aList[$i][1]), 2) Then
                ControlSend($hWnd, "", "", $username & "{TAB}" & $password & "{ENTER}")
                ExitLoop 2

            EndIf
        Next

        Sleep(1000)
        Local $aList = WinList()
    WEnd

EndFunc

 

Thanks a lot for your advice! If anyone else is looking to use this, please keep note of the windowsize.

Edited by pottapitot

Share this post


Link to post
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