locked
Automated coded UI tests - Visual Studio 2012 RRS feed

  • Question

  • I'm using Visual Studio Premium 2012 to create automated coded UI unit tests for my .Net application. On click of a Submit button on one of the pages, a pop-up window opens. I'm able to add assert conditions by focussing on the popup window. However, the challenge I have is - my UI tests are failing at the point where I added assert conditions for the popup window. It is always trying to match the popup window assert search properties in the main window itself and failing. Error message says expected value doesn't match with actual value. What should I do to correctly locate the popup window?

    Monday, July 22, 2013 4:07 PM

Answers

  • Hello,

    Glad to receive your reply.

    Based on your description, you locate the popup window first and then add assertion to URL property of the popup window to validate if the URL contains of '/adminreport’ in the Coded UI test.

    If yes, in order to make sure that the popup window is found before you add assertions to URL property, if you write your own code to search the popup window, I suggest that you use the following properties in searchproperties and DrawHighlight method to check if the correct window is found:

    'ControlType' property Equals 'Window'
    'Name' property Equals 'eDRS'
    'Uri' property Equals ‘https://edrsngdevweb/adminreport’

    If you create the Coded UI test using Coded UI Test Builder, I suggest that you use the same properties above to search the popup window. Please check it in Coded UI Test Editor through UI Control Map->select a control->F4->Search Properties in Properties window. If the Contains comparator is still used on URL property, please change it to ‘Equal’ to check the result.

    Best regards,


    Amanda Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Amanda Zhu Friday, August 2, 2013 11:47 AM
    Monday, July 29, 2013 5:33 AM

All replies

  • Hello,

    As my understanding, the Coded UI test about asserting the pop up window failed when you run the test because CodedUI always check the properties of main windows instead of the popup window during playback.

    In this case, I suggest that you try to hover over the window with mouse and hold down the Ctrl key and the I key at the same time and then release the keys to locate the popup window and then add assertions for it. For more information, please see ‘Selecting a hidden control using the keyboard’ section in this article: http://msdn.microsoft.com/en-us/library/dd286726.aspx

    After that you can run the coded UI test. During playback, please check if the popup window is in the front of the main window. If the popup window is behind the main window, maybe the Coded UI test will fail because of the issue in the original post.

    Also you can write your own Coded UI test to validate the popup window. You can locate the popup window through some searchproperties and then validate its property or anything else.

    This link give code to validate if the popup window exists: http://stackoverflow.com/questions/12483482/monitor-if-a-popup-window-is-visible-in-a-coded-ui-test-for-a-win32-application

    About hand coding a coded UI test, please see:

    http://blogs.msdn.com/b/mathew_aniyan/archive/2009/02/12/hand-coding-a-coded-ui-test.aspx

    Best regards,


    Amanda Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 24, 2013 4:56 AM
  • Hello,

    Thank you for your detailed response. I have tried your suggestion to use Ctrl + I to select the popup window instead of using Crosshair, and then add assertions, but still it did not work. It is failing to locate the poup window.

    Below is what I've tried before and the error response I got.

    In the Coded UI Test Builder, I used the Crosshair to select the popup window and investigate its properties to add an assertion. I've used the following properties to add assertions to the popup window.

    'ControlType' property Equals 'Window'
    'Name' property Equals 'eDRS'
    'Uri' property Contains '/adminreport'  --> (Comparator - Contains; Comparision Value - '/adminreport')

    The first 2 properties - ControlType and Name have the same values for the main window as well as popup window. Uri is one property that was majorly different betwen the main window and popup window. Hence I have used the Uri to add an assertion, to distinguish the popup window from main window.

    Uri of popup window is - https://edrsngdevweb/adminreport
    Uri of the main window - https://edrsngdevweb/Reports/Administrative/SearchAdminReport.aspx

    Below is the error message that I'm receiving when I run the test method.

    Message: StringAssert.Contains failed. String 'https://edrsngdevweb/Reports/Administrative/SearchAdminReport.aspx' does not contain string '/adminreport'

    From the above error message, I think that - it is always trying to find the search parameters in the main window itself and not in the popup window.

    Friday, July 26, 2013 8:49 PM
  • Hello,

    Glad to receive your reply.

    Based on your description, you locate the popup window first and then add assertion to URL property of the popup window to validate if the URL contains of '/adminreport’ in the Coded UI test.

    If yes, in order to make sure that the popup window is found before you add assertions to URL property, if you write your own code to search the popup window, I suggest that you use the following properties in searchproperties and DrawHighlight method to check if the correct window is found:

    'ControlType' property Equals 'Window'
    'Name' property Equals 'eDRS'
    'Uri' property Equals ‘https://edrsngdevweb/adminreport’

    If you create the Coded UI test using Coded UI Test Builder, I suggest that you use the same properties above to search the popup window. Please check it in Coded UI Test Editor through UI Control Map->select a control->F4->Search Properties in Properties window. If the Contains comparator is still used on URL property, please change it to ‘Equal’ to check the result.

    Best regards,


    Amanda Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Amanda Zhu Friday, August 2, 2013 11:47 AM
    Monday, July 29, 2013 5:33 AM
  • Hello,

    I am marking useful reply as answer. If the suggestion can’t help you, you can come back and unmark it as answer. If you have anything unclear, please feel free to come back and ask me.

    Best regards,


    Amanda Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 2, 2013 11:47 AM
  • Hello,

    Thanks for your response. I'm creating the Coded UI tests using the Coded UI Test Builder. I have used the same properties that you mentioned to search for the popup window and still my test is failing with the following error message.

    Message: StringAssert.AreEquals failed. Expected value ‘https://edrsngdevweb/adminreport’ doesn't match the actual value 'https://edrsngdevweb/Reports/Administrative/SearchAdminReport.aspx'

    I actually tried 'Equals' operator already and then switched to 'Contains' operator when someone suggested to try that.

    Regarding the issue that I posted here - this is a scenario where one popup window is opening a second popup window. That is - the main window that I was referring to in the description of the problem is a popup window. This main popup window opens a second popup window on click of a Submit button. And my UI tests are failing in the assert conditions, while trying to locate the second popup window. I think I didn't make this point clear in my description of the problem.

    Friday, August 2, 2013 4:42 PM
  • Hello,

    Since it is hard for us to repro this issue, maybe you could share us a sample which can be used to repro this issue on our side, we try to run it in our PC. Please attach your Visual Studio coded UI test project and a simple application, you can upload it to the sky drive, and then share the download link in your post.

    Thanks for your understanding.

    Best regards,


    Amanda Zhu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 5, 2013 7:35 AM