EventFiringWebDriver is not working.

181 views
Skip to first unread message

Amit Kumar

unread,
Aug 16, 2012, 6:00:09 AM8/16/12
to seleniu...@googlegroups.com
Hi All,

I'm trying the following code to capture events in webdriver.

public class WebDriverListerners implements WebDriverEventListener
{
   
    @Override
    public void onException(Throwable throwable, WebDriver webdriver)
    {
        File scrFile = ((TakesScreenshot)webdriver).getScreenshotAs(OutputType.FILE);
        try
        {
        org.apache.commons.io.FileUtils.copyFile(scrFile, new File("C:\);
        }
        catch(Exception e)
        {
           
           
        }
       
    }


     Webdriver velocity=new FirefoxDriver();
   
    EventFiringWebDriver event=new EventFiringWebDriver(velocity);
    event.register(new WebDriverListerners());
    velocity.get(url);

But it does not capture the screenshot as indented if any runtime exception occurs like element not found, alert present etc. The execution never goes inside onException overrided method of WebDriverListerners class.

Please update me if there is existing bug or I'm missing something.


Regards,
Amit Kumar

  

Amit Kumar

unread,
Aug 17, 2012, 1:34:06 AM8/17/12
to seleniu...@googlegroups.com
Hi,

Is there anyone who reply on this.....

Regards,
Amit Kumar

Ramesh Babu Prudhvi

unread,
Aug 17, 2012, 7:59:47 AM8/17/12
to seleniu...@googlegroups.com
Hi Amit,
You can try the following code to capture screenshot on test fail.


public class ScreenShotOnFail extends TestListenerAdapter
{
    static String newScreenShotPath=null;
    static String screenShotFile=null;
    @Override
    public void onTestFailure(ITestResult arg0)
    {
        
        try {
             File location=new File(".");
            
             newScreenShotPath=location.getCanonicalPath()+"\\test-output\\screenShots\\"+arg0.getName()+getdate()+"";
             screenShotFile=newScreenShotPath+"_Report"+".png";
            captureScreenShot(screenShotFile);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        Reporter.log("<a href=\""+ screenShotFile+"\">"+arg0.getName()+"_ErrorLogScreenShot");
    }

    public static void captureScreenShot(String name) throws Exception
    {
         File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
         FileUtils.copyFile(screenshot,new File(name) );
         Thread.sleep(2000);
    }
    public static String getdate()
    {
        DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HHmmss");
        Date date = new Date();
        return dateFormat.format(date);

Amit Kumar

unread,
Aug 18, 2012, 8:22:54 AM8/18/12
to seleniu...@googlegroups.com
Hi ,

You have shared me the testng code, it is fine but I'm bit concerned about why eventfiringwebdriver is not working.

Is this is an existing bug or my implementation is wrong. 

Please respond.

Regards,
Amit Kumar

Amit Kumar

unread,
Aug 22, 2012, 7:21:22 AM8/22/12
to seleniu...@googlegroups.com
Is there anyone to help me out.....

Regards,
Amit Kumar

Peter Gale

unread,
Aug 22, 2012, 7:50:43 AM8/22/12
to Selenium Users
You have this:


     Webdriver velocity=new FirefoxDriver();   
     EventFiringWebDriver event=new EventFiringWebDriver(velocity);
     event.register(new WebDriverListerners());

But when you say:

     velocity.get(url);

Aren't you are using the original FirefoxDriver still, not the EventFiringWebDriver.

I think you want this instead:

    event.get(url);


Date: Wed, 22 Aug 2012 04:21:22 -0700
From: kam...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: EventFiringWebDriver is not working.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/RbPchXInz1AJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages