简体   繁体   English

在Selenium测试运行时捕获URL

[英]Capturing URL while Selenium Tests run

i am automating using selenium webdriver and C#. 我正在使用Selenium Webdriver和C#实现自动化。 Is there a way to capture all urls that my browser navigates to while my Selenium automation tests run using an external tool such as Fiddler core / wireshark. 当使用外部工具(例如Fiddler core / wireshark)运行Selenium自动化测试时,是否可以捕获浏览器导航到的所有URL。 I mean while my tests continue to run, I would like some of these tools to capture my urls parallely so that incase my tests fail, i could investigate further by using the final few urls(from the point of failure) to debug the issue. 我的意思是,当我的测试继续运行时,我希望其中一些工具能够并行捕获我的网址,以防万一我的测试失败,我可以通过使用最后几个网址(从失败的角度)来进一步调查问题。

Is this really possible. 这真的有可能吗? Do I need to use a separate thread to one of these tools(Fiddler/wireshark/any other tool) to capture the url? 我是否需要对这些工具之一(Fiddler / wireshark /任何其他工具)使用单独的线程来捕获URL?

Can this really be done 真的可以做到吗

There are a few options. 有一些选择。

  1. Start wireshark (or fiddler) before your Selenium test kicks off. 在Selenium测试开始之前,先启动Wireshark(或Fiddler)。 You can do this with a batch file that gets executed in your test setup. 您可以使用在测试设置中执行的批处理文件来执行此操作。
  2. You can utilize a browser plugin for fiddler. 您可以将浏览器插件用于提琴手。 IE has one, I'm not sure if there is a comparible plugin for all browsers though. IE有一个,我不确定是否所有浏览器都具有可比的插件。 Then you can get Selenium to activate this through the browser...assuming fiddler keeps in the browser window and not open a separate non-browser window that Selenium can't see. 然后,您可以让Selenium通过浏览器激活它……假设提琴手保留在浏览器窗口中,并且没有打开Selenium无法看到的单独的非浏览器窗口。 UPDATE : Fiddler plugins don't stay in the browser window so this option won't work. 更新 :Fiddler插件不会停留在浏览器窗口中,因此该选项将不起作用。
  3. Write some wrapper code that does a driver.Url and stores it into a list. 编写一些执行driver.Url包装器代码,并将其存储在列表中。 This wrapper code would check to see if the driver.Url is different from the last stored entry in the object and if it is different then it would add it to the list. 该包装器代码将检查driver.Url是否与对象中最后存储的条目不同,如果不同,则将其添加到列表中。

All have pros and cons. 都有优点和缺点。 3 would give you the most control as your test itself would gather the URL's and maintain a list in code that you can do what you want with. 3将给您最大的控制权,因为您的测试本身将收集URL并在代码中维护一个列表,您可以根据自己的意愿进行操作。 1 of course would give you the most robust details, depending on how you setup wireshark, and you can profile the entire machine and network experience. 当然,1将为您提供最可靠的详细信息,具体取决于您设置wireshark的方式,并且可以描述整个计算机和网络的体验。 2 is a middle ground where your test still drives it, but the results are separate...but being part of the browser you would have to avoid cleanup after your tests...if you have more tests than one execute at a time this could cause alot of problems... 2是测试仍将其驱动的中间立场,但结果是分开的...但是作为浏览器的一部分,您必须避免在测试后进行清理...如果您一次执行的测试多于一次可能会导致很多问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Azure管道中为C#运行Selenium UI测试。 OpenQA.Selenium.WebDriverException:到远程WebDriver服务器的URL的HTTP请求 - How to Run Selenium UI tests in azure pipeline for c#. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL 无法并行运行测试(Selenium grid + NUnit) - Cannot run tests in parallel (Selenium grid + NUnit) Github Actions run Nunit Selenium 测试问题 - Github Actions run Nunit Selenium tests question 硒测试在本地计算机上运行,​​但不通过詹金斯运行 - Selenium tests run on local machine but not through jenkins 使用C#在多个浏览器中运行Selenium测试 - Run Selenium tests in multiple browsers with C# 在服务器上运行硒测试的理想方法是什么 - What is the ideal way to run selenium tests on server Selenium Grid测试仅运行一次 - Selenium Grid tests will only run once Selenium GRID 2 + NUnit 3选项可并行运行测试 - Selenium GRID 2 + NUnit 3 options to run tests in parallel 使用基类在多个浏览器中运行Selenium测试 - Run Selenium tests in multiple browsers with a base class 如何使用CI(持续集成)运行Selenium测试? - How to run Selenium tests with CI (Continuous Integration)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM