summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-11-19 12:36:16 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-11-19 12:36:37 +0100
commit4c37cf684d75297a88db2dd1c286a68fd8aec701 (patch)
treef909d8c01477d2fa23b3a291cfaa6c0963b5e788
parent6e1df95ed3a552e4c4dc61150dc2825508d888ec (diff)
downloadgitlab-ce-4c37cf684d75297a88db2dd1c286a68fd8aec701.tar.gz
Make QA runtime browser an actable object
[ci skip]
-rw-r--r--qa/qa/page/base.rb15
-rw-r--r--qa/qa/page/main/login.rb8
-rw-r--r--qa/qa/page/mattermost/login.rb8
-rw-r--r--qa/qa/runtime/browser.rb83
-rw-r--r--qa/qa/specs/features/mattermost/login_spec.rb2
5 files changed, 56 insertions, 60 deletions
diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb
index a43192ed903..69f14386223 100644
--- a/qa/qa/page/base.rb
+++ b/qa/qa/page/base.rb
@@ -22,24 +22,9 @@ module QA
yield if block_given?
end
- ##
- # If you want to use specific page class as an entrypoint
- # for Runtime::Browser.session, you need to implement this
- # method in a subclass.
- #
def self.address
raise NotImplementedError
end
-
- ## TODO
- # When we navigate through pages, we want to check if we are on a
- # valid page everytime we instantiate a new Page object.
- #
- # See gitlab-org/gitlab-qa#111
- #
- # def self.pattern
- # raise NotImplementedError
- # end
end
end
end
diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb
index 37580ad89b1..4c38f81bce7 100644
--- a/qa/qa/page/main/login.rb
+++ b/qa/qa/page/main/login.rb
@@ -2,10 +2,6 @@ module QA
module Page
module Main
class Login < Page::Base
- def self.address
- Runtime::Scenario.gitlab_address + '/users/sign_in'
- end
-
def initialize
wait('.application', time: 500)
end
@@ -21,6 +17,10 @@ module QA
fill_in :user_password, with: Runtime::User.password
click_button 'Sign in'
end
+
+ def self.address
+ Runtime::Scenario.gitlab_address + '/users/sign_in'
+ end
end
end
end
diff --git a/qa/qa/page/mattermost/login.rb b/qa/qa/page/mattermost/login.rb
index 846a96d20bf..9eb43fdc1b2 100644
--- a/qa/qa/page/mattermost/login.rb
+++ b/qa/qa/page/mattermost/login.rb
@@ -2,10 +2,6 @@ module QA
module Page
module Mattermost
class Login < Page::Base
- def self.address
- Runtime::Scenario.mattermost_address + '/login'
- end
-
def sign_in_using_oauth
click_link class: 'btn btn-custom-login gitlab'
@@ -13,6 +9,10 @@ module QA
click_button 'Authorize'
end
end
+
+ def self.address
+ Runtime::Scenario.gitlab_address + '/login'
+ end
end
end
end
diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb
index a14a4adce22..2226c56c012 100644
--- a/qa/qa/runtime/browser.rb
+++ b/qa/qa/runtime/browser.rb
@@ -5,49 +5,24 @@ require 'selenium-webdriver'
module QA
module Runtime
- module Browser
- extend self
+ class Browser
+ include Scenario::Actable
- def visit(entry, &block)
- address = entry.is_a?(String) ? entry : entry.address
-
- configure!
- page.visit(address)
-
- if block_given?
- block.call(page)
+ def initialize
+ self.class.configure!
+ end
- page.visit(address)
- reset_domain_session!
- end
- rescue
- # RSpec examples will take care of screenshots on their own
- #
- unless block.binding.receiver.class < RSpec::Core::ExampleGroup
- Capybara::Screenshot.screenshot_and_save_page
+ def visit(page, &block)
+ Browser::Session.new(page).tap do |session|
+ session.perform(&block)
end
-
- raise
end
- ##
- # Current session, when Capybara::DSL is included `page` method is
- # mixed in as well.
- #
- def page
- Capybara.current_session
+ def self.visit(page, &block)
+ new.visit(page, &block)
end
- def reset_domain_session(address)
- ##
- # Selenium allows to reset session cookies for current domain only.
- #
- # See gitlab-org/gitlab-qa#102
- #
- Capybar.reset_session!
- end
-
- def configure!
+ def self.configure!
return if Capybara.drivers.include?(:chrome)
Capybara.register_driver :chrome do |app|
@@ -73,6 +48,42 @@ module QA
config.save_path = 'tmp'
end
end
+
+ class Session
+ include Capybara::DSL
+
+ attr_reader :address
+
+ def initialize(page)
+ @address = page.is_a?(String) ? page : page.address
+ end
+
+ def perform(&block)
+ visit(@address)
+
+ block.call if block_given?
+ rescue
+ # RSpec examples will take care of screenshots on their own
+ #
+ unless block.binding.receiver.class < RSpec::Core::ExampleGroup
+ Capybara::Screenshot.screenshot_and_save_page
+ end
+
+ raise
+ ensure
+ clear! if block_given?
+ end
+
+ ##
+ # Selenium allows to reset session cookies for current domain only.
+ #
+ # See gitlab-org/gitlab-qa#102
+ #
+ def clear!
+ visit(@address)
+ Capybara.reset_session!
+ end
+ end
end
end
end
diff --git a/qa/qa/specs/features/mattermost/login_spec.rb b/qa/qa/specs/features/mattermost/login_spec.rb
index 449161e2bb7..7820170a345 100644
--- a/qa/qa/specs/features/mattermost/login_spec.rb
+++ b/qa/qa/specs/features/mattermost/login_spec.rb
@@ -1,7 +1,7 @@
module QA
feature 'logging in to Mattermost', :mattermost do
scenario 'can use gitlab oauth' do
- Runtime::Browser.visit(Page::Gitlab::Login) do
+ Runtime::Browser.visit(Page::Main::Login) do
Page::Main::Login.act { sign_in_using_credentials }
Runtime::Browser.visit(Page::Mattermost::Login) do