Open edurenye opened 6 years ago
“Pausing” the execution of a Selenium test can be done by the client by holding off the next HTTP request. Does that not fulfil your requirement?
No, it does not pause the execution of the JS code, pause feature should behave like a breakpoint that acts wherever you are at the exact moment when you pause the webdriver.
That sounds like something one would use CDP or the Firefox Devtools protocol for.
@andreastt You can see this example: https://github.com/SeleniumHQ/selenium/issues/5269
@edurenye @eromoe, I'd like to ask for some additional detail on what is being requested here, if you don't mind. Two things mainly:
If you have examples of things that could be made reliable but are now impossible/flaky, that would also be great.
Disclaimer: I work on the Chrome team but not on ChromeDriver, but a similar request to this has come up internally and I'm trying to see if it's the same underlying need. Can't promise that anything will happen in the spec or in ChromeDriver.
Well, I don't even work anymore for the company where I was working when I needed this, I changed company one month after I created this issue, so I don't really remember why I needed. I think at the moment I was running Scrapy and it was failing at some point to fetch something and I wanted to debug what was happening. But also I wanted this even earlier to debug some automatic test I did in Drupal and I wanted it to stop in the middle of a JS execution to debug it, something like it, don't recall why I couldn't use the non headless version of Chrome and just set a breakpoint.
@foolip I have an example in https://github.com/SeleniumHQ/selenium/issues/5269
As I remember, I was crawling a js site . Maybe that site had some auto sliding blocks(js control) . I couldn't get all infomation stably if there is no pause function . Since the api may be very complicated I don't tend to mock request . I mean this pausing abbility is mainly tend to reduce my crawling work . You don't need to understand the api, only interact with frontend ui , easy found partern and fault .
Pause dom changing and js execution are both need .This is also good for automated testing .
About "wait for all queued work to finish and then pause" , sounds right . It would be good to pause when an element appeared on dom , like pause_when_element_appeared(some_css_selector)
Mainly inspect the DOM once paused . Or maybe I would insert some custom js header to that site(like what tampermonkey do ) .
https://github.com/WICG/page-lifecycle/issues/42 may address some of the use cases here.
@edurenye @eromoe, I'd like to ask for some additional detail on what is being requested here, if you don't mind. Two things mainly:
- What is the moment at which you'd typically like pause the browser? Is it simply when the command is received, or is the ask more like "wait for all queued work to finish and then pause"?
- What are the things that you'd like to do once paused? Screenshots haven't been mentioned, so is this mainly about running scripts to inspect the DOM once paused?
If you have examples of things that could be made reliable but are now impossible/flaky, that would also be great.
Disclaimer: I work on the Chrome team but not on ChromeDriver, but a similar request to this has come up internally and I'm trying to see if it's the same underlying need. Can't promise that anything will happen in the spec or in ChromeDriver.
I see the need for a pause/resume functionality because it would make "atomic" transactions possible. The reality with modern frameworks like Angular or React is that elements or entire element trees are exchanged with similar/equal elements without the user noticing it (looks the same or similar, but the web element reference IDs have changed). Combined with the fact that with the WebDriver protocol it is not possible to send two request without the risk of something in the DOM changing in between the two requests, it makes some things impossible.
Let's say you want to get all h2 elements whose text represents a prime number. Typically you want (1) get all h2 elements. And then (2) for all of these h2 elements you would retrieve the texts. If between (1) and (2) parts of the DOM have been exchanged, you will get stale element reference exceptions. Let's say the 37th h2 has become stale. What should you do? You could try to retrieve the list of all h2 elements again. But if the DOM change happens very frequently, let's say every 16 ms, then you could be in an endless loop. And there is no mechanism to start with the 37th element. And even if there was some mechanism, you still don't know if the list before is still valid.
With a pause/resume function, you could solve this problem. (a) Send 'pause' (b) Send 'get elements with tag name "h2"' (c) for all found elements, send 'get text' (d) Send 'resume' Between (a) and (d) the DOM would not change.
To be able to pause Selenium or any other application that uses webdriver, we need to add this feature to webdriver. It's interesting to be able to pause the execution in a concrete moment, read something in the DOM or perform other tasks and be able to resume it again afterwards. You can see more use cases in the original issue from Selenium: SeleniumHQ/selenium#5269