4

I am new to CodedUI & C#.

I am trying to automate a wpf application which has a WPF Browser. So basically, It's WPF container with html content inside. I have created a similar sample small application and shared it here. This application opens the amazon.in website within wpfwindow.

WPF Browser application

My problem is Coded UI is not able to identify the Html-Controls/elements like 'Buttons', 'Text input fields' properly.

Below, the top image is from the WPF Browser app [Link which i have shared]. Here you can see a blue square box on the top-left. The coded UI identifies that area has the Search Go button.

Bottom part of the image is of the amazon website in IE browser where coded ui is properly highliting/ identifying the Search Go button.

Does this mean i cannot automate WPFBrowser apps using Coded UI.?

Can someone please tell what to do to identify the buttons properly in coded ui

enter image description here

user2048204
  • 729
  • 4
  • 13
  • 27
  • Guessing from the Screenshots you shared, it looks like the renderings are of different width. It's basically dependent on how you browser choose to display something. Try reduce the WPF control width manually so that the header matches the width of Image banner below. Just a speculation, not sure if that the reason. In the other hand, do you get any issues when you run the test ? – Prageeth Saravanan Nov 29 '16 at 21:29
  • @PrageethSaravanan , Yes I have same issues even while running the scripts. And to reduce the WPF Control width, i need to do it in the Application source code right ? – user2048204 Nov 30 '16 at 09:02
  • you can do it in many ways. For Instance updating the control properties (You will find them under layout group).Refer this as well http://stackoverflow.com/questions/21170316/resize-dialog-webbrowser-to-webpage-width .. In General as I understand WinForms version of webbrowser control exposes more property than WPF webbrowser control. you may want to try that as well – Prageeth Saravanan Nov 30 '16 at 19:45
  • @PrageethSaravanan I do not have access to the source code of the application. I have only installed the Application on my system as an end user. So as an end user, can i change the properties of the controls? – user2048204 Dec 03 '16 at 13:49
  • I feel you may be approaching this wrong. Do you really need CodedUI? if you're trying to mimic user actions perhaps a headless browser could work for you and you could display the final html? and when the user clicks something in browser to update the in application browser, you do the same action on your headless browser staying in sync. If something like this can work, try researching SimpleBrowser nuget. I've used it with quite a bit of success. Essentially eliminating browser from user view completely and instead offering my own custom WPF View while still using underlying page for action – Maverik Dec 03 '16 at 16:57
  • @Maverik, The actual appication that i need to test has both HTML & WPF controls. Clicking on the on a HTML button might also invoke a WPF UI/ WPF Window. In this case, i guess browser might not be useful – user2048204 Dec 03 '16 at 17:15

2 Answers2

1

You need to specify Id attributes for the controls that you want exposed to Coded UI.

AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140
  • I have ID attirbute, But still i see the same problem. And moreover, The Coded Ui is identifying the Control but not exactly on the place where it exists. – user2048204 Dec 13 '16 at 08:27
1

To me this looks like CodedUI is getting some control that's similar, rather than the correct one.

You haven't mentioned if you're recording and executing tests or handwriting them in a separate CodedUI solution.

If you're recording them: Be sure that you're recording using your WPF application and interactions inside of them, rather than recording using your browser and then trying to execute tests using the WPF application

If you're writing them by hand: Be sure that you're correctly creating trees of inheritance when writing your tests. For instance, in a traditional CodedUI scenario the absolute top level object that all other controls inherit from is a web browser. In your scenario, that object should be the WPF object. There are probably going to be some other windows or various controls that are children of the WPF application which in turn will finally have the browser as a child.

Ryanman
  • 880
  • 1
  • 8
  • 20
  • I am not recording them, I am hand-coding them. Yes, I have created the inheritance properly. And yes, Top Level object is WPFObject. I can see this tree through the CodedUI Test builder. – user2048204 Dec 13 '16 at 08:31