Trouble finding validation summary in SPA

7 posts, 0 answers
  1. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 16 Sep Link to this post

    Hi:

    I am doing my first UI testing.  The rendered code can be found in the comments;

    public string ValidationError
    {
        get
        {
            // <div class="validation-summary-errors" data-valmsg-summary="true">
            //  <ul><li>The user name or password provided is incorrect.</li></ul>
            // </div>
            _browser.Manager.ActiveBrowser.AutoDomRefresh = true;
            _browser.Manager.ActiveBrowser.RefreshDomTree();
            System.Threading.Thread.Sleep(500);
            return _browser.Find.ByAttributes<HtmlDiv>(_validationErrorsSelector).Find.ByTagIndex("li",0).InnerMarkup;
        }
    }

    I can see the value on the screen, but what is returned is an empty string.  It is finding by attribute OK, but the ActiveBrowser DOM does not seem to be what is rendered.

    Phil

     

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 21 Sep Link to this post

    Hello Phillip,

    I have slightly modified your code so it is more simple:

    HtmlDiv div = ActiveBrowser.Find.ByAttributes<HtmlDiv>("class=validation-summary-errors");

    HtmlListItem item = div.Find.ByTagIndex<HtmlListItem>("li", 0);

    This will find the first div with class=validation-summary-errors and then find the first li in that div.

    Let me know if that helps.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 21 Sep in reply to Boyan Boev Link to this post

    Hi Boyan:

    I am using a Page Object Model to simplify my UI tests and place all of the dependencies in a class.

    My code is finding by attribute OK, but the ActiveBrowser DOM does not contain what is currently being rendered.  That is why I am refreshing the DOM tree, but it still does not have what is currently being rendered.

    Phil
  4. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 23 Sep Link to this post

    Hello Phil,

    Can you please isolate the problem in a runnable test case you can send our way to replicate locally? That seems to be the best course of action here in order to avoid multiple back and forth messages before we can figure out how to further assist you. You can send any additional and even private data in a support ticket to avoid posting it publicly in the forum if you prefer.

    Regards,
    Konstantin Petkov
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  5. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 23 Sep in reply to Konstantin Petkov Link to this post

    Hi Konstantin:

    The project is easy.  This is the standard template ToDo SPA in Visual Studio.  I am using VS 2012 Express edition.  I do all of my talks with free VS.  The test is as follows:

    [TestCategory("TestingFramework"), TestMethod]
    public void TF_UI_Todo_LoginFailure_Test()
    {
        Browser _browser = Manager.ActiveBrowser;
        string _expected = "The user name or password provided is incorrect.";
        Console.WriteLine("*** Login Failure Test ***");
        SiteLoginPage _login = new SiteLoginPage(_browser);
        _login.UserName = HelperPage.ValidUserName + "X";
        _login.Password = "Invalid123@";
        TodoPage _todo = _login.SubmitPage();
        string _actual = _login.ValidationError;
        Assert.AreEqual(_expected, _actual);
    }

    Login Page Object Model is as follows:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    //
    using ArtOfTest.WebAii.Controls.HtmlControls;
    using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
    using ArtOfTest.WebAii.Core;
    using ArtOfTest.WebAii.ObjectModel;
    using ArtOfTest.WebAii.TestAttributes;
    using ArtOfTest.WebAii.TestTemplates;
    using ArtOfTest.WebAii.Win32.Dialogs;
    //
    namespace UAT_Tests
    {
        public class SiteLoginPage
        {
            Browser _browser = null;
            string _siteUrl = HelperPage.SiteUrl;
            string _userNameField = "loginName";
            string _passwordField = "Password";
            string _loginPanelId = "loginPanel";
            string _submitButtonAttibute = "type=submit";
            string _userSettings = HelperPage.UserSettingsSectionId;
            string _validationErrorsSelector = "class=validation-summary-valid";
            //
            public SiteLoginPage(Browser driver)
            {
                Console.WriteLine("*** Logout Script ***");
                _browser = driver;
                _browser.Manager.ActiveBrowser.NavigateTo(_siteUrl);
            }
            //
            public string URL
            {
                get { return _siteUrl; }
            }
            //
            public string UserName
            {
                set
                {
                    Console.WriteLine("SendKeys Login Field: " + _userNameField);
                    HtmlInputText loginField = _browser.Find.ById<HtmlInputText>(_userNameField);
                    loginField.Text = value;
                }
            }
            //
            public string Password
            {
                set
                {
                    Console.WriteLine("SendKeys Password Field: " + _passwordField);
                    HtmlInputPassword passField = _browser.Find.ById<HtmlInputPassword>(_passwordField);
                    passField.Text = value;
                    passField.Focus();
                    passField.InvokeEvent(ScriptEventType.OnKeyUp);
                }
            }
            //
            public bool IsSiteLoginPage()
            {
                HtmlDiv _setting = _browser.Find.ById<HtmlDiv>(_userSettings);
                if (_setting != null)
                {
                    Console.WriteLine(_userSettings + " text: " + _setting.InnerText.Trim());
                    return (_setting.InnerText.Trim() == "" ? true : false);
                }
                return false;
            }
            //
            public TodoPage SubmitPage()
            {
                Console.WriteLine("SendKeys Password Field: Enter");
                HtmlInputSubmit _submit = _browser.Find.ByAttributes<HtmlInputSubmit>(_submitButtonAttibute);
                _submit.Click();
                System.Threading.Thread.Sleep(500);
                return new TodoPage(_browser);
            }
            //
            public string ValidationError
            {
                get
                {
                    // <div class="validation-summary-errors" data-valmsg-summary="true">
                    //  <ul><li>The user name or password provided is incorrect.</li></ul>
                    // </div>
                    _browser.Manager.ActiveBrowser.AutoDomRefresh = true;
                    _browser.Manager.ActiveBrowser.RefreshDomTree();
                    System.Threading.Thread.Sleep(500);
                    Console.WriteLine("Get error by: " + _validationErrorsSelector);
                    // _browser.Find.ById<HtmlDiv>(_loginPanelId).Wait.ForAttributes(_validationErrorsSelector);
                    return _browser.Find.ByAttributes<HtmlDiv>(_validationErrorsSelector).Find.ByTagIndex("li",0).InnerMarkup;
                }
            }
            //
            public TodoPage SiteLogin()
            {
                UserName = HelperPage.ValidUserName;
                Password = HelperPage.ValidPassword;
                TodoPage _todo = SubmitPage();
                return _todo;
            }
        }
    }

    Todo Page Object Model stub:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    //
    using ArtOfTest.WebAii.Controls.HtmlControls;
    using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
    using ArtOfTest.WebAii.Core;
    using ArtOfTest.WebAii.ObjectModel;
    using ArtOfTest.WebAii.TestAttributes;
    using ArtOfTest.WebAii.TestTemplates;
    using ArtOfTest.WebAii.Win32.Dialogs;
    //
    namespace UAT_Tests
    {
        public class TodoPage
        {
            Browser _browser = null;
            //
            public TodoPage(Browser manager)
            {
                _browser = manager;
            }
        }
    }

    Static helper class:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    //
    namespace UAT_Tests
    {
        public static class HelperPage
        {
            public readonly static string SiteUrl = "http://localhost:20000/";
            public readonly static string UserSettingsSectionId = "userSettings";
            public readonly static string ValidUserName = "TestUser";
            public readonly static string ValidPassword = "Ab.!234@";
            public readonly static string TestAddItem = "X Test Todo item X";
        }
    }

    Phil

     

  6. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 25 Sep in reply to Phil Link to this post

    Hi:

    Got it with:

    string _validationErrorsXPath = "//*[@id='loginForm']/fieldset/div/ul";
    ...
    return _browser.Find.ByXPath<HtmlUnorderedList>(_validationErrorsXPath).Find.ByTagIndex("li", 0).InnerMarkup;

    But I am still missing a large piece of understanding, of why it wasn't working other ways!

    Phil

  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 28 Sep Link to this post

    Hello Phil,

    I am happy to hear that everything works now.

    In order to say why exactly it doesn't work we will need your project and access to the application so we can debug it.

    Thank you for your cooperation.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top