Jump to content

Scripts stop working, run without error but don't effect window


gobane
 Share

Recommended Posts

Hello,

I've been having issues with my script using it to automatically upload files during Cucumber/Gherkin tests. The tests get to a point where the selenium web driver is able to open the file upload window and run the .exe file without issue, and the script will run without issue the first few times. Then without any changes to the tests or script, the scripts all of a sudden will be run without any errors, but won't effect the file upload window in any way. I have tried testing whether or not the script is completing with message boxes, and it will easily reach the end of the code, but will not effect the file upload window in any way. Even running the .exe by itself on a fresh chrome window won't work.

The only way to get it to work it seems is to restart my computer, and then this whole scenario will repeat itself after the test is run once or twice. The only thing I can think of is that something with selenium is getting stuck with the script running in the background, but I can't seem to see any running scripts in task manager, and the script should close either way. I added in the first two lines to try and prevent it from running duplicates, and messing up that way, but that doesn't seem to have fixed the issue.

 

$g_szVersion = "File Upload"
If WinExists($g_szVersion) Then Exit

WinWait("Open")
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1", @ScriptDir & "\small.pdf")
ControlClick("Open","","Button1")

 

Link to comment
Share on other sites

It's kinda hard to tell with such a small section of code.  Based on what you have shown id assume at some point that the first window fails to close fast enough from the previous run and the script sees it and exits.  

The only other thing I can add based on this code is that you should probably add in some safety checks and consider using a handle to these windows so they're easier to keep track of if you're on a new window or the last one...

You probably don't see it running in the task manager bc it has exited.

 

Also idk how you have your program setup but it sounds like you have one script launching another script?  I'd suggest just using one script and looping it so that the need to continuously open and close scripts is unecessary.

 

Instead of exiting try something like 

While 1
    ;do stuff create window etc
    If winexist("win") then ;start again 
    Exit loop
    Else
    ;continue 
    Endif
    Wend

Edited by markyrocks
Link to comment
Share on other sites

Unfortunately that's the entire script so there isn't more to show of it. :(

Quote

Also idk how you have your program setup but it sounds like you have one script launching another script?

What happens is that the selenium chrome driver is unable to access the file upload window during tests, so I am trying to use this script to select the PDF from a relative folder path. For example:

  1. The chrome driver selects to upload a new file, and waits 0.5 seconds
  2. The file upload window opens
  3. The chrome driver runs the .exe file, and waits 1.5 seconds
  4. The script uploads the PDF file, and ends
  5. The file upload window closes
  6. The test continues on as expected

In this particular test, this scenario happens twice in a row. I am not sure if timing is the issue here, normally this scenario plays out with no issue. At some point after running this test X amount of times, the script stops working completely, whether the test was run ten minutes after the first, or three hours.

Quote

consider using a handle to these windows so they're easier to keep track of if you're on a new window or the last one...

How would I go about trying this?

Link to comment
Share on other sites

Again it's near impossible to tell with such small amount of info.   Like what is controlling the web driver?  Are you manually opening and closing it?  With a freeze lockup type scenario I'd guess the memory from these countless scripts is probably not being cleared and its creating a leak but again this is just spitballing.   Why can't the script just continue to run while all this is happening?  That's kinda the idea behind a while loop.

Its basically waiting for an event....script says ok the event happened time to do my thing...ok now that that's done....let's wait for the next thing and so on.

 

 

Link to comment
Share on other sites

Quote

Like what is controlling the web driver? 

The tests are run in the IntelliJ IDE, using a selenium chrome driver to control the browser, written using Gherkin/Cucumber for java.

Quote

Are you manually opening and closing it? 

No, the chrome driver is controlling the browser window, and the java code is opening the script.

Quote

countless scripts

  1. The test runs (cucumber/gherkin/java code)
  2. the test opens the script (the AutoIT .exe file)
  3. the script runs (finds the PDF file)
  4. the script closes
  5. the test continues on as expected

The script itself is run once then closes, depending on how many PDF files I need. (In this case 2, so it runs twice)

Quote

Why can't the script just continue to run while all this is happening?

The form that requires the PDF cannot continue without the PDF, and the test will time out if the PDF is not uploaded.

Quote

Its basically waiting for an event....script says ok the event happened time to do my thing...ok now that that's done

Correct, but the script ends after this, and the issue I am having is that the script does not do it's thing, having worked perfectly a few minutes earlier.

 

I have found a better solution using the java code, but I don't understand why the script would all of a sudden refuse to work until I restart my PC.

Link to comment
Share on other sites

The tests manage to execute the autoIt script fine. The scripts for some reason will stop doing anything to the file upload window.

 

This is the entire script. It works, and then after running the tests a few times it stops effecting the upload window at all (no errors, runs to completion).

$g_szVersion = "File Upload"
If WinExists($g_szVersion) Then Exit

WinWait("Open")
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1", @ScriptDir & "\small.pdf")
ControlClick("Open","","Button1")

 

Link to comment
Share on other sites

you need to do error checking of each function you call. and waiting statically usually never works well or repeatedly. Use the AutoIt Info tool to find out information of your application, and use handles or other better ways to make sure you are talking to the desired control. I have a udf you might be able to use. These 2 files below can be included and you can use the AutoIt Info tool to get the information you need to call the function in the UDF

WaitForControls.au3 

log4a.au3 (logging utility needed so you can debug from console)

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Ok you're using java to quarterback this whole process.   Great.  When I say countless scripts I'm referring to the instance of autoit created.   I test a script 100x or more sometimes and I'll end up with 100x little autoit symbols in the toolbar and my computer will bog down ect.  Autoit is not very good at cleaning up after itself.   Anyways.   That's my experience yours may very.

I don't understand the problem with this?

$g_szVersion = "File Upload" 

$hwd=null
while 1

If WinExists($g_szVersion) Then
$hwd=wingethandle($_szVersion)

elseif not WinExists($hwd) then
$hwd2=WinWait("Open") 
     if $hwd2<>NULL then
         ControlFocus($hwd2,"","Edit1") ;etc
         ControlSetText("Open","","Edit1", @ScriptDir & "\small.pdf")
         ControlClick("Open","","Button1")
     endif
endif
sleep(50) 
wend
;this could probably run forever 

;untested
 

 

Youd probably want to add a hotkey exit button.  The first time thought it should enter the elseif.  2nd time get the window handle.   Then not enter the elseif again until the initial window is destroyed.   Rinse repeat.   Maybe I'm missing the point here. But I feel something like this would work more accurately than opening and closing the script.  Just open it once and it does its job forever.

 

This could obviously be cleaned up but I'm just trying to make the point and I'm on a phone etc

Edited by markyrocks
Link to comment
Share on other sites

i like this better.  I'm going to write like this more often

HotKeySet("{ESC}","exit1")
Global Const $g_szVersion = "File Upload"
Global $hwd=null


while 1
$hwd = WinExists($g_szVersion) ? 0 : WinWait("Open")
$hwd = $hwd ? WinActivate($hwd) & _RipIt($hwd) : $hwd
sleep(50)
wend

func _RipIt($hwd)
Local $focused,$setted,$clicky
    while $focused<>1 and $setted<>1 and $clicky<>1
        $focused=ControlFocus($hwd,"","Edit1") ? 1 : MsgBox('','focused','not focused',1)
        $setted=ControlSetText($hwd,"","Edit1",@ScriptDir & "\small.pdf") ? 1 : MsgBox('','setted','not setted',1)
        $clicky=ControlClick($hwd,"","Button1") ? 1 : MsgBox('','clicky','not clicked',1)
        sleep(50)
    WEnd
EndFunc

Func exit1()
    Exit
    EndFunc

 

i love how doing this is fine...

func _RipIt($hwd)
    while ControlFocus($hwd,"","Edit1") ? ControlSetText($hwd,"","Edit1",@ScriptDir & "\small.pdf") ? ControlClick($hwd,"","Button1") ? _
false : MsgBox('','clicky','not clicked',1) : MsgBox('','setted','not setted',1) : MsgBox('','focused','not focused',1)
        sleep(50)
    WEnd
EndFunc

 

but for some reason this is giving me an error but i swear it was not giving me an error b4.... hmmmm

$hwd ? WinActivate($hwd) & _RipIt($hwd) : $hwd

 

Edited by markyrocks
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...