tealang
tealang

Reputation: 201

Wait for user action

I am looking for a solution, if it is possible to wait for the data entered by the user in protractor.

I mean test stop for a while and I can enter some value and then these data are used in further tests.

I tried to use javascript prompt, but I did not do much, maybe it is possible to enter data in OS terminal?

Please give me an example if it is possible.

Upvotes: 3

Views: 1404

Answers (3)

Paulo Merson
Paulo Merson

Reputation: 14477

I had the same question. After a long search I found a solution with Protractor 5.3.2 that worked:

var EC = protractor.ExpectedConditions;

it('will pause for input...', function() {
    browser.ignoreSynchronization = true
    browser.waitForAngularEnabled(false);

    // open web page that contains an input (in my case it was captchaInput)
    browser.driver.get('https://example.com/mywebpagehere');

    // waits for 15 sec for the user to enter something. The user shall not click submit 
    browser.wait(EC.textToBePresentInElementValue(captchaInput, '999'), 15000, "Oops  :^(")   
        .then(function() {
            console.log('Hmm... Not supposed to run!');
        }, function() {
            console.log('Expected timeout, not an issue');
        });

    browser.sleep(1000);   

    // submit the user input and execution proceeds (in my case, captchaButton)
    captchaButton.click();

    // . . .
});

Upvotes: 0

magicode118
magicode118

Reputation: 1474

If your data will reside in the console, you can get that data by using the following:

browser.manage().logs().get('browser').then(function(browserLogs) {
   // browserLogs is an array which can be filtered by message level
   browserLogs.forEach(function(log){
      if (log.level.value < 900) { // non-error messages
        console.log(log.message);
      }
   });
});

Then as mentioned in other posts, you can explicitly wait for a condition to be true by using driver.wait():

var started = startTestServer(); 
driver.wait(started, 5 * 1000, 
'Server should start within 5 seconds'); 
driver.get(getServerUrl());

Or expected conditions if waiting for more than one condition, for example.

Upvotes: 0

alecxe
alecxe

Reputation: 473893

I would not recommend mixing the automatic and manual selenium browser control.

That said, you can use Explicit Waits to wait for certain things to happen on a page, e.g. you can wait for the text to be present in a text input, or an element to become visible, or a page title to be equal to something you expect, there are different ExpectedConditions built-in to protractor and you can easily write your own custom Expected Conditions to wait for. You would have to set a reasonable timeout though.


Alternatively, you can pass the user-defined parameters through browser.params, see:

Example:

protractor my.conf.js --params.login.user=abc --params.login.password=123

Then, you can access the values in your test through browser.params:

var login = element(by.id("login"));
login.sendKeys(browser.params.login.user);

Upvotes: 1

Related Questions