Skip to content

Commit 34341aa

Browse files
harsha509AutomatedTester
authored andcommitted
Add: Added W3C capability strictFileInteractability(c-nodejs) (#7850)
* Add: Added W3C capability strictFileInteractability(c-nodejs)
1 parent 753dbba commit 34341aa

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

javascript/node/selenium-webdriver/lib/capabilities.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ const Capability = {
212212
* prompts.
213213
*/
214214
UNHANDLED_PROMPT_BEHAVIOR: 'unhandledPromptBehavior',
215+
216+
/**
217+
* Defines the current session’s strict file interactability.
218+
* Used to upload a file when strict file interactability is on
219+
*/
220+
STRICT_FILE_INTERACTABILITY: 'strictFileInteractability',
215221
};
216222

217223

@@ -512,6 +518,13 @@ class Capabilities {
512518
getAlertBehavior() {
513519
return this.get(Capability.UNHANDLED_PROMPT_BEHAVIOR);
514520
}
521+
522+
/**
523+
* Sets the boolean flag configuration for this instance.
524+
*/
525+
setStrictFileInteractability(strictFileInteractability) {
526+
return this.set(Capability.STRICT_FILE_INTERACTABILITY, strictFileInteractability);
527+
}
515528
}
516529

517530

javascript/node/selenium-webdriver/lib/test/fileserver.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const Pages = (function() {
102102
addPage('uploadPage', 'upload.html');
103103
addPage('veryLargeCanvas', 'veryLargeCanvas.html');
104104
addPage('xhtmlTestPage', 'xhtmlTest.html');
105+
addPage('uploadInvisibleTestPage', 'upload_invisible.html');
105106

106107
return pages;
107108
})();

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const W3C_CAPABILITY_NAMES = new Set([
4242
'proxy',
4343
'setWindowRect',
4444
'timeouts',
45+
'strictFileInteractability',
4546
'unhandledPromptBehavior',
4647
]);
4748

javascript/node/selenium-webdriver/test/lib/capabilities_test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919

2020
const Capabilities = require('../../lib/capabilities').Capabilities;
2121
const Symbols = require('../../lib/symbols');
22+
const chrome = require('../chrome');
2223

2324
const assert = require('assert');
25+
const fs = require('fs');
26+
const io = require('../io');
2427

2528
describe('Capabilities', function() {
2629
it('can set and unset a capability', function() {
@@ -126,4 +129,60 @@ describe('Capabilities', function() {
126129
assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
127130
});
128131
});
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+
})
129188
});

0 commit comments

Comments
 (0)