Created
April 22, 2021 21:26
-
-
Save KonnorRogers/5fe937ee60695ff1d227f18fe4b1d5c4 to your computer and use it in GitHub Desktop.
Clipboard reading in Capybara
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "should read clipboard text" do | |
page.driver.browser.execute_cdp( | |
"Browser.setPermission", | |
{ | |
origin: page.server_url, | |
permission: { name: "clipboard-read" }, | |
setting: "granted", | |
}) | |
clip_text = page.evaluate_async_script("navigator.clipboard.readText().then(arguments[0])") | |
expect(clip_text).to eq("copied text") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for using the latest async clipboard API.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard
https://chromedevtools.github.io/devtools-protocol/tot/Browser/#type-PermissionSetting