Microsoft Access CODED UI Tests Control id recording - coded-ui-tests

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?

Related

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

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.

Who is calling VisualStateManager.GoToState behind the scenes?

I am a newbie to xaml and windows app dev so sorry if this question might seem silly.
I created a textbox and in the designer I right clicked it and selected edit template=>edit a copy and put it into my custom dictionary.
In the control template for this textbox I saw visual states like disabled,focused and so on. And I modified them and run the mobile app and observed that my changes work like changing border color when textbox is focused.
But in order for this to work somebody has to call
VisualStateManager.GoToState("Focused")
when the textbox is focused so who is calling this because I don't see any visual transitions in the control template so how is this happening?
The code in the control itself is calling VisualStateManager.GoToState(...) .
When you start implementing your own custom controls, you might subscribe to events you have available and transition states based on your own logic. Here is an example of a custom control with its own two custom states.
https://github.com/xyzzer/WinRTXamlToolkit/blob/master/WinRTXamlToolkit/Controls/WatermarkTextBox/WatermarkTextBox.cs
XAML is a compiled language, and if you've looked extra close, what happens under the hood, is that the class behind your xaml has the same namespace as your xaml code.
This means (for no practical purpose) that compiling your program turns all of that XAML into C# code before then going over to MSIL and eventually execute as a binary program.
Much of the state changes that happen are event based, and TextBox, like all other user controls, will transmit a message and listen to messages. The Page that contains the TextBox will probably be the one that transmits a state change whenever one of it's children gets focus, and as a good control, the TextBox listens for this event and reacts to it.

Unable to find the WPF custom control using coded ui

I am trying to automate WPF application (WPF with 3rd party devexpress) using coded UI (VS 2012) in my local machine (Windows server 2008 R2).
I am facing issues while identifying controls under dynamically generated content of the window. I've Tried different hierarchical levels to hit the control,But i am
still not able to hit the control.
Till some level I am getting the handle, but after I am not getting the handle.
My application is complex hierarchically structured with combining winforms and WPF.
I've Tried to use coded UI record and play feature to generate the UI Map and used the same structure to identify the controls. It worked while debugging line by line but it's failing while running.
e.g. Below is one hierarchy,
List item
Dashboard
Dash_Grid
LayoutManager
LayoutGroup
LayoutPanel -->Till this level I am able to get the handle and lower I am not able to hit the control
Container
Navtop
Nav_Grid
TileLayoutControl
........(all tiles)
This issue is not only with one page. I am having the same problem with all the pages.So this is blocking our automation.
Please can any one help me on this?
Try this two possible solutions:
Use the devexpress extension for codedui to identify and locate dexExpress controls:
https://www.devexpress.com/products/net/controls/winforms/coded-ui/
Dont replicate the elaborate hierarchy of your app when identifying controls but instead select the main controls in the hierarchy and use them to set your search properties. this is especially important for dynamically created content where the hierarchy is constantly changing.
in your example:
var List_item = new WpfListItem(parent);
List_item.SearchProperties.. = some search properties
and than set your control's parent to that top list item and ignore the midlle men:
var Container = new UITestControl(List_item);
where UITestControl should be replaced with the controls actuall type.

How to write Coded UI Assert for Treeview.ItemsSource > 0

Background: Am just learning Coded UI. This is from a simple test app in WPF using VS 12.
I have created a Coded UI Test Project and a Coded UI Test.
I have recorded opening the app, clicking a button, and then closing the app and it will run through this in a Test Run.
Now I want to add an assertion to a Treeview. The scenario is a user opens a file, and it loads a treeview, and I want to make sure the Treeview has at least one item in it.
So I run the exe, open the Coded UI Test Builder and drag the crosshairs to the Treeview. It successfully hightlights the TreeView. It then shows the Add Assertions Dialog.
The Treeview is shown in the Dialog, but there is no "Control Specific" properties of ItemsSource. It shows only 5 control specific properties, such as HelpText, AccessKey etc.
I can add an assertion for HelpText, but that isn't what is needed.
So the question, why isn't ItemsSource being shown in the Assertion Dialog?
How do I get it to show?
After dragging the crosshairs tool onto a UI control the assertions dialogue is shown. To the right of the Add Assertion button there are four arrows arranged as Up, Down, Left and Right. Clicking these allow the selected control to be changed between siblings (Left and Right), ancestors (Up) and children (Down). Use these buttons to explore the tree control. I do not know what an "ItemsSource" is in the particular tree that you are viewing, it might not be an exposed property of the tree even if it is part of the implementation or the API. There may be other properties of some part of the tree that have the values you need.
I do not believe that Coded UI can generate an assertion to test that the tree contains at least one item. I believe you will need to hand code that part. My first thoughts there would be to get the UIControl object for the tree and then use its GetChildren method to find the items in the tree. That may need to be recursive to get all the elements in the tree.

Capybara Cucumber test fail to find xpath when browser is minimized

I'm running a scenario where form fields are automatically filled in with invalid values which trigger some javascripts to show warnings under each incorrectly filled field when I blur.
The test passes when the browser is in focus. It finds the xpath with the "expected warning" that I pass. But if I minimize or just click on another application, it fails to find the xpath.
I'm running Firefox 3.6 (going to update it soon) and the way I'm doing to find the xpath is by using "page.should have_xpath(xpath)"
Does anyone have any idea how what might solve this? It's really important for me to run it with the browser minimized.
Edit and alternative solution:
I guess the timing issue that occurs in events such as blur followed by finding a certain xpath in a minimized browser inherent to the driver itself. Therefore, I decided to run the tests in a Virtual Frame Buffer using xvfb in Linux and it seems to be working really well. I'm planning on applying this to be triggered by Hudson/Jenkins whenever a change is committed.
Could it be a timing issue? Perhaps if the browser isn't frontmost and maximised, the rendering is not happening quickly enough for the content be present when Capybara checks for it.
Also: How are you triggering the blur event?

Resources