Protractor: Unable to insert 100 000 characters of the test data to a text field

Created on 23 Sep 2015  ·  3Comments  ·  Source: angular/protractor

Hi. For the testing purpose I need to insert 100 000 characters to the input field. The problem is that sendKeys() cannot handle such amount of data and the browser freezes. It starts input data to a text field and then after some time stops respond and the test fails because of timeout.

I tried different ways to solve this problem, like divide the file on the few pieces but it can't handle even 30 000 characters.

Manually I'm just copy-pasting the data from the text editor to that field and it works fine.

Does somebody have the solution how to insert into the text field 100 000 of characters?
Thank you!

Code:
var fs = require('fs');
var path = require('path');
var filePath = path.join(__dirname, 'datafile.json');
var data=require(filePath)
browser.findElement(By.tagName("textarea")).sendKeys(data.cbb);
browser.sleep(5000);
browser.findElement(By.name("Submit")).click();

question

All 3 comments

WebDriver's sendKeys isn't really intended to handle 100,000 keypresses. It simulates events natively, so for each individual character it's sending a separate request.

I suppose you could get around this by setting the text directly through JavaScript executed in the browser:

browser.executeScript('findMyTextarea.textContent="myreallyreallylongstring"');

Closing as a support question - Please direct general support questions like this one to an appropriate support channel, see https://github.com/angular/protractor/blob/master/CONTRIBUTING.md#questions

I've resolved this problem with this code:

var data = fs.readFileSync(filePath,'utf8')
var element = browser.findElement(By.tagName("textarea"));
browser.executeScript("arguments[0].value = arguments[1];", element, data);

Thank you for your help! :+1:

Was this page helpful?
0 / 5 - 0 ratings