|
19 | 19 |
|
20 | 20 | const Capabilities = require('../../lib/capabilities').Capabilities;
|
21 | 21 | const Symbols = require('../../lib/symbols');
|
| 22 | +const chrome = require('../chrome'); |
22 | 23 |
|
23 | 24 | const assert = require('assert');
|
| 25 | +const fs = require('fs'); |
| 26 | +const io = require('../io'); |
24 | 27 |
|
25 | 28 | describe('Capabilities', function() {
|
26 | 29 | it('can set and unset a capability', function() {
|
@@ -126,4 +129,60 @@ describe('Capabilities', function() {
|
126 | 129 | assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
|
127 | 130 | });
|
128 | 131 | });
|
| 132 | + |
| 133 | + describe('StrictFileInteractability capability', function(env){ |
| 134 | + it('should fail to upload files to a non interactable input when StrictFileInteractability is on', async function(){ |
| 135 | + const options = new chrome.Options; |
| 136 | + options.setStrictFileInteractability(true); |
| 137 | + const driver = env.builder().setChromeOptions(options).build(); |
| 138 | + |
| 139 | + const LOREM_IPSUM_TEXT = 'lorem ipsum dolor sit amet'; |
| 140 | + const FILE_HTML = '<!DOCTYPE html><div>' + LOREM_IPSUM_TEXT + '</div>'; |
| 141 | + |
| 142 | + let fp = await io.tmpFile().then(function(fp) { |
| 143 | + fs.writeFileSync(fp, FILE_HTML); |
| 144 | + return fp; |
| 145 | + }); |
| 146 | + |
| 147 | + driver.setFileDetector(new remote.FileDetector); |
| 148 | + await driver.get(Pages.uploadInvisibleTestPage); |
| 149 | + const input = await driver.findElement(By.id("upload")); |
| 150 | + try{ |
| 151 | + await input.sendKeys(fp); |
| 152 | + assert(false, "element was interactable") |
| 153 | + } catch (e) { |
| 154 | + assert(e.message.includes("element not interactable")) |
| 155 | + } |
| 156 | + }); |
| 157 | + |
| 158 | + it('Should upload files to a non interactable file input', async function() { |
| 159 | + |
| 160 | + const LOREM_IPSUM_TEXT = 'lorem ipsum dolor sit amet'; |
| 161 | + const FILE_HTML = '<!DOCTYPE html><div>' + LOREM_IPSUM_TEXT + '</div>'; |
| 162 | + |
| 163 | + let fp = await io.tmpFile().then(function(fp) { |
| 164 | + fs.writeFileSync(fp, FILE_HTML); |
| 165 | + return fp; |
| 166 | + }); |
| 167 | + |
| 168 | + const options = new chrome.Options; |
| 169 | + options.setStrictFileInteractability(false); |
| 170 | + const driver = env.builder().setChromeOptions(options).build(); |
| 171 | + |
| 172 | + driver.setFileDetector(new remote.FileDetector); |
| 173 | + await driver.get(Pages.uploadInvisibleTestPage); |
| 174 | + |
| 175 | + await driver.findElement(By.id('upload')).sendKeys(fp); |
| 176 | + await driver.findElement(By.id('go')).click(); |
| 177 | + |
| 178 | + // Uploading files across a network may take a while, even if they're really small |
| 179 | + let label = await driver.findElement(By.id("upload_label")); |
| 180 | + driver.wait(until.elementIsNotVisible(label), 10000); |
| 181 | + |
| 182 | + driver.switchTo().frame("upload_target"); |
| 183 | + |
| 184 | + let body = driver.findElement(By.xpath("//body")); |
| 185 | + driver.wait(until.elementTextMatches(body, LOREM_IPSUM_TEXT),10000); |
| 186 | + }); |
| 187 | + }) |
129 | 188 | });
|
0 commit comments