Magenic / MAQS

Magenic's automation quick start
MIT License
45 stars 18 forks source link

How to GetDevToolsSession() in MAQS 7 #910

Closed pjotal closed 2 years ago

pjotal commented 2 years ago

The documentation so far doesn't describe how we can leverage one of the richest features of Selenium 4 in MAQS 7, which is using Chrome dev tools.

I tried the following piece of code and got an error. DevToolsSession session = ((ChromeDriver)WebDriver).GetDevToolsSession();

error: System.InvalidCastException : Unable to cast object of type 'OpenQA.Selenium.Support.Events.EventFiringWebDriver' to type 'OpenQA.Selenium.Chrome.ChromeDriver'.

Haven't anything in the documentation describing classes to support the usage of Selenium Bidi or CDP so would like to suggest you document how we can use CDP until an official implementation is provided via MAQS.

thanks :)

TroyWalshProf commented 2 years ago

DevToolsSession session = ((ChromeDriver)WebDriver.GetLowLevelDriver()).GetDevToolsSession();

pjotal commented 2 years ago

hi troy,

It seems GetLowLevelDriver() is not available at the test class level.

Got it going with the following code but i am not sure this is what you would suggest.

var driver = WebDriverFactory.GetDefaultBrowser();
TestObject.WebManager.OverrideDriver(driver);
var session = ((ChromeDriver)driver).GetDevToolsSession();

Also noticed that even though i've set to override the driver with a ChromeDriver i am still getting the EventFiringWebDriver when i call WebDriver later on. This also makes it a bit harder for me to consume the Network and Fetch classes later on :(

TroyWalshProf commented 2 years ago

Add the following using statement to be able to access GetLowLevelDriver: Using Magenic.Maqs.BaseSeleniumTest.Extensions

pjotal commented 2 years ago

worked for me. thanks :) feel free to close the ticket if you wish.

btw.. any chances you'll include some new features to easy intercepting request and response calls in near future releases? that would be great.

TroyWalshProf commented 2 years ago

This can be done with the Playwright feature in MAQS 9 Note* The MAQS project has moved to here: https://github.com/CognizantOpenSource/maqs-dotnet