Jump to content

Outstanding tool... and a simple question.


Recommended Posts

Hi guys!

I found this tool just a few days ago and all I can say is that so far, so awesome!

I work with a DB administration tool and I was proposed the task of finding some way to automate it. I already have Selenium IDE & RC Scripts as well as JMeter for the performance aspect, but the idea is to have something more visual for the support guys to see as it goes.

I did my first steps with many tools like this one, but somehow I feel more comfortable with AutoIt so I intend to spend some time on getting something done to show off ;)

Onto the help side of the post...

I am currently working with the ImageSearch feature I found in another thread. I am able to search for a browser icon, I am able to search for the Maximize button of the browser and I am also able to locate the DB sign in 'widget'. That was so until past friday.

Today I found out that my script (a really ugly, drafty script) does not work. After using the historically renowned debugging method: Messageboxes! I realized the script is just fine and that the problem is in my screen captures.

I am not using the Tolerance parameter because I want exact matches (DB fields will not move neither change colors), but how crazy would someone be if he states that "the video card shows a very slightly different color tone from day to day"?

Thanks in advance!!

P.S.: I just captured a new image set and the script works like a charm again!

Link to comment
Share on other sites

You can search for a color range but maybe a better way is to simply ID the control you are dealing with. If you are working with Internet Explorer there is IE.au3 that can do many of the jobs you are currently using a "pixel search then click" method. Look in the help file and you can find many examples of what to do.

Link to comment
Share on other sites

Thanks for the heads up, Scullion!

Although Internet Explorer is a 'no no' for the guys I work with (which I can't say I'm against that policy), I did check the UDF you pointed me to.

It seems that it is not that far from Selenium. What is more, I could see some sort of xpath-like to click on links and it's using some HTML tag properties as 'locators'. I will further check this file, as it seemed interesting in any case :)

As to my original question, perhaps I should have added that one of the ideas is for the guys that will use the tool to create their own tests by simply adding or renaming some image assets.

And what concerns me is the odd result from one day to the next without changing the script or the images ;)

Thanks again!

Link to comment
Share on other sites

Internet Explorer is built into Windows, Windows Explorer is just another version of IE running on your hard drive instead of the internet.

While IE has it's problems, it's also the only browser on Windows that allows you to interact with it directly without a 3rd party app, so discounting the use of the IE.au3 functions, just because they use Internet Explorer, is just going to cause you to do far more work to do the same thing.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You can use FF.au3 for firefox. I've found IE.au3 much easier to work with however.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Thank you guys!

I got the point regarding the features in IE.au3 (it's granted I'll look at FF.au3) and its ease of use but my concern was about why would ImageSearch not find an image from one day to the next :P

Of course, I will assess the advantages of your solution, but as an ex-developer and pseudo IT-guy I need to know what's wrong with ImageSearch xD

Edit: I'm really sorry if the above sounds kind of harsh. English is not my main language :(

Edited by leansoli
Link to comment
Share on other sites

Sure I'll post the code below. What happened was that on last Friday, the below script would find "maximizechrome.bmp" and on monday I had to screen-capture "maximizechrome2.bmp" for it to work.

I'll check the tolerance parameter and play with it. My best guess is that it performs a pixel-to-pixel substraction, thus ending with a matrix of integer values per pixel and then decide whether the tolerance is OK.

Here is my very first attempt with the ImageSearch feature:

msgbox(0, "Screen Resolution", "The current Screen Resolution is: " & @DesktopWidth & " * " &@DesktopHeight)

$Search = _ImageSearch("chrome.bmp", 0, $x, $y, 0)
if $Search = 1 Then
;mousemove($x, $y, 20)
MouseClick("left",$x, $y, 2)
;Wait 5 seconds for Chrome to load - ToDo: Check for windows activation rather than just a timer.
sleep(5000)
EndIf

;Then maximize the window.
$Search = _ImageSearch("maximizeChrome.bmp", 0, $x, $y, 0)
if $Search = 1 Then
MouseClick("left",$x, $y, 1)
sleep(300)
Else
msgbox(0, "Maximizar Chrome", "Not found!")
EndIf

Here are the images I am using (please note that the file extension has been switched to PNG by the Image repository upload process whereas I have BMP files):

Chrome Icon:

Posted Image

Chrome Maximize button 1:

Posted Image

Chrome Maximize button 2:

Posted Image

Thanks!

Link to comment
Share on other sites

Couldn't you just do this?

Opt("wintitlematchmode", 2)
$handle = WinGetHandle("- Google Chrome")
WinSetState($handle, "", @SW_Maximize)

Or this?

Run("Path to wherever chrome.exe is", "", @SW_MAXIMIZE)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Indeed, I discovered the run command yesterday and I also tried the @SW_MAXIMIZE feature to no avail (although my code did not include that Opt sentence). It could open Chrome, but not maximize it.

I'll check on that Opt sentence later on.

What's a 'handle'? Where can I get some insight into them? (it's been several years since I do not code :/)

Thanks!!

Link to comment
Share on other sites

Indeed, I discovered the run command yesterday and I also tried the @SW_MAXIMIZE feature to no avail (although my code did not include that Opt sentence). It could open Chrome, but not maximize it.

I'll check on that Opt sentence later on.

What's a 'handle'? Where can I get some insight into them? (it's been several years since I do not code :/)

Thanks!!

Say you create a GUI with GUICreate(), and the code was:

$hGui = GUICreate( "test", 100, 100 )

$hGui would be the handle. You can then use the handle to interact with the GUI, such as

GUISetState( @SW_SHOW, $hGui ) would make $hGui appear

GUISetState( @SW_HIDE, $hGui ) would make $hGui disappear

Edited by caleb41610
Link to comment
Share on other sites

A handle is the absolute identifier to an object (in your case a window). Every object is assigned a handle in order to manipulate it. To figure out the handle of a window, you can use a function like WinGetHandle().

A handle is also unique. There will never be another object with the same handle.

It's important to understand the above statement because when dealing with windows that may change its title (such as chrome, firefox, ie, etc), you can retrieve its handle and never have to worry about figuring out what the new title might be.

For example:

Opt("WinTitleMatchMode", 2) ; Performs a string-in-string type searching for window titles
ShellExecute("iexplore.exe")
WinWait("Windows Internet Explorer")
Sleep(3000)
$hWin = WinGetHandle("Windows Internet Explorer") ; gets the handle to an open IE window
WinSetState($hWin, "", @SW_MINIMIZE) ; The handle is used in the place of the 'title' parameter for any function that uses 'title'.
WinSetState($hWin, "", @SW_MAXIMIZE)
msgbox(0,"",WinGetTitle($hWin) & @CRLF & WinGetState($hWin))
Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Crystal clear, guys!

I'll read about them on Wikipedia (which article was, at first glance, suspiciously short :/) or any other source I can find. But the examples you provided were straight to the point.

Are handles part of the implementation of a given software or are they part of windows/nix*? In other words, if I ever code an app., would I have to think about supporting them?

Thanks once again!

Link to comment
Share on other sites

Handles are built and managed by Windows.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

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...