1

I was wondering if there's a way of grouping Protractor's scenarios into contexts like it's possible in Capybara?

For example, if I was writing tests for post privacy settings, I could have context for user that is not logged in and context for logged in user that divides into different scenarios based on relation between the users. Another example:

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 allows me to make the specs DRY, because I can add a before block inside it that contains steps that are repeating for scenarios inside the context. Is it possible with Protractor?

anks
  • 303
  • 2
  • 12
  • Are you may be asking [about specs vs suites](http://stackoverflow.com/questions/30331018/suites-vs-specs-protractor)? – alecxe Aug 07 '16 at 03:46

1 Answers1

1

Short answer to your question is - No, there is no direct capability in protractor such as contexts in capybara,Since you come from Rails background let me give some brief insights on protractor:

  • Protractor is a node.js program built on top of webdriver.js so all its methods are asynchronous and return promises.
  • The default testing framework for protractor is Jasmine2.0currently.

Now to DRY your specs you have two good options:

Ram Pasala
  • 4,931
  • 3
  • 16
  • 26