3

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.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
tealang
  • 201
  • 1
  • 3
  • 11

3 Answers3

1

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);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • thanks, for a quick answer, but I mean something else, (I need something else, I don't need wait for element to load on page). I need to enter some data during test, depending on what I see on the screen. e.g during test i see in console :"enter value" and I enter value and test go to next step – tealang May 29 '15 at 14:35
  • but I don't have a input box, on page which i test. I want own input box ( prompt or enter data in console)created by protractor. – tealang May 29 '15 at 14:39
  • 1
    @tealang alright, I'm getting closer to what you are asking about. Could you provide an example real world use case of the problem? Thanks. – alecxe May 29 '15 at 14:40
  • @tealang nono, I mean, give me a bigger picture and the motivation behind the question. – alecxe May 29 '15 at 14:48
0

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.

magicode118
  • 1,444
  • 2
  • 17
  • 26
  • I think you didn't understand my question. I want enter data yourself. I mean I want (during test execution) create prompt( or something else) to enter data and these data will be used in test. – tealang May 31 '15 at 13:10
  • Question: Will you know what that data will be before the test starts, or during the test itself? What are you trying to accomplish? Answers to these questions will help us help you better – magicode118 Jun 02 '15 at 15:19
0

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();

    // . . .
});
Paulo Merson
  • 13,270
  • 8
  • 79
  • 72