Problem with a custom test step

2 views
Skip to first unread message

Clément Beaujoin

unread,
Mar 25, 2009, 12:01:53 PM3/25/09
to CubicEx-discuss
Hi, i'm working on a custom test named VerifyCount, it counts how many
time a locator is present and compare to the expected count. If it's
true test should be validate and if it's false the test should be
display as fail.
But the test is considered as valid everytime.

Here is the code :

public void executeTest(Map<String, String> arguments, IElementContext
context, Selenium selenium) throws Exception {

// Retrieve the parameters.
final String _locator = getArgTarget();
final Integer _value = getArgValueAsInteger();
final Integer _deviation = getArgDeviation();

if (log.isInfoEnabled()) {
log.info("VerifyCount: target '" + _locator + "', value '" + _value
+ "', deviation '" + _deviation + "'.");
}
// Retrieve the count
Integer _countOfElement = selenium.getXpathCount(_locator).intValue
();

switch(_deviation)
{
case 0 :
verifyTrue((boolean)(_value == _countOfElement));
break;

case 1 :
verifyTrue((boolean)(_countOfElement < _value));
break;

case 2 :
verifyTrue((boolean)(_countOfElement > _value));
break;
}
}


Any Idea?

Ronald Mathies

unread,
Mar 25, 2009, 1:50:23 PM3/25/09
to CubicEx-discuss
Hmm... i have created the same command based on your code and counted
how many times a button appears on my page. The xpath expression was
correct since it resulted with me in 12 buttons. Since i said i wanted
to be sure that my expected count is smaller then the actual count i
would also expect it to fail.

And actually it does fail, internally the SeleneseTestBase does
perform the following:

/** Like assertTrue, but fails at the end of the test (during
tearDown) */
public void verifyTrue(boolean b) {
try {
assertTrue(b);
} catch (Error e) {
verificationErrors.append(throwableToString(e));
}
}

And i do get an exception which is caught and added to the
verificationErrors... but the test resulted in a green square in my
flow and i did not see any logging... So i am also quite amazed. You
component works fine, it is the handling of the verificationErrors
that gives some problems.

I am going to look further into this to see if it is something we can
solve.

Ronald Mathies

unread,
Mar 25, 2009, 1:59:28 PM3/25/09
to CubicEx-discuss
I don't know if my message was send correctly since i don't see it
back here again (maybe i send it directly to you. So here goes
again :)

I created exactly the same command as what you have using your code
and i see the same result. When i use debugging i see it fails and
that an exception is thrown and handled properly. However in the end
it doesn't show anything.

I do notice two things, the first is that the exception doesn't have
any description but it is NULL which could mean that it does print to
the log
but it doesn't have anything to print.

So i tried it with one of my other verify commands to let it fail on
purpose and i noticed the following:

verifyTrue((boolean)(_countOfElement > _value));
verifyTrue(_countOfElement > _value);
verifyEquals(_countOfElement > _value, true);

All don't show anything, but when i change it to the following:

verifyEquals(String.valueOf(_value == _countOfElement), "true");

Then i do get a message saying that the test failed:

expected "true" to match glob "false" (had transformed the glob into
regexp "false"

So i would say there is something wrong with handling the booleans.

On Mar 25, 5:01 pm, Clément Beaujoin <cbeauj...@gmail.com> wrote:

Ronald Mathies

unread,
Mar 26, 2009, 2:19:58 AM3/26/09
to CubicEx-discuss
Hi Clément,

I made a mistake in my previous post:

verifyEquals(String.valueOf(_value == _countOfElement), "true");

should be

verifyEquals(String.valueOf(_value.intValue() ==
_countOfElement.intValue()), "true");

I have added your component to the library, i made some changes in to
what kind of comparisons it can do so that it is a bit clearer in how
it can be used and it provides some more check capabilities.

I also created an Assert version of it.

Currently the checks are performed like this:

if (_action.equalsIgnoreCase("<")) {
verifyEquals(String.valueOf(_countOfElement.intValue() <
_value.intValue()), "true");
} else if (_action.equalsIgnoreCase("==")) {
verifyEquals(String.valueOf(_countOfElement.intValue() ==
_value.intValue()), "true");
} else if (_action.equalsIgnoreCase(">")) {
verifyEquals(String.valueOf(_countOfElement.intValue() >
_value.intValue()), "true");
} else if (_action.equalsIgnoreCase("<=")) {
verifyEquals(String.valueOf(_countOfElement.intValue() <=
_value.intValue()), "true");
} else if (_action.equalsIgnoreCase(">=")) {
verifyEquals(String.valueOf(_countOfElement.intValue() >=
_value.intValue()), "true");
} else if (_action.equalsIgnoreCase("!=")) {
verifyEquals(String.valueOf(_countOfElement.intValue() !=
_value.intValue()), "true");
}

I introduced a new property action which can take on of the following
values <, <=, ==, >=, > and !=.
This also makes it a bit clearer then using 0, 1, 2.

Clément Beaujoin

unread,
Mar 26, 2009, 11:10:34 AM3/26/09
to CubicEx-discuss
Hi ronald,

thank you for this commands, it works fine :)
Moreover it's a good idea to have introduced the action property, it
will be very useful for other commands.
So, I'm going to refactor my other commands then i will send you (next
week i think).

See u
Reply all
Reply to author
Forward
0 new messages