This question is locked. New answers and comments are not allowed.
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
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
0
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":
I hope this solution will work for you, let me know how it goes!
Greetings,
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
Hello Nicolas,
Kind regards,
Cody
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);
}
Cody
the Telerik team
Interested in Agile Testing?
Check out Telerik TV for a recording of
Automated Testing in the Agile Environment
0
Hello Nicolas,
This line of code will fail the test if it can't find a <meta> tag that contains CONTENT="NOARCHIVE"
Cody
the Telerik team
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"
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
Hello Oleg,
Cody
the Telerik team
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
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
Hi Oleg,
Cody
the Telerik team
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
Test Studio Trainings