[Webtest] RE: Webtest for JS and dynamic webpages

Craig Copeland Craig Copeland <craig_a_copeland@yahoo.com>
Fri, 13 Oct 2006 10:11:23 -0700 (PDT)


Howdy Amit,=0A=0AYeah.  I have issues from time to time with webtest and JS=
.  Some have been bugs in HtmlUnit (the underlying browser) but most have b=
een "bad" JavaScript or poor HTML on my side.  Being on the QA side of the =
house, sometimes I can't effect a change when the code succeeds for IE and =
FF, but fails for WebTest/HtmlUnit.  Therefore, I sometimes find the follow=
ing tricks helpful:=0A1) In the config portion, use:=0A---=0A<config ...>=
=0A  <option name=3D"JavaScriptEnabled" value=3D"false" />=0A</config>=0A--=
-=0AOf course, this is just disabling JS for your test run, but can be help=
ful from time to time.=0A=0A2) With <webtest><steps> hierarchy use:=0A---=
=0A        <groovy>=0A          step.context.webClient.throwExceptionOnScri=
ptError =3D true=0A          step.context.webClient.throwExceptionOnFailing=
StatusCode =3D true=0A        </groovy>=0A---=0AThen you can re-enable thes=
e failure cases after you're past the troublesome code where HTML Unit is t=
hrowing exceptions or returning some failed status for HTML.  I typically u=
se these settings independently depending on the situation I run into.=0A=
=0A3) Some developers will use the "alert" function to dubug.  I've not fou=
nd this tremendous helpful within WebTest.  Instead, I've found tweaking th=
e JS code to write variable data, etc to the page itself can be helpful usi=
ng something like:=0A---=0Avar variableInQuestion =3D ...;=0Avar tmp =3D ge=
tElementById("foo"); //A div tag, or something used on your page=0Atmp.inne=
rHTML =3D "foo =3D '" + tmp + "'";=0A---=0Aand then testing this with a web=
test <verify... /> call or using the suggestion below in #4.=0A=0A4) Again =
Within <webtest><steps>, use:=0A---=0A<storeProperty propertyType=3D"ant" p=
roperty=3D"foo" value=3D"something you want to see" />=0A<storeXPath proper=
tyType=3D"dynamic" property=3D"bar" xpath=3D"<some xpath expression like 'i=
d(myElement)'>"=0A<antWrapper>=0A  <echo message=3D"foo =3D '${foo}' and ba=
r =3D '#{bar}' " />=0A</antWrapper>=0A---=0Awhich will give you output to y=
our command terminal.=0A=0A5) Probably the best suggestion and perhaps most=
 helpful, is incrementally narrowing the scope of the problem.  I will typi=
cally create a new page on my local apache instance with the "broken" code =
first.  Then remove JS or HTML to narrow down where the problem might be.  =
Then once you've got the smallest possible code (and webtest), submit a que=
stion/comment to the list.  When you have an easy test to run, Marc, et al,=
 can often run down your issue fairly quickly.=0A=0AThese are my tricks.  I=
'm sure some of the others on the list have some that are better, but this =
is where I'm at currently.  Honestly, I'd love to have a quick list like th=
is on the Canoo page with stuff like this from those guys that are smarter =
than me.=0A=0AHope this helps,=0ACraig=0A> Now I am trying to make Webtest =
work against Java Script and against=0A> dynamically generated webpages. Co=
uld you point me in the right=0A> direction by giving me an idea of the Web=
test keywords I should be=0A> looking into?=0A=0A=0A=0A