测试模板量角器? [英] Testing templates in Protractor?

查看:209
本文介绍了测试模板量角器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是写应该在一个跨网站的每个页面申请主张的最好方式?

What's the best way to write assertions that should apply across every page in a site?

我测试,看看在我的网站的页脚中存在的元素,所以元素应该在所有网页上。

I'm testing to see if an element exists in the footer of my site, so the element should exist on all pages.

我想写入的网站的测试模板元一个单独的文件中,然后加入本中的所有规范。它似乎并不像其他人一样在做这个有关系吗?

I am thinking of writing a separate file for testing template elements of the site, and then include this in all specs. It doesn't seem like anyone else is doing this though?

推荐答案

首先,编写清洁测试,并有一个更好的了解你的目标网站所包含的内容,应用的页面对象模式并您的网页的部分分成不同的页面对象。例如,页脚可以而且应该是会在不同的网页你的网站被重用单独的页面对象

First of all, for writing cleaner tests and having a better understanding of what your target site consists of, apply the Page Object pattern and split the parts of your web pages into different page objects. For instance, footer, header can and should be separate page objects that would be reused across different web pages of your site.

更多的题目是:

  • Using Page Objects to Organize Tests
  • Protractor Page Objects (Tutorial, very detailed)
  • PageObject (Martin Fowler)
  • Using Page Objects to Overcome Protractor's Shortcomings

据我了解的问题,按照你想有某种共享茉莉花规格,你可以的定义一次,并在多个测试套件运行的的干的原则。

As far as I understand the question, to follow the "DRY" principle you want to have some sort of the "shared" jasmine specs that you can define once and run in multiple test suites.

这正是枯竭茉莉花规格带共用行为文章描述。这个想法很简单 - 定义一个函数与你的测试套件内,从其他测试套件调用它。例如:

This is exactly what DRYing up Jasmine Specs with Shared Behavior article is describing. The idea is rather simple - define a function with your test suites inside and call it from other test suites. Example:


  • 创建一个接受上下文功能 - 页面对象 - 并包含页脚具体可重复使用的测试:

  • create a function which accepts a context - page object - and contains the footer specific reusable tests:

function testFooter(footer) {

    describe("(shared)", function () {

        describe("should show footer with necessary information", function () {
            it("should show copyright", function () {
                expect(footer.copyright.getText()).toEqual('Copyright 2014');
            });
        });

    });
}


  • 从通过上下文中的其他测试套件调用的函数 - 页脚页面对象:

  • call the function from other test suites passing the context - footer page object:

    var FooterPage = require('./footer.po.js');
    
    describe('Contacts page', function () {
        var scope = {};
    
        beforeEach(function () {
            browser.get('/contacts/');
            browser.waitForAngular();
            scope.page = new ContactsPage();
        });
    
        // other contacts page specific suites 
        // ...
    
        testFooter(new FooterPage());
    
    });
    


  • 您可能需要调整和完善code,使其工作,但这个想法保持不变:一次定义和重用。围绕页面对象传递只是使它变得更干净和透明。

    You may need to adjust and improve the code to make it work, but the idea stays the same: define once and reuse. Passing around page objects just makes it a lot cleaner and transparent.

    另请参见:

    • What's a good way to reuse test code using Jasmine?
    • Protractor Page Objects Inheritance

    这篇关于测试模板量角器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆