Dduvall has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/280470

Change subject: Support browser version as part of `BROWSER`
......................................................................

Support browser version as part of `BROWSER`

The version is inherently part of the full browser specification
when running CI builds and this will simplify the configuration
necessary for matrix builds.

Implemented a `browser_version` method that returns either the explicit
version given as `VERSION` or the version given at the end of `BROWSER`
(e.g. `BROWSER=internet_explorer VERSION=8.0` or
`BROWSER='internet_explorer 8.0'`). Implemented `browser_tags` which
will help our rake task filter for only those scenarios that are tagged
with either the browser name (e.g. `@internet_explorer`) or an exact
version (e.g. `@internet_explorer_8.0`).

Bug: T128190
Change-Id: I340e2edbfd9e0b6f30f37ef07f31980099193ebf
---
M lib/mediawiki_selenium/environment.rb
M lib/mediawiki_selenium/rake_task.rb
M spec/environment_spec.rb
3 files changed, 100 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/selenium 
refs/changes/70/280470/1

diff --git a/lib/mediawiki_selenium/environment.rb 
b/lib/mediawiki_selenium/environment.rb
index 8a757ff..4959deb 100644
--- a/lib/mediawiki_selenium/environment.rb
+++ b/lib/mediawiki_selenium/environment.rb
@@ -183,12 +183,41 @@
       end
     end
 
-    # Name of the browser we're using.
+    # Name of the browser we're using. If the `:browser` configuration
+    # contains a version at the end, only the name is returned.
+    #
+    # @example
+    #   env = Environment.new(browser: 'internet_explorer 8.0')
+    #   env.browser_name # => :internet_explorer
     #
     # @return [Symbol]
     #
     def browser_name
-      lookup(:browser, default: 'firefox').downcase.to_sym
+      browser_spec[0].to_sym
+    end
+
+    # Tag names that can be used to filter test scenarios for a specific
+    # browser and/or version.
+    #
+    # @return [Array<String>]
+    #
+    def browser_tags
+      tags = [browser_name.to_s]
+
+      version = browser_version
+      tags << "#{browser_name}_#{version}" if version
+
+      tags
+    end
+
+    # Version of the browser we're using. If a `:version` configuration
+    # is provided, that value is returned. Otherwise a version is searched for
+    # in the `:browser` configuration.
+    #
+    # @return [String]
+    #
+    def browser_version
+      lookup(:version, default: browser_spec[1])
     end
 
     # Returns the current alternate ID for the given configuration key.
@@ -523,7 +552,19 @@
     private
 
     def browser_config
-      lookup_all(browser_factory.all_binding_keys, default: nil).reject { |_k, 
v| v.nil? }
+      config = lookup_all(browser_factory.all_binding_keys, default: 
nil).reject { |_k, v| v.nil? }
+
+      # The browser version may be provided as part of the `:browser`
+      # configuration or separately as `:version`. In either case,
+      # `browser_version` will return the right value.
+      version = browser_version
+      config[:version] = version unless version.nil?
+
+      config
+    end
+
+    def browser_spec
+      lookup(:browser, default: 'firefox').to_s.downcase.split(' ')
     end
 
     def normalize_config(hash)
diff --git a/lib/mediawiki_selenium/rake_task.rb 
b/lib/mediawiki_selenium/rake_task.rb
index 8066f87..9690221 100644
--- a/lib/mediawiki_selenium/rake_task.rb
+++ b/lib/mediawiki_selenium/rake_task.rb
@@ -10,7 +10,7 @@
 
       workspace = env.lookup(:workspace, default: nil)
       site = URI.parse(env.lookup(:mediawiki_url)).host
-      browser = env.browser_name
+      browser_tags = env.browser_tags.map { |tag| "@#{tag}" }.join(',')
 
       options = "#{env.test_dir}"
 
@@ -22,7 +22,7 @@
       end
 
       super(name) do |t|
-        t.cucumber_opts = "#{options} --tags @#{browser}"
+        t.cucumber_opts = "#{options} --tags #{browser_tags}"
       end
     end
   end
diff --git a/spec/environment_spec.rb b/spec/environment_spec.rb
index 85f8ad3..cafe184 100644
--- a/spec/environment_spec.rb
+++ b/spec/environment_spec.rb
@@ -260,6 +260,60 @@
           expect(subject).to be(:firefox)
         end
       end
+
+      context 'when browser and version are combined' do
+        let(:browser) { 'internet_explorer 8.0' }
+
+        it 'returns only the name' do
+          expect(subject).to be(:internet_explorer)
+        end
+      end
+    end
+
+    describe '#browser_tags' do
+      subject { env.browser_tags }
+
+      context 'when a version is specified' do
+        let(:browser) { 'internet_explorer 8.0' }
+        
+        it 'returns tags for use in filter test scenarios' do
+          expect(subject).to eq(['internet_explorer', 'internet_explorer_8.0'])
+        end
+      end
+
+      context 'when no version is specified' do
+        let(:browser) { 'internet_explorer' }
+
+        it 'includes only a tag for the browser name' do
+          expect(subject).to eq(['internet_explorer'])
+        end
+      end
+    end
+
+    describe '#browser_version' do
+      subject { env.browser_version }
+
+      let(:browser) { 'internet_explorer 8.0' }
+
+      context 'when no explicit version configuration is provided' do
+        it 'is the version specified at the end of browser' do
+          expect(subject).to eq('8.0')
+        end
+      end
+
+      context 'when an explicit version configuration is provided' do
+        let(:config) { minimum_config.merge(version: '9.0') }
+
+        it 'ignores the version given at the end of browser and returns the 
explicit one' do
+          expect(subject).to eq('9.0')
+        end
+      end
+
+      context 'when no version is specified' do
+        let(:browser) { 'internet_explorer' }
+
+        it { is_expected.to be(nil) }
+      end
     end
 
     describe '#current_alternative' do

-- 
To view, visit https://gerrit.wikimedia.org/r/280470
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I340e2edbfd9e0b6f30f37ef07f31980099193ebf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/selenium
Gerrit-Branch: master
Gerrit-Owner: Dduvall <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to