Taking screenshots only if there is an error

583 views
Skip to first unread message

remya

unread,
May 2, 2012, 12:53:50 PM5/2/12
to webdriver
Hi All,

I need to take screenshot of pages only when there is an error
(say validation error messages which appear in red colour), when the
application comes to a standstill encountered
by an exception(say Element Not Found Exception).
How do i approach this? I have already implemented the logic for
taking screenshots.
Can you guys shed some light on the approach i should take?

Thanks in Advance!



Peter Gale

unread,
May 2, 2012, 12:59:46 PM5/2/12
to webd...@googlegroups.com
Try writing a handler to catch all exceptions and insert the code for taking a screenshot in the catch clause of the handler.
 
> Date: Wed, 2 May 2012 09:53:50 -0700
> Subject: [webdriver] Taking screenshots only if there is an error
> From: rem...@gmail.com
> To: webd...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

Tarun Kumar

unread,
May 3, 2012, 1:50:02 AM5/3/12
to webd...@googlegroups.com
I had blogged on it some time ago - http://www.seleniumtests.com/2008/09/capture-screenshot-on-test-failure.html
might help.

Anshul Singh

unread,
May 3, 2012, 3:00:40 AM5/3/12
to webd...@googlegroups.com
Put all failure conditions  in catch block along with screen-capture code  .Every time any test case will fail ,it will execute screen capture code .

Thanks,
Anshul

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/fXRQdkQFzX0J.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.



--

~ Anshul 


darrell

unread,
May 3, 2012, 8:28:33 AM5/3/12
to webdriver
Tarun's example is good but if you don't want to use TestNG and Fest
here is my solution using just WebDriver code:
http://darrellgrainger.blogspot.ca/2011/02/generating-screen-capture-on-exception.html.

remya

unread,
May 3, 2012, 9:39:48 AM5/3/12
to webdriver
Thanks All!!

i have got an idea...how to approach if there are any exceptions.
How to track the validation error messages which appear(red coloured
messages)in the application..
how can i track them in webdriver....?


On May 3, 1:28 pm, darrell <darrell.grain...@gmail.com> wrote:
> Tarun's example is good but if you don't want to use TestNG and Fest
> here is my solution using just WebDriver code:http://darrellgrainger.blogspot.ca/2011/02/generating-screen-capture-....

darrell

unread,
May 15, 2012, 9:28:01 AM5/15/12
to webdriver
If an application throws an exception that is a standard which
Selenium can work with. If the software developer is catching the
exception and displaying a custom message to the user in red there is
no standard for this. Typically, a developer will create an invisible
div on all pages. If an error occurs, the code will set the text of
the div to an error message, change the colour of the font to red then
make the div visible. They might be doing something similar but not
exactly the same. What you will need to do is figure out if there is a
pattern the developer is using to display error messages and write a
method to check for error messages. For example, my application has:

<div id="err_msg" style="color: red"></div>

If an error occurs, the javascript will update the DOM so it becomes:

<div id="err_msg" style="color: red">Your error message goes
here.</div>

When I write my automation I would have a method to check the error
message:

public String getCurrentErrorMessage() {
WebElement div = driver.findElement(By.id("err_msg"));
return div.getText();
}

A call to this method with no error message returns "". If an error
occurred it returns the error message text. There is no way to
automatically detect the error message and create a screen shot. I
just know that certain actions may result in an error so I explicitly
look for the error message.
Reply all
Reply to author
Forward
0 new messages