- stacaz
- Posts : 4
Join date : 2010-06-11
verifyTrue (FALSE) causes AssertionError: null
Thu Jun 24, 2010 2:37 am
I have the error: "java.lang.AssertionError: null" with the following code:
import java.util.Calendar;
import java.util.Properties;
import java.util.Vector;
import junit.framework.AssertionFailedError;
import java.lang.AssertionError;
import javax.mail.*;
import javax.mail.internet.*;
import com.thoughtworks.selenium.*;
try {
. . . previous code steps. . . .
verifyTrue(selenium.isTextPresent("some text is here");
. . . other code . . . .
} Catch SeleniumException e){
some code
} Catch AssertionFailedError e){
some code
} Catch Exception e){
some code
} Catch Error e){
some code
}
I have nailed the error down to the verifyTrue line.
I have also tried assertTrue(selenium.isTextPresent("some text here");, but it throws a "null" exception and stops the test run in the middle.
How do you verify if text is on a web page???
Thanks!
import java.util.Calendar;
import java.util.Properties;
import java.util.Vector;
import junit.framework.AssertionFailedError;
import java.lang.AssertionError;
import javax.mail.*;
import javax.mail.internet.*;
import com.thoughtworks.selenium.*;
try {
. . . previous code steps. . . .
verifyTrue(selenium.isTextPresent("some text is here");
. . . other code . . . .
} Catch SeleniumException e){
some code
} Catch AssertionFailedError e){
some code
} Catch Exception e){
some code
} Catch Error e){
some code
}
I have nailed the error down to the verifyTrue line.
I have also tried assertTrue(selenium.isTextPresent("some text here");, but it throws a "null" exception and stops the test run in the middle.
How do you verify if text is on a web page???
Thanks!
- metmanAmateur
- Posts : 58
Join date : 2010-04-02
Re: verifyTrue (FALSE) causes AssertionError: null
Thu Jun 24, 2010 3:15 am
Well, that code shouldn't compile, given that you are missing a close paren. Otherwise, what is your actual search string? There could be something funky going on with the formatting there.
- stacaz
- Posts : 4
Join date : 2010-06-11
Re: verifyTrue (FALSE) causes AssertionError: null
Thu Jun 24, 2010 3:33 am
That's not all the code. What I am trying to figure out is why the catch is not trapping verifyTrue, and why an assertTrue does not work like I want either. I am new to Selenium and J-Unit, and very rusty on Java. There is much here than shown. And it all works fine, except for the 'verifyTrue' lines.
Here is it more accurately, showing the relevant sections:
import java.util.Calendar;
import java.util.Properties;
import java.util.Vector;
import junit.framework.AssertionFailedError;
import java.lang.AssertionError;
import javax.mail.*;
import javax.mail.internet.*;
import com.thoughtworks.selenium.*;
[prior code here]
try {
selenium.setTimeout("10000");
selenium.open(url);
assertEquals("Whatever text", selenium.getTitle()); //this works fine
selenium.click("SubmitBtn");
verifyTrue(selenium.isTextPresent("Whatever Text"); //causes the 'AssertionError: null' in failure trace.
assertTrue(selenium.isTextPresent("Also Whatever Text"); //error gets caught, but stops the whole test and output of the exception is "null".
}
catch (AssertionFailedError e) { some stuff here }
catch (AssertionError e) { some stuff here }
catch (Exception t) { some stuff here }
catch (Error e) { some stuff here }
[rest of code here]
Here is it more accurately, showing the relevant sections:
import java.util.Calendar;
import java.util.Properties;
import java.util.Vector;
import junit.framework.AssertionFailedError;
import java.lang.AssertionError;
import javax.mail.*;
import javax.mail.internet.*;
import com.thoughtworks.selenium.*;
[prior code here]
try {
selenium.setTimeout("10000");
selenium.open(url);
assertEquals("Whatever text", selenium.getTitle()); //this works fine
selenium.click("SubmitBtn");
verifyTrue(selenium.isTextPresent("Whatever Text"); //causes the 'AssertionError: null' in failure trace.
assertTrue(selenium.isTextPresent("Also Whatever Text"); //error gets caught, but stops the whole test and output of the exception is "null".
}
catch (AssertionFailedError e) { some stuff here }
catch (AssertionError e) { some stuff here }
catch (Exception t) { some stuff here }
catch (Error e) { some stuff here }
[rest of code here]
- stacaz
- Posts : 4
Join date : 2010-06-11
Re: verifyTrue (FALSE) causes AssertionError: null
Thu Jun 24, 2010 3:36 am
Here is the actual verifyTrue line:
verifyTrue(selenium.isTextPresent("ERROR\r\nPlease enter your Cell Phone Number in the following format: ###-###-####\r\nIt should be ten digits long beginning with your area code."));
verifyTrue(selenium.isTextPresent("ERROR\r\nPlease enter your Cell Phone Number in the following format: ###-###-####\r\nIt should be ten digits long beginning with your area code."));
- stacaz
- Posts : 4
Join date : 2010-06-11
Re: verifyTrue (FALSE) causes AssertionError: null
Thu Jun 24, 2010 3:54 am
Ok, I simplified it down to this very short piece of code after removing everything else. Apparently you can't use \r and \n as new line and return. I have removed those.
So, I get no errors when "test text" is on the page, but I get the AssertionError: null in the trace log when "test text" is NOT on the page:
verifyTrue(selenium.isTextPresent("test text"));
Why am I getting this error?? How do I catch the error when that text does NOT appear on the web page without blowing up the test?
I still have those catch blocks per the above post. But apparently none of them are catching the error!
So, I get no errors when "test text" is on the page, but I get the AssertionError: null in the trace log when "test text" is NOT on the page:
verifyTrue(selenium.isTextPresent("test text"));
Why am I getting this error?? How do I catch the error when that text does NOT appear on the web page without blowing up the test?
I still have those catch blocks per the above post. But apparently none of them are catching the error!
- metmanAmateur
- Posts : 58
Join date : 2010-04-02
Re: verifyTrue (FALSE) causes AssertionError: null
Thu Jun 24, 2010 4:30 am
I'd suggest using assertTrue from jUnit rather than verifyTrue. That's what I use for these types of things, and it works fine for me. Also, if you read the JavaDocs, raw string is not the default interpretation for isTextPresent. Try prepending "exact:" to the beginning of your search string and see if that works any better. No guarantees, but that's what I'd try.
- window is "null" or not an object
- how to verify the condition using verifytext and store the value in to variable either true or false.
- error in eclipse java.lang.RuntimeException: Could not start Selenium session: null
- Selenium RC verifyTrue(selenium.isTextPresent(“string”))
- selenium.isTextPresent() and selenium.isElementPresent() are NULL
Permissions in this forum:
You cannot reply to topics in this forum
|
|