How to validate the control based on Style?

Jul 10, 2012 at 6:47 PM

I have two control on my web page.

<tr id="FCYear2" style="display: inline; background-color: rgb(234, 234, 234);">

<tr id="FCYear3" style="display: none;">

First control "FCYears2" shows up on the webpage. The second one "FCYear3" is not displayed on page.  

I have to validate the above controls display. I wrote below  

 

Assert.IsTrue(pgSubmitServiceOrder.cel2012.Exists);

Assert.IsFalse(pgSubmitServiceOrder.cel2013.Exists);

First assertion is passed. Second assertion is failed. How can we validate the control existence based on the style or any other way ? Appreciate your hep in this ?

Thanks,

Sailaja

Coordinator
Jul 11, 2012 at 8:24 PM

Hi Sailaja,

There is a sample unit test that illustrates how to use the Exists property for invalid controls.

.\Sample_CUITeTestProject\Tests_for_HtmlControls.cs

[TestMethod]
public void Test_InvalidControlExists()
{
    Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None; //required if you are using .Exists on an invalid control
    CUITe_BrowserWindow.Launch("http://www.google.com");
    GoogleHomePage pgGHomePage = CUITe_BrowserWindow.GetBrowserWindow();
    Assert.IsFalse(pgGHomePage.divInvalid.Exists);
}

Jul 12, 2012 at 7:49 PM

Hi,

Thank you for quick response.  I tried the above sample code.  Throwing me an compilation error  "SmartMatchOptions" doesnot exist in current context. What could be reason? Am I missing anything? Appreciate your help.

Thanks,

Sailaja

 

Coordinator
Jul 12, 2012 at 8:16 PM

You are probably missing a project reference and using statement for Microsoft.VisualStudio.TestTools.UITest.Extension:

HintPath: c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.TestTools.UITest.Extension.dll

Version: 10.0.0.0

 

SmartMatchOptions Enumeration

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitest.extension.smartmatchoptions.aspx

Jul 13, 2012 at 4:50 PM

Yes, I missed the reference. I added that.  Still the asserts are failing. When i looked at the view source both the controls exist, but the only diffrence is style attribute. Is there any other way that we can validate invalid control on the page. Appreciate your help. Thanks,

<tr id="FCYear2" style="display: inline; background-color: rgb(234, 234, 234);">

<tr id="FCYear3" style="display: none;">

Coordinator
Jul 14, 2012 at 2:01 AM
Edited Jul 14, 2012 at 2:03 AM

I just checked in a sample unit test in Sample_CUITeTestProject

From TestHtmlPage.html:

 

<button id="hiddenButton" style="display: none;" />

 

From Tests_for_HtmlControls.cs:

 

[TestMethod]
public void HtmlButton_HiddenByStyle_ControlExistsAndCanAssertOnStyle()
{
    CUITe_BrowserWindow bWin = CUITe_BrowserWindow.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");

    CUITe_HtmlButton btnHiddenButton = bWin.Get("id=hiddenButton");

    Assert.IsTrue(btnHiddenButton.Exists);

    Assert.IsTrue(btnHiddenButton.UnWrap().ControlDefinition.Contains("style=\"DISPLAY: none\""));

    bWin.Close();
}