【问题标题】:How can I use Protractor with google.com?如何在 google.com 中使用 Protractor?
【发布时间】:2015-06-29 03:58:23
【问题描述】:

google.com 不是 Angular 应用程序,但 Protractor 应该仍然可以对其进行测试,对吧?我一直在尝试对搜索进行简单测试,但一直出错。

规格:

browser.ignoreSynchronization = true;

describe('Google Demo', function() {
  it('Should Search', function() {
    browser.get('http://google.com/');
    browser.wait(element(By.id('q')).isPresent);
    element(By.id('q')).sendKeys('please work');
  });
});

错误是:

Failures:

1) Google Demo Should Search
 Message: TypeError: Cannot read property 'count' of undefined

我做错了什么?如有任何帮助,我将不胜感激!

【问题讨论】:

标签: testing selenium protractor


【解决方案1】:

由于它是一个非 Angular 应用程序,因此您需要使用 browser.driver 而不仅仅是 browserGitHub Link for non-angular app

browser.ignoreSynchronization = true;

describe('Google Demo', function() {
  it('Should Search', function() {
    browser.driver.get('http://google.com/');   
    browser.driver.findElement(by.name('q')).sendKeys('please work');
  });
});

这在我的系统上运行!

【讨论】:

    【解决方案2】:

    这也适用于非 Angular 应用程序

    browser.waitForAngularEnabled(false);
    

    describe('Google search', function() {
        it('should search a text as GURU99', function() {
        browser.waitForAngularEnabled(false);
        browser.get('https://www.google.com');
        element(by.name("q")).sendKeys('test')
        browser.sleep(5000);
    
    });
    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-04
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 2014-06-01
      相关资源
      最近更新 更多