Browser Window in each method of test case? Using coded ui - coded-ui-tests

I am new to coded UI, is it good practice to initialize Browser Window in each method of test case. For example i have two methods in my test case, I am trying to find control in each method, for that i write browser window in each method, can i write like that.

I don't see an issue with that approach.
Are you trying to reduce code/setup statements?
It really depends, you could have a test class with many test methods. however have a method attributed with ClassInitialize to launch the browser one time (and set the option to not destroy the window after each test) and keep reusing the same window. Then, possibly, have a method to close the window attributed with ClassCleanup.
Then in a test, you should only potentially need to use the NavigateTo method at the start of your tests to be on the right page.
Do you have test requirements dealing with sessions or saved data?
You may need to actively close down a window after a test and programmatically empty caches. Then in this aspect, I would be using BrowserWindow.Launch typically and letting CodedUi automatically destroy the window if i forgot to call close on the window.

Related

Instantiate a TreeViewer before opening a dialog

I have a TreeViewer inside a jface Dialog window.
The treeViewer needs to be populated with a large number of items with the setInput().And so it takes quite a bit of time for the tree to show, each time the dialog window is opened.
I want to know if there is any way to instantiate and save the treeViewer beforehand, so that the when the dialog window is opened, the treeViewer is just added to the dialog window and it is instantly visible.
I don't recall ever seeing anything try to do this. Creating the tree has to be done in the UI thread so this would still be difficult to do without stalling the UI.
There are various things you can do:
The model objects that the content provider provides can be built at any time since they are not UI objects. So you could get these in the background before the dialog is displayed.
You can use a virtual tree using the SWT.VIRTUAL style and an ILazyTreeContentProvider to delay building parts of the tree until they are needed.
If the code is in an Eclipse plugin you can use org.eclipse.ui.progress.DeferredTreeContentManager to defer building parts of the tree (there isn't much documentation on this method).

Visual C Multi-Threading (Please Help)?

I have written a .NET program, using Windows form Application.
My application is fairly simple.
Basically, I have two simple buttons on my form.
When the form is first loaded, I set up a global variable (bool run = true).
And my first button is essentially a very simple while loop.
while(run)
{
// do some code
}
And what I want to do, is have the second button set the value of the boolean to false (bool run = false).
But, once I clicked the first button, I cannot even touch the second button!
I have read quite about this, and I think my solution is to use a multi-threading.
I have found some example codes on line for multi-threading, and I tried to incorporate those, but I don't know why I cannot get it to work. Once I click button #1, there is no way for me to be able to click button #2.
Your UI thread should not have any infinite or a wait-on-something - never! You must not block the UI for anything (other than simple calculations, validations, user confirmation etc). You should make a thread for performing length task, and let that thread communicate to UI thread using asynchronous (or synchronous, if you prefer) communication.
On native Windows GUI application, you can use PostMessage (async), or SendMessage (sync). For .NET GUI applications, you can use Control.BeginInvoke (async), or Control.Invoke (sync).
Please read this article on how this is done.

Microsoft Access CODED UI Tests Control id recording

I have implemented a test framework trough coded UI to test msaccess application which has some buttons and dialog boxes popping up.
i have a strange problem which is, when i use coded UI it actually captures the coordinates for the control. this executes all the tests when i run from the same machine but fails to run the tests wherever the resolution changes or screen re sizes.
please let me know the way by which i can call the controls from a vba application based on their control names or id rather then coordinates.
I don't think that the coordinates is the reason that your tests are failing. These coordinates are referred to the controls themselves just to simulate the exact point you clicked on the control.
See this link: Why are we using coordinate based actions in Coded UI Test?

YUI browser history manager back button

In am using YUI browser history manager for keeping track of Ajax navigations. I am registering history object like:
YAHOO.util.History.register("state",init, onStateChange);
Here onStateChange is getting called when I do
YAHOO.util.History.navigate("state",urlhash);
and when I press back button.
Is there any way to know if onStateChange is called on back button or by calling navigate?
If this event can be called by an external system sometimes (in this case the browser back button) and by your own code sometimes, you can differentiate the caller by making it a requirement to do something special when your own code calls the method. Wrapping the call to navigate() in your own helper method can help make sure you stay consitent with this.
In the YUI docs I see that register() can take an optional 4th parameter (among others) which is an arbitrary object that will get passed into your onStateChange handler function. One of the properties of this object could be a flag indicating that it was called from your code versus initiated by the browser, and in your navigate() wrapper always set that flag. Remember to set it back in your handler.
Note: I am not as familiar with YUI as ExtJS, maybe some guru that knows the API better can help, but this is a general strategy that can work. This answer makes an inelegant assumption that a call to navigate() will make that handler fire reliably before any other navigation has a chance to occur, which is probably a safe bet in the single-threaded javascript world.

Adapting Modal Dialog Script to Firefox

I'm adapting my regression tests to test a web app in firefox. The biggest stumbling block seems to be how to automate the modal dialogs in firefox.
In ie I use variations of the script below, but it doesn't work in Firefox. Is there an alternative that will work in both ie and firefox?
popup=Thread.new {
autoit=WIN32OLE.new('AutoItX3.Control')
ret=autoit.WinWait(title,"",60)
if (ret==1)
puts "There is popup."
autoit.WinActivate(title)
button.downcase!
if button.eql?("ok") || button.eql?("yes") || button.eql?("continue")
autoit.Send("{Enter}")
else
autoit.Send("{tab}")
autoit.Send("{Enter}")
end
elsif (ret==0)
puts "No popup, please check your code."
end
}
at_exit { Thread.kill(popup) }
end
button.click_no_wait
check_for_popups("Message from webpage", "OK")
Given you are talking about a javascript created dialog, I really have to ask, is there a lot of value in actually testing those?
It basically amounts to testing the functionality of the browser
If you are talking about the type of popups described here http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups then I think the first solution, of overriding the javascript may well be your best cross platform option.
The problem with modal dialogs like this is that they are basically a UI even that is happening out at the OS level, it's no longer inside the browser DOM, and thus you need tools that are specific to the OS (like stuff that depends on win32ole, such as autoit) in order to generate the necessary interaction with the native UI and click buttons, send keystrokes etc. Most of the solutions presented should I think work with FF on windows (with proper renaming of expected window titles etc) but would fail on a mac or *nix OS. That means you need a different solution for each OS, which is a pain.
It might simply be easier to verify you can find the proper stuff that would fire the event in the HTML of the page, so you know an event WOULD be fired, and then override things so it isn't. After all it's not really your job to validate that the browser pops up a local dialog when something like alert('This is an alert box') is invoked in javascript. Your concern is that in the HTML a given element is coded to fire off the event that is needed e.g. that there's something like this onClick = 'javascript:x = confirm('Do you really want to do this');" affiliated with the element
I am experiencing a similar problem in Firefox (and I do have to test in Firefox). I can see the code calling the Javascript but when I try to override as described above nothing happens. Is there any kind of a workaround for this? Anticipated updates to Watir? ;-)

Resources