This is a migrated thread and some comments may be shown as answers.

Trouble finding validation summary in SPA

6 Answers 34 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 2
Phil asked on 17 Sep 2016, 03:43 AM

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

 

6 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 21 Sep 2016, 02:51 PM
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
 
0
Phil
Top achievements
Rank 2
answered on 21 Sep 2016, 10:35 PM

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
0
Konstantin Petkov
Telerik team
answered on 23 Sep 2016, 12:26 PM
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
 
0
Phil
Top achievements
Rank 2
answered on 24 Sep 2016, 02:14 AM

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

 

0
Phil
Top achievements
Rank 2
answered on 25 Sep 2016, 07:12 PM

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

0
Boyan Boev
Telerik team
answered on 28 Sep 2016, 03:27 PM
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
 
Tags
General Discussions
Asked by
Phil
Top achievements
Rank 2
Answers by
Boyan Boev
Telerik team
Phil
Top achievements
Rank 2
Konstantin Petkov
Telerik team
Share this question
or