2

我基本上是在尝试为这个网页编写测试:http ://www.talklocal.com/mobile/#/step1

我想填写表格中的信息,然后单击下一步按钮。虽然测试应该将我重定向到表单的第 2 步(检查 url),但它没有,而是失败了。测试代码:

describe('going from step1 to step 2', function() {

        //fill out step 1 form
        beforeEach(function() {
            browser.get('index.html');

            element(by.model('Request.categoryID')).click();
            element(by.css('option[value=0]')).click();
            element(by.class('where-text ng-pristine ng-valid').sendKeys('20902'));

            element(by.class('btn action-button')).click();
        });

        it('should be on the step2 page', function() {

            browser.getLocationAbsUrl().then(function(url) {
                expect(url.split('#')[1]).toBe('/step2');
            });
        });
    });

终端中的错误消息:

  1) myApp going from step1 to step 2 should be on the step2 page
   Message:
     TypeError: Object [object Object] has no method 'class'
  2) myApp going from step1 to step 2 should be on the step2 page
      Message:
      Expected '/step1' to be '/step2'.
  3 tests, 5 assertions, 2 failures

我用谷歌搜索了这些错误,并一直在尝试为 element(by.attribute) 方法插入不同的类和属性,但无济于事。

我将不胜感激有关此问题的任何和所有反馈。谢谢!

4

2 回答 2

2

没有locatorby.class,如果你想依赖类 - 请改用by.css

element(by.css('.where-text.ng-pristine.ng-valid').sendKeys('20902'));
element(by.css('.btn.action-button')).click();

仅供参考,还有by.className选择器:

element(by.className('action-button')).click();
于 2015-02-26T23:49:29.967 回答
0

检查量角器 API 文档
by.class 无效。您可以使用模型或按钮文本作为按钮。

element(by.model('User.zipcode').sendKeys('20902'));
element(by.buttonText('Next')).click();
于 2015-02-26T23:57:29.053 回答