New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2550 Implement downloading files via CDP #2567
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add integration tests as in integration.FileDownloadToFolderTest
src/main/java/com/codeborne/selenide/impl/DownloadFileToFolderCdp.java
Outdated
Show resolved
Hide resolved
src/main/java/com/codeborne/selenide/impl/DownloadFileToFolderCdp.java
Outdated
Show resolved
Hide resolved
src/main/java/com/codeborne/selenide/impl/DownloadFileToFolderCdp.java
Outdated
Show resolved
Hide resolved
src/main/java/com/codeborne/selenide/impl/DownloadFileToFolderCdp.java
Outdated
Show resolved
Hide resolved
src/main/java/com/codeborne/selenide/impl/DownloadFileToFolderCdp.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add integration tests as in integration.FileDownloadToFolderTest
Add tests to |
@britka Few tests failed in Firefox: FileDownloadToFolderWithCdpTest > downloadLargeFile() FAILED
java.lang.IllegalArgumentException: The browser you selected "firefox" doesn't have Chrome Devtools protocol functionality.
at com.codeborne.selenide.impl.DownloadFileToFolderCdp.initDevTools(DownloadFileToFolderCdp.java:78)
at com.codeborne.selenide.impl.DownloadFileToFolderCdp.prepareDownloadWithCdp(DownloadFileToFolderCdp.java:83)
at com.codeborne.selenide.impl.DownloadFileToFolderCdp.download(DownloadFileToFolderCdp.java:49)
at com.codeborne.selenide.commands.DownloadFile.execute(DownloadFile.java:75)
at com.codeborne.selenide.commands.DownloadFile.execute(DownloadFile.java:29)
at com.codeborne.selenide.commands.Commands.execute(Commands.java:161)
at integration.FileDownloadToFolderWithCdpTest.downloadLargeFile(FileDownloadToFolderWithCdpTest.java:265) You can add |
Ok. I'll add that |
@asolntsev @BorisOsipov I will revert some changes. Variant 2. What do you think? |
If the user has chosen FOLDER, we should use the FOLDER method and not confuse the user with some of our predictions about how we can make the file available to them. |
…ipped if browser is firefox
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@BorisOsipov agree. |
@asolntsev I fixed the tests according to your comments |
src/main/java/com/codeborne/selenide/impl/DownloadFileToFolderCdp.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
private void initDevTools(Driver driver) { | ||
if (driver.browser().isChromium()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace driver.browser().isChromium()
by driver.getWebDriver() instanceof HasDevTools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asolntsev I disagree with you. For example, FirefoxDriver
is also implementing HasDevTools
interface. But it doesn't support this functionality. It uses devtools v.85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried - Firefox does download the file. Only command setDownloadBehavior
doesn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to leave current implementation if you do not mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we forbid this functionality in Firefox if it works.
Browser.downloadProgress(), | ||
e -> { | ||
downloadComplete.set(e.getState() == COMPLETED); | ||
log.debug("Download is in progress"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would log "Download is completed" if
e.getState() == COMPLETED`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I check this in other piece of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this log is lying. It says Download is in progress
, but the download is actually completed.
src/test/java/com/codeborne/selenide/impl/DownloadFileToFolderCdpTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/codeborne/selenide/impl/DownloadFileToFolderCdpTest.java
Outdated
Show resolved
Hide resolved
statics/src/test/java/integration/FileDownloadToFolderWithCdpTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asolntsev Fixed unused imports |
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
…e it got "completed" it seems that CDP continues sending events "inProgress" (14 of 14 bytes) even AFTER it already sent the "completed" event. We will just ignore them.
…for N ms this feature ("increment timout") was implemented only in FOLDER mode, now in CDP as well.
CDP may send "in progress" events about multiple files simultaneously. We need to track of all them, and pick the right file using given FileFilter.
e.g. when Chrome is running in Selenoid
…e it got "completed" it seems that CDP continues sending events "inProgress" (14 of 14 bytes) even AFTER it already sent the "completed" event. We will just ignore them.
…for N ms this feature ("increment timout") was implemented only in FOLDER mode, now in CDP as well.
CDP may send "in progress" events about multiple files simultaneously. We need to track of all them, and pick the right file using given FileFilter.
e.g. when Chrome is running in Selenoid
Proposed changes
Add new download method CDP. It works similar to FOLDER approach but now this process is controlled by browser.
To use this download method you need to use snippet
Note
This method works only for Chromium based browsers
For more information see:
Checklist
gradlew check chrome_headless firefox_headless
command