AutoIT or User32 button that works intermittently

I am trying to automate application testing, and I am stuck in a problem that I am trying to fix.

The application has standard buttons for Windows, and I tried using both AutoIT and User32 DLLs to click. Sometimes buttons are pressed correctly (yay!), And sometimes they fail (boo!) - but even worse, AutoIT is convinced that he pressed the button (double-boo!), Which then generates false positives (triple-boo!). When I saw that he was convinced, I mean that he returns that the click was successful when it was not.

I run the application on Win Server 2K8, there is nothing special in this application, except that it uses MDI windows, and some of them are contained in MDI windows. Some of them, however, are not included in MDI windows (for example, the login window before the parent window is created).

Here is my order of commands:

Find the button in the window (success, always) Take the foreground window (success) Activate the window (success) Button active (success) Button focus (success) If the button is focused and the button is on, click it. (Success / Failure, unpredictable behavior. I cannot narrow down why this sometimes succeeds and why it sometimes fails ...)

Other information:

Sometimes in the order a button is clicked that should open another window. This window is closed, then the button is pressed again - and this time nothing happens. In other cases, it works as expected.

I work as an administrator, and UAC is completely disabled.

This is not a time issue, as far as I know, because I'm sure that the button is focused and on before trying to click on it, and I see that the button really focuses on it.

And, as I mentioned, I also tried this with a simple call to User32 / SendMessage, and this also fails.

Last but not least, this does not happen when I manually interact with the application. I have always had valid button presses.

Any thoughts?

UPDATE

Here's another variable for the equation that I should have mentioned - it happens in a virtual machine (because where I need to run it). I can conduct limited testing on my machine, but in order to get true testing, it must be on a virtual machine. Clicking on my own block box seems reliable, which makes it even more mysterious.

I tried this on another virtual machine and it works there too. As for the two virtual machines, they work with the same version of Windows, the same version of my application, the same version of AutoIT, etc.

I reduced it to one detail - that, as luck would have it, I won’t be able to configure myself, and I need to deposit a ticket to change any configuration. The difference in configurations is as follows:

On a virtual machine in which it does not work , the device manager displays a mouse, which is a vmware mouse. On the virtual machine in which it works The device manager displays a mouse, which is a PS / 2 mouse. Obviously, both are soft mice, but now I wonder if the VMWare mouse can act differently and make the buttons not always work. I'm not sure how likely this solution is, because, in my understanding of this, using the User32 SendMessage call doesn't actually use the mouse, but instead sends the same message that the mouse would send, but it's worth it ...

+4
source share
3 answers

You say that you successfully pressed the Focus button, so you tried to send the Spacebar event, not MouseClick ?

 Send("{SPACE}") 

(I think the syntax. I'm not a regular AutoIt)

The spatial key can usually be used to interact with most interactive controls, such as buttons and check boxes. In my experience, simulated mouse clicks and even ControlClicks much less reliable than keystrokes for strange, inconsistent reasons. My likes.

Regarding button click detection, perhaps the simplest task would be to get the button to make changes to the form that AutoIT can detect. For example, a status label that reads Ready until the user clicks a button. When the user clicks the button, the text changes to Processing . If necessary, you can make the label invisible (or placed outside the form) so that the user cannot see it, but AutoIt can.

+2
source

I simulated your case and it works 100% on Windows 7 :

 using System.Runtime.InteropServices; [DllImport("user32.dll", SetLastError = true)] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); void ClickFocusedControl() { const uint KEYEVENTF_EXTENDEDKEY = 0x1; const uint KEYEVENTF_KEYUP = 0x2; keybd_event(13, Convert.ToByte(0), KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero); //Generates a KEY_DOWN keybd_event(13, Convert.ToByte(0), KEYEVENTF_KEYUP, UIntPtr.Zero); // Generates a KEY_UP } 
0
source

You will probably be able to solve this problem by the time you post this question, but there is no good answer yet, so I will send a message:

I had the same problem on a virtual machine running Windows Server 2008 R2: I could not send a keystroke or do anything through the Win32 SendMessage API to a specific program (and its main window).

Accordingly, Q / A is a UIPI problem (which exists with Windows Vista). You should simply disable your UAC to solve this problem. I tested it and it works. Additional alternatives can be found at the link I provided.

0
source

Source: https://habr.com/ru/post/1395650/


All Articles