I am looking to start automated regression testing on a fairly large Excel add-in that revolves around a GUI composed of a few modal UserForms with standard controls.
The main problem is that most of the automated testing tools I have looked into (Rational Robot, AutomatedQA TestComplete, Network Automation Automate etc) don't fully support the VBA controls so their tests end up replaying mouse clicks and key presses, so aren't really maintainable. Ideally I need a testing tool that recognises the VBA form controls, so I can say "press this button and wait for this listbox to change" rather than "click at (237, 58) and wait 500 milliseconds".
I also considered building the test automation into the add-in as VBA, but most of the user's time is spent interacting with a modal dialog which stops the VBA running in the background, so that's pretty much out of the question.
My question- does anyone here have any experience with an automated testing tool that
a) recognises VBA user form controls and can reliably interact with them
b) has support for test scripting with conditional branches and success/failure logging, rather than just record and playback?
Alternatively, does anyone know of a way I can get around the problem of modal dialogs pausing VBA execution so I can drive the add-in from within VBA?
I've spent a while looking around QA forums but haven't found anything there, so any help or leads would be appreciated.
Thanks for your help,
-Martin
I don't know of a tool that does what you say, but have you thought about attacking from a different direction?
I'm speculating a little here about how much of the logic in the could be pushed down into a "normal" VB/VBA Class in such a way that individual methods could be unit-tested. Perhaps such a Class might expose events, even, so that for testing you could replace the form with a test harness that provided the necessary stimuli and collected the responses for checking.
It wouldn't address the hookup of the (now very lightweight) form itself to the underlying class, but it would at least minimise the untested area.
I'm really just thinking "out loud", but do you think that would work at all?
Related
is it possible to run photoshop action from vba? if it is, how?
If the remote process supports some kind of IPC, or you can use parameters on start to execute your request, then yes.
As far as I know, Photoshop does support COM indetop, thus you should be able to automate it from VBA. However, there can be limitations compared to GUI manipulation. Check this document: https://www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-scripting-guide-2019.pdf especially the chapter Viewing Photoshop's type library on page 22, but actually the whole document is the answer to your question.
My company is using this program called Visma Contracting. This program is used to type inn a product number (example: 10 240 75) and how many of this item was used (example: 4). So these numbers we (me and my co-workers) put into an excel sheet and deliver to the guy in charge of the systematizing these (A column being product number, an B column being the used amount). From there it is retyped from excel to Visma. This is madness! There must be a way for the two programs to talk to each other? I have talked to the Visma support and they are giving me nothing else then a no. I wish i could give more info about this Visma stuff, but i fear that it is a locked program. I have also been searching around for a 3rd party software that can eliminate this massive annoying problem, with no luck. Does anyone have anything that might ease my itch?
Thanks in advance!
Sounds impossible but...
If you want to try blind keystrokes check out Mouse and Keystroke Recorder I have some experience automating stuff with this program. It works sometimes with varying degrees of reliability.
Be forewarned that nobody recommends this as it could cause problems. It simply plays back keystrokes without being aware of what it is doing. When used with care it can work but it could be dangerous.
Or use SendKeys from Excel VBA; that might work better as the data is already in Excel. But the same warnings apply. Use at your own risk.
I have recorded a set of actions on a UI with the integrated Coded UI Test Recorder. It works kind of nice.. actually, right now I am going through the code and adding some polling for .Enabled and recently found the .TryGetClickablePoint which seems to be really useful. So it looks like recording is a breeze now (with those few polls to be added to get the timing right).
One thing that is a typical use case of the GUI is using the mouse wheel (for interacting with a zoomable image like in google maps). It seems like those are not captured.
I could manually generate those events, but would be far off from reproducing the actual behavior during recording with manually guessing the extent of the scrolling.
Is there some integrated way?
Would I have to capture the events myself with some external/selfmade tool to at least get an idea of how many ticks I made?
For stuff like this I'd recommend using the API directly for your test. You can use the Mouse.MoveScrollWheel method for this. You might have to experiment a little to get the number of ticks right.
I want to code a trading bot for Magic: The Gathering Online. This bot should wait until someone offers to trade, accept, look through the cards available from the other trader (the information is shown on screen), and perform other similar functions. I have several questions:
How can it know that someone is offering a trade?
How can it know that the other trader has some card (the informaion is stored in pictures)?
I just cannot imagine right now how to do it, I have no experience with it, until now I've been coding only console programs for my physics neŃessities.
First, you should note that some online games forbid bots, as they can give certain players unfair advantages. The MTGO Terms of Service do not seem to say anything about this, though they do put restrictions on anything that might negatively impact the service. They have also said that there is a possibility they will add an API in the future, so they don't seem to be against the idea of automation, but are not supporting it at the moment. Tread carefully here, but it looks like it should be OK to write a bot as long as it is not harmful or abusive. This is not legal advice, and it would be a good idea to ask the folks who run MTGO for permission. edit since I wrote this, it has been pointed out that there are lots of bots already, so there should be no problems writing bots.
Assuming that it is not forbidden by the terms of service, but they do not have an API, you will have to find a way to detect what's going on, and control the game automatically. There's a pretty good series of articles on writing poker bots (archived copy), which has some good information on how to inject a DLL into an application, scrape the screen, and control the application. That might provide you with a starting point for doing this sort of thing.
You might also want to look for tools that other people have already written for doing this. It looks like there are several existing MTGO bots, but they all seem a bit sketchy (there have been some reports of them stealing passwords), so be careful there.
Edit
Since this answer still seems to be getting upvotes, I should probably update it with some more useful information. Since writing this, I have found a great UI automation system called Sikuli. It allows you to write programs in Python that automate a GUI. It includes image recognition features which make it very easy to recognize buttons, cards, and other UI elements; you just take a screenshot, crop it down to include just the thing you're interested in, and do fuzzy image matching (so that changing backgrounds and the like doesn't cause the match to fail). It even includes a custom IDE that allows you to embed those screenshots directly in your source code, so you can see exactly what the code is looking for. Here's an example from the documentation (apologies for the code formatting, doing images inline in code is not easy given StackOverflow's restricted subset of HTML):
def resizeApp(app, dx, dy):
switchApp(app)
corner = find(Pattern().targetOffset(3,14))
drop_point = corner.getTarget().offset(dx, dy)
dragDrop(corner, drop_point)
resizeApp("Safari", 50, 50)
This is much easier to get started with than the techniques mentioned in the article linked above, of injecting a DLL into the process you are debugging. Sikuli runs entirely at the UI level, so you never have to modify the program you are automating or worry about changes to the internals breaking your script.
One thing it is a bit poor at is handling text; it has OCR features, but they aren't all that good. If the text is selectable, however, you can select the text, copy it, and then look directly at the clipboard.
If I were to write a bot to automate something without a good API or text-based interface, Sikuli is probably the first tool I would reach for.
This answer is constructed from my comments.
What you are trying to do is hard, any way you try and do it.
Arguably the easiest way to do it is to totally mimic the user. So the application presses buttons, moves the mouse etc. The downside with this is that it is dependant on being able to recognise the screen.
This is easier if you can alter the games files as you can then just skin ( changing the image (texture)) the required cards to a single unique colour.
The major down side is you have to have the game as the top level window or have the game running in a virtual machine. Neither of which is ideal.
Another method is to read the processes memory. You may be able to find a list of memory locations, which would make things simpler, otherwise it involves a lot of hardwork, a debugger to deduce the memory addresses. It also helps (a lot) to be able to understand assembly.
The third method is to intercept the packets, and alter them. This is easier that the method above as it (at least for me) is easier to reverse engine the protocol as you have less information to deal with. It is just a matter of setting up a packet sniffer and preforming a action with one variable different (for example, the card) and comparing the differences.
The thing you need to check are that you are not breaking the EULA. I don't know how the game works, but most of the games I have come across have a EULA that prohibits (i.e. You get banned) doing any of the things I have mentioned.
We have a lot of reports that are generated via VBA & Excel. Only a small percentage of the reports are actual calculations - the majority of the work is sql calls and formatting/writing of cells. The longest of which takes several hours, the majority takes around 20-30 mins each.
The VBA/Excel code plugs into a dll that the VB6 desktop apps use - it's here that all the sql calls are made. While I am sure that there is room for improvement here, it's not this that concerns me - the desktop apps are fairly snappy.
Two VBA functions are used in abundance: These are called GetRange and SetupCell and they nearly always appear together. The GetRange function is a wrapper for the Excel.Range object. It takes a sheet, and 4 values for the extents of the range. Its main use is to pick the cell for editing. There doesn't appear to be much chance of optmising it, but is it the best way?
Its partner is SetupCell. This takes a Excel.Range object, text and a dozen parameters about the cell (font, borders, etc). Most of these parameters are optional booleans but again, it seems very wasteful. Some of these can be set posthumously but some are dependant on the values contained in the cell.
There's quite a lot of code contained in these functions, mainly if statements and work won't appreciate me posting it.
I guess I've got two questions: Is there a better way and what is it and is there are free profiler that I can use to see if the bulk of the time is here or in the dll?
several hours is ridiculous for a report.
If the problem is VBA buy "Professional Excel Development" (stephen Bullen, Rob Bovey et al): this has a free VBA profiler called PerfMon.
If the problem is Excel Calculation see http://msdn.microsoft.com/en-us/library/aa730921.aspx?ppud=4
But I would guess that the problem is the high overhead associated with referencing things cell-by-cell: you should always work in large blocks of cells at a time.
Have you thought about using an actual reporting solution? What's your backend db? If you are using MSSQL 2000 or higher there is a fairly decent reporting solution you can use free of charge. SQL Server Reporting Services.
It sounds as if the reports are spending most of their time formatting cells. This could be why the reports seem so slow and the desktop app doesn't.
Alternatively, if you know the formatting before hand and it is fairly static, you could pre-format the sheets to cut down on some of the work.
I will throw this in there as well. Most reporting solutions will allow for conditional formatting and such, but since they are designed to work as such performance will be much better than having Excel do it.
This isn't a profiler recommendation, but it is a suggestion for speeding up Excel macros that are spending their time updating the screen. I've had excellent results by turning off screen updating while the macro is running: set Application.ScreenUpdating= False, and also using a number of other similar settings. Just be sure to turn them back on again when the macro finishes :P
It's not free but you can profile with this. I suspect the demo will be adequate to your needs: http://www.aivosto.com/vbwatch.html
It sounds like the VBA code (or the VB code that's writing to the sheets) is doing so line by line, this can take ages, and is poor design. Write to Excel as a variant in one go. Format the sheet after the data is all imported.
Thanks
Ross