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

Vérification of html tag attributes

7 Answers 121 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nicolas
Top achievements
Rank 1
Nicolas asked on 24 Jan 2011, 04:45 PM
Hello

I'd like
to know how we can test by coded steps, the attributes of an html tag, for example to verify that the "CONTENT" attribute  of a meta tag is "NOARCHIVE".
example :   <META NAME="GOOGLEBOT" CONTENT="NOARCHIVE">

thanks

7 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 25 Jan 2011, 02:56 PM
Hi Nicolas,
   this requires a bit of coding since normally you can't reach the HTML code that's in the <head> part of a page. Instead we use:
String content = ActiveBrowser.ViewSourceString;
to get the entire source of the page and we write our own logic to parse the <meta> tags. Here's the entire code for a step that check whether each meta-tag on a page contains content="noarchive":
String content = ActiveBrowser.ViewSourceString;
         
        while (content.Contains("<META")||content.Contains("<meta") )
        {  
            content = content.Substring(content.IndexOf("META",StringComparison.CurrentCultureIgnoreCase)+4);
            String meta = content.Substring(0, content.IndexOf(">")-1);
            content = content.Substring(content.IndexOf(">") + 1);
 
            if (meta.Contains("CONTENT=\"NOARCHIVE\"")) {
                Assert.IsTrue(true, "Meta-tag content=noarchive");
                break;
            };
        }

I hope this solution will work for you, let me know how it goes!

Greetings,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Cody
Telerik team
answered on 28 Jan 2011, 10:34 PM
Hello Nicolas,

Sorry about that. You're right. Here is some much cleaner and more reliable code to look for that attribute.

[CodedStep("MyCustom Step Description")]
public void MyCustomStep()
{
    bool found = false;
 
    ReadOnlyCollection<Element> nodes = Find.AllByTagName("meta");
    foreach (Element metatag in nodes)
    {
        foreach (iAttribute attr in metatag.Attributes)
        {
            if (attr.Name.Equals("content", StringComparison.InvariantCultureIgnoreCase)
                && attr.Value.Equals("noarchive", StringComparison.InvariantCultureIgnoreCase))
            {
                found = true;
                break;
            }
        }
    }
    Assert.IsTrue(found);
}

Kind regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Cody
Telerik team
answered on 29 Jan 2011, 11:17 PM
Hello Nicolas,

I just thought of how this can be done with one line of code:

Assert.IsNotNull(ActiveBrowser.Find.ByExpression(new HtmlFindExpression("TagName=meta", "content=noarchive")));

This line of code will fail the test if it can't find a <meta> tag that contains CONTENT="NOARCHIVE"


Kind regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Oleg
Top achievements
Rank 1
answered on 16 Mar 2012, 12:41 PM
how i can change this sample for verification of text value of edit field (HTML or Silverlight?)
0
Cody
Telerik team
answered on 16 Mar 2012, 03:04 PM
Hello Oleg,

The simplest thing to do is to just record a Verification step. Then no code is required. Will that approach work for you?

Kind regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Oleg
Top achievements
Rank 1
answered on 17 Mar 2012, 10:37 AM
Cody, in verification menu i see only visible and tooltip verification,can`t realize why. if i don`t forget it, i`ll send screenshot. But now it`s not matter, because yesterday i wrote all verification for Sliverlight and HTML in code. By the way, all data i`m loading from XML, and then verification can be in code, as far as i know, data can changing between test running
0
Cody
Telerik team
answered on 17 Mar 2012, 10:15 PM
Hi Oleg,

Ok. If you need assistance in the future we'll be here.

Kind regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Nicolas
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Cody
Telerik team
Oleg
Top achievements
Rank 1
Share this question
or