Watij, JAX-WS and hiding html control elements.

35 views
Skip to first unread message

Chris Santen

unread,
Jan 7, 2008, 3:32:00 PM1/7/08
to watij
Hello Watij Community,

I wrote a prototype to demonstrate that I can log in and run test on a
web app that leverages JAX-WS. The log in page was no problem because
there are actual html elements being rendered to the browser that I
can populate and click on etc. . . .

However, now that the application has loaded all of the actual html
controls are being hidden / rendered by java script it appears. When
I grab all of the html elements (ie.elements()) I get the following
output:

bsh % print( ie.elements() );
[[HTML: null], [HEAD: null], [TITLE: null], [SCRIPT: null], [LINK:
null], [LINK: null], [LINK: null], [LINK: null], [LINK: null], [LINK:
null], [LINK: null], [LINK: null], [LINK: null], [LINK: null], [LINK:
null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
[SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
[SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
[SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
[SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
[SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
[SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
[SCRIPT: null], [SCRIPT: null], [FRAMESET: null], [FRAME: null],
[FRAME: null], [FRAME: null], [FRAME: null]]

Am I dead in the watij with this? I'm hoping that I can get a set of
events that I can use Watij to fire off and or execute these java
scripts intelligently such that I can continue to write tests scripts
in Watij (enter text, click on buttons etc). Any advise would be
appreciated.

Thank you,
Chris

Chris Santen

unread,
Jan 8, 2008, 10:43:19 AM1/8/08
to watij
So to add a bit more info here to this post, here is an example what
the browser object can parse:

* several link tags like:
<link rel="stylesheet" href="/gpas/wdk/theme/documentum/css/
dragdrop.css" type="text/css">
<link rel="stylesheet" href="/somepath/css/webforms.css" type="text/
css">

* several script tags like:
<script src="/somepath/wdk/include/trace.js" type="text/javascript"></
script>
<script src="/somepath/wdk/include/wdk.js" type="text/javascript"></
script>

* some java script like:
registerClientEventHandler("titlebaractions","buttonClicked",
onButtonClicked);
registerClientEventHandler(null,"ViewChanged",onViewChanged);
function onUnload()
{
promptIfUnsavedChangesExist();
manageTimeout(frames["timeoutcontrol"]);
}
function onButtonClicked(srcControl,size){
window.frames['view']['workarea']
['content'].postServerEvent(null,null,null,"onClickThumbnails","view",srcControl,"size",size);
}
function onViewChanged(strView){
window.frames['titlebar']['titlebaractions'].currentView(strView);
}

* a frameset containing a set of frames.

Is it possible to send events via Watij or leverage these functions?
The normal method of finding a button object and sending it a .click()
doesn't seem to work with this Ajax supported interface. Perhaps what
I should do is to find some examples of a Watij test against an Ajax
client, I'm under the impression that Watij works well with the newer
web UI tools so I'm hoping I can explore that aspect of it.

Thank you,
Chris

Brian Knorr

unread,
Jan 9, 2008, 11:37:34 AM1/9/08
to wa...@googlegroups.com
Hi Chris,

You can send actual javascript to the page via ie.executeScript which will evaluate it on the page (so the sky is the limit here).......also the best way to handle async javascript calls (ajax) is to use a waiter.  For example:

ie.link().click(); //fires an ajax call to update something
new WaiterImpl(10000, 200).waitUntil(new Ready() {
    public boolean isReady() throws Exception {
        return ie.containsText("update successful"); //wait until the text is returned from the ajax call
    }

    public String getNotReadyReason() {
        return "control doesn't exist";
    }
});

Hope this helps...best,

Brian

> I grab all of the html elements ( ie.elements()) I get the following

> output:
>
> bsh % print( ie.elements() );
> [[HTML: null], [HEAD: null], [TITLE: null], [SCRIPT: null], [LINK:
> null], [LINK: null], [LINK: null], [LINK: null], [LINK: null], [LINK:
> null], [LINK: null], [LINK: null], [LINK: null], [LINK: null], [LINK:
> null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
> [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
> [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
> [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
> [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
> [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
> [SCRIPT: null], [SCRIPT: null], [SCRIPT: null], [SCRIPT: null],
> [SCRIPT: null], [SCRIPT: null], [FRAMESET: null], [FRAME: null],
> [FRAME: null], [FRAME: null], [FRAME: null]]
>
> Am I dead in the watij with this?  I'm hoping that I can get a set of
> events that I can use Watij to fire off and or execute these java
> scripts intelligently such that I can continue to write tests scripts
> in Watij (enter text, click on buttons etc).   Any advise would be
> appreciated.
>
> Thank you,
> Chris




--
Brian Knorr
www.watij.com

Chris Santen

unread,
Jan 9, 2008, 12:39:34 PM1/9/08
to watij
Brian,

Thank you so much for you response! Okay I am going to try this.
Question - is it possible for me to get a hold of an Ajax object and
send it clicks and text the way we get a hold of html elements?

I've posted the following thread up on a fellow Watij user (test
developer's page) who goes by Mushy, that illustrates where I am and
what I am trying to accomplish I think better than the posts I've put
up here so I'm going to copy it and past it into this thread. Here is
the post (the code examples I have do not show any of my wait
messages, I've been using .ie.waitUntilReadyInvokeLater(); and
ie.waitUntilReady() between most of my calls to the browser with good
results during the log in and send key ops). Anyway, here's the post:

"Mushy,

I am looking into AJAX Apps with an IE window as my primary focus.
After I can find these hidden controls using watij (which is where I
have been stumped) I will probably attempt to tackle some MS Word and
Excel customization testing if possible.

So, when I did my watij proof of concept I was merely opening a
browser to a URL, logging in, and sending some combo keys to create a
new object in Documentum. The sendkeys was sort of a desperate
attempt on my part to demonstrate watij's usability, but I'd rather
(and now realize I need to) actually get a handle on the target
control and send it a click event or populate a text field like I did
with the log in screen:

String aUrl = "http://somelocation.com";
String aUserName = "me";
String aPassword = "mypassword";
IE ie = new IE();
User aUser = new User(ie);
aUser.setMyUrl(aUrl);
aUser.login(aUserName, aPassword);
=== user.login() ====================
myBrowser.start(myUrl);
myBrowser.textField(name,"Login_username_0").set(aUserName);
myBrowser.textField(name, "Login_password_0").set(aPassword);
myBrowser.waitUntilReady();
myBrowser.button(name, "Login_loginButton_0").click();
myBrowser.waitUntilReady();
===============================================


This is a nice bit of code if your webpage actually has html elements
like < button > or < input > or the like, but with this new interface
the only tags/elements I get are < script > < link > and some embedded
functions for event registration and stuff.

I've been reading the Watij group up on google and there are others
who appear to have gotten past the point that I'm on, but gleaming my
solution from theirs is not as straight forward as I had hoped and my
java is pretty rusty adding to my challenge.

What I gather so far is that I may need to write my own finder and
that I need to get a handle on the document object which may contain
these hidden controls. So, I've been exploring ie.iWebBrowser2() and
the watij API for this and that's about where I am at.

If you have any examples of where you have written code that can grab
a non-html ajax like element and are able to populate it with text or
if it's a button send it a click, even better a pull down menu item,
selection list item etc., I would be greatly appreciating it :)

Thank you!
Chris"

So, apologies for the lengthy reading, and thank you again for your
advise. I am now going to see how I can leverage this example and
will likely report back to this thread in the hopes that my verbose
problem solution documentation can help others while I get to the
finish line. :)

Cheers!
Chris





On Jan 9, 9:37 am, "Brian Knorr" <btkn...@gmail.com> wrote:
> Hi Chris,
>
> You can send actual javascript to the page via ie.executeScript which will
> evaluate it on the page (so the sky is the limit here).......also the best
> way to handle async javascript calls (ajax) is to use a waiter. For
> example:
>
> ie.link().click(); //fires an ajax call to update something
> new WaiterImpl(10000, 200).waitUntil(new Ready() {
> public boolean isReady() throws Exception {
> return ie.containsText("update successful"); //wait until the text
> is returned from the ajax call
> }
>
> public String getNotReadyReason() {
> return "control doesn't exist";
> }
>
> });
>
> Hope this helps...best,
>
> Brian
>
> > > I grab all of the html elements (ie.elements()) I get the following

Chris Santen

unread,
Jan 14, 2008, 9:46:07 AM1/14/08
to watij
Hat's off to Mushy's mumbeling website where he has an article
praising the use of Watij! He was able to help point me in a
direction that is proving to be towards my goal! What is turning out
to be very helpful is the IE7 add on called "IE Developer Tools" I
can click on any of the screen elements and it will reveal the
element's actual name, attributes and it's path in the DOM. So from
where I'm standing it looks like the use of this tool with the
development of some finders (using some DOM traversal tool perhaps)
and I'll be able to write some useful and re-usable automated tests.
Cheers!
Reply all
Reply to author
Forward
0 new messages