Use EventFiringWebDriver to log all Actions the WebDriver performs during a UnitTest

20 views
Skip to first unread message

Christian Schulze

unread,
Aug 9, 2019, 5:46:35 AM8/9/19
to Selenium Users
I want to use the EventFiringWebDriver to log everything the WebDriver finds or clicks or do in any way happens on a website. The Goal is to get a complete log off all actions the Webdriver performend during a UnitTest. I need this to report this log if a UnitTest fails to give the developer a red line to reproduce the error. 

A log looks for Example like this:

* FindElementComplete with elementId, FindMethod was xy
* Click on the Element with Id 
* etc. 

This is a simple example but the Method:

public class WebDriverEventListener : EventFiringWebDriver
{

public WebDriverEventListener(IWebDriver parentDriver) : base(parentDriver)
{

FindElementCompleted += (sender, e) =>
{

};
}

only returns the Element from which the FindElement was called like someElement.FindElement(By....) and the FindMethod. If the FindElement Method was called by the WebDriver this Element is null. 
But I want to get the WebElement which has been found to put its ID and some additional infos into a datastructure for later use. For Example I click on an Element and then I only get the internal Id of the Element on which I clicked

A workaround can be: The WebElement from which I want to have the internal ID performs a FindElement(By.CssSelector("*") to become the this WebElement as root Element in the Event FindElementCompleted, but I have to do this inside a try/catch because maybe their is nothing inside this Element. But this is really dirty.

Has anybody a good Idea to realize this Idea?
Reply all
Reply to author
Forward
0 new messages