【问题标题】:Is there a way of grouping Protractor's scenarios into contexts?有没有办法将 Protractor 的场景分组到上下文中?
【发布时间】:2016-08-08 17:57:14
【问题描述】:

我想知道是否有一种方法可以像在 Capybara 中那样将 Protractor 的场景分组到上下文中?

例如,如果我正在为帖子隐私设置编写测试,我可以为未登录的用户提供上下文,为登录的用户提供上下文,根据用户之间的关系划分为不同的场景。 另一个例子:

feature 'allows user to share' do
  let!(:post) { create :post }

  before do
    create :feed_post, user: user, post: post
    app.sign_in user
  end

  context 'with comment' do
    subject { feed.share_modal }

    before { feed.posts.first.share_post }

    scenario { is_expected.to have_content t('social_sharing.new.title') }
    scenario { is_expected.to have_button t('social_sharing.new.action') }

    context 'sharing with a comment' do
      before do
        feed.share_modal.comment_on_share 'a nice comment'
        feed.share_modal.submit_share_form
        feed.wait_until_share_modal_invisible
      end

      scenario 'closes the modal' do
        expect(feed).to have_no_share_modal
      end

      scenario 'shows shared message' do
        expect(feed.posts.first)
        .to have_content "#{user.name} shared #{post.user.name.possessive} post"
        expect(feed.posts.first).to have_content 'a nice comment'
      end
    end
  end
end

Context 允许我将规范设为 DRY,因为我可以在其中添加一个 before 块,其中包含针对上下文中的场景重复的步骤。量角器可以吗?

【问题讨论】:

标签: protractor


【解决方案1】:

对您的问题的简短回答是 - 不,量角器没有直接功能,例如水豚中的上下文,由于您来自 Rails 背景,让我简要介绍一下量角器:

  • Protractor 是一个基于 webdriver.js 构建的 node.js 程序,因此它的所有方法都是异步的并返回 Promise。
  • protractor 的默认测试框架是Jasmine2.0currently。

现在要干燥您的规格,您有两个不错的选择:

【讨论】:

    猜你喜欢
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2015-06-22
    相关资源
    最近更新 更多