none
Don't get UIElement Sizes in a UITestMethod of Unit Test App (Universal Windows) RRS feed

  • Question

  • I would like to check the change of dimensions of a UIElement after a change of the content of the appropriate UIElement. All the sizes in the test method (see the LogMessage output) seem to be untouched. But I can see the controls in the App Window that is opened by the TestRunner . I guess there is a synchronization problem, but I don't know how to solve it. Does anyone have a suggestion? I don't want to use a Coded UI Test.

    Thanks, Boris

    // Unit Test App (Universal Windows)

    using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; using UITestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AppContainer.UITestMethodAttribute; using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace UIUnitTest.MSTest { [TestClass] public class UnitTest { [UITestMethod] public void Test_LocalPage() { TextBlock tb = new TextBlock { Text = "Hello!" }; Page page = new Page { Content = tb }; Size sz = Size.Empty; page.SizeChanged += (sender, args) => sz = args.NewSize; Window.Current.Content = page; Logger.LogMessage("1 - sz: {0}, tb.ActualWidth: {1}, tb.DesiredSize: {2}", sz, tb.ActualWidth, tb.DesiredSize); tb.Text = "Hello, it's me"; Logger.LogMessage("2 - sz: {0}, tb.ActualWidth: {1}, tb.DesiredSize: {2}", sz, tb.ActualWidth, tb.DesiredSize); } } }

    The ouput of the Logger:

    Result StandardOutput: 
    1 - sz: Empty, tb.ActualWidth: 0, tb.DesiredSize: 0,0
    2 - sz: Empty, tb.ActualWidth: 0, tb.DesiredSize: 0,0

    Thursday, December 17, 2015 12:51 PM

All replies

  • Hi b.petit,

    Currently I think I am not able to help you solve this issue. But I will invite some Microsoft senior engineers for further troubleshooting.

    Best Regards,

    Lake Xiao


    Monday, December 21, 2015 8:35 AM
    Moderator