首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS - scenario.js码

AngularJS - scenario.js码
EN

Stack Overflow用户
提问于 2016-06-28 05:44:24
回答 1查看 126关注 0票数 1

在关于angularjs.org的应用程序构建教程中,step-8,测试部分,下面的代码行是什么意思?

代码语言:javascript
复制
element.all(by.css('.phones li a')).first().click();
expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s');

提前感谢!

PS:确切的URL是- 08,而代码文件(scenarios.js)是-

代码语言:javascript
复制
    'use strict';

// Angular E2E Testing Guide:
// https://docs.angularjs.org/guide/e2e-testing

describe('PhoneCat Application', function() {

  describe('phoneList', function() {

    beforeEach(function() {
      browser.get('index.html');
    });

    it('should filter the phone list as a user types into the search box', function() {
      var phoneList = element.all(by.repeater('phone in $ctrl.phones'));
      var query = element(by.model('$ctrl.query'));

      expect(phoneList.count()).toBe(20);

      query.sendKeys('nexus');
      expect(phoneList.count()).toBe(1);

      query.clear();
      query.sendKeys('motorola');
      expect(phoneList.count()).toBe(8);
    });

    it('should be possible to control phone order via the drop-down menu', function() {
      var queryField = element(by.model('$ctrl.query'));
      var orderSelect = element(by.model('$ctrl.orderProp'));
      var nameOption = orderSelect.element(by.css('option[value="name"]'));
      var phoneNameColumn = element.all(by.repeater('phone in $ctrl.phones').column('phone.name'));

      function getNames() {
        return phoneNameColumn.map(function(elem) {
          return elem.getText();
        });
      }

      queryField.sendKeys('tablet');   // Let's narrow the dataset to make the assertions shorter

      expect(getNames()).toEqual([
        'Motorola XOOM\u2122 with Wi-Fi',
        'MOTOROLA XOOM\u2122'
      ]);

      nameOption.click();

      expect(getNames()).toEqual([
        'MOTOROLA XOOM\u2122',
        'Motorola XOOM\u2122 with Wi-Fi'
      ]);
    });

    it('should render phone specific links', function() {
      var query = element(by.model('$ctrl.query'));
      query.sendKeys('nexus');

      element.all(by.css('.phones li a')).first().click();
      expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s');
    });

  });

});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-28 06:06:28

它正在测试到/phones/nexus-s的路由。它是用量角器编写的。

第一行读取DOM并查找所有.phones li a css规则。然后,它只接受第一个,并在上面调用click()

代码语言:javascript
复制
element.all(by.css('.phones li a')).first().click();

第二行要求函数browser.getLocationAbsUrl()的输出为字符串/phone/nexus-s

代码语言:javascript
复制
expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s');

因此,在所有测试框架中,单击一个按钮,并期望它被路由到一个新页面。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38067935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档