等待用户操作

时间:2015-05-29 14:21:37

标签: javascript selenium testing selenium-webdriver protractor

我正在寻找解决方案,如果可以等待用户在量角器中输入的数据。

我的意思是测试停止一段时间,我可以输入一些值,然后这些数据用于进一步的测试。

我尝试使用javascript提示,但是我做的不多,也许可以在OS终端输入数据?

如果有可能,请举个例子。

3 个答案:

答案 0 :(得分:1)

我不建议混合自动和手动selenium浏览器控件。

也就是说,您可以使用Explicit Waits等待页面上发生的某些事情,例如你可以等待文本出现在文本input中,或者一个元素变得可见,或者页面标题等于你期望的内容,ExpectedConditions内置{ {1}}您可以轻松编写自己的自定义预期条件等待。你必须设置一个合理的超时。

或者,您可以通过protractor传递用户定义的参数,请参阅:

示例:

browser.params

然后,您可以通过protractor my.conf.js --params.login.user=abc --params.login.password=123

访问测试中的值
browser.params

答案 1 :(得分:0)

如果您的数据将驻留在控制台中,则可以使用以下命令获取该数据:

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

然后如其他帖子中所述,您可以使用driver.wait()显式等待条件为真:

var started = startTestServer(); 
driver.wait(started, 5 * 1000, 
'Server should start within 5 seconds'); 
driver.get(getServerUrl());
例如,如果等待多个条件,则

expected conditions

答案 2 :(得分:0)

我有同样的问题。经过长时间的搜索,我找到了一个有效的Protractor 5.3.2的解决方案:

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

    // . . .
});
相关问题