Dduvall has uploaded a new change for review.

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

Change subject: Decouple session annotation from Cucumber
......................................................................

Decouple session annotation from Cucumber

Moved the annotation of the Selenium session into `Environment#setup`.

Bug: T108273
Change-Id: I3d1434ee94d07c014fc42d399bc5c219dcd769f1
---
M lib/mediawiki_selenium/environment.rb
M lib/mediawiki_selenium/support/hooks.rb
M spec/environment_spec.rb
3 files changed, 34 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/selenium 
refs/changes/34/230234/1

diff --git a/lib/mediawiki_selenium/environment.rb 
b/lib/mediawiki_selenium/environment.rb
index 49acff5..f5f9085 100644
--- a/lib/mediawiki_selenium/environment.rb
+++ b/lib/mediawiki_selenium/environment.rb
@@ -346,14 +346,31 @@
       RemoteBrowserFactory::REQUIRED_CONFIG.all? { |name| lookup(name, 
default: false) }
     end
 
-    # Executes setup tasks. Currently no tasks are performed by default but
-    # additional helpers may perform their own tasks by implementing this
+    # Executes setup tasks, annotating the Selenium session with any
+    # configured `job_name` and `build_number`.
+    #
+    # Additional helpers may perform their own tasks by implementing this
     # method.
     #
-    # @param _info [Hash] Hash of test case information.
+    # @example Setup the environment before each scenario starts
+    #   Before do |scenario|
+    #     setup(name: scenario.name)
+    #   end
     #
-    def setup(_info = {})
-      # no-op
+    # @param info [Hash] Hash of test case information.
+    #
+    def setup(info = {})
+      browser_factory.configure do |options|
+        options[:desired_capabilities][:name] = info[:name] || 'scenario'
+      end
+
+      browser_factory.configure(:job_name) do |job, options|
+        options[:desired_capabilities][:name] += " #{job}"
+      end
+
+      browser_factory.configure(:build_number) do |build, options|
+        options[:desired_capabilities][:name] += "##{build}"
+      end
     end
 
     # Executes teardown tasks including instructing all browser factories to
diff --git a/lib/mediawiki_selenium/support/hooks.rb 
b/lib/mediawiki_selenium/support/hooks.rb
index 70cff16..d9971bb 100644
--- a/lib/mediawiki_selenium/support/hooks.rb
+++ b/lib/mediawiki_selenium/support/hooks.rb
@@ -59,19 +59,6 @@
 Before do
   # Create a unique random string for this scenario
   @random_string = Random.new.rand.to_s
-
-  # Annotate sessions with the scenario name and Jenkins build info
-  browser_factory.configure do |options|
-    options[:desired_capabilities][:name] = @scenario_name
-  end
-
-  browser_factory.configure(:job_name) do |job, options|
-    options[:desired_capabilities][:name] += " #{job}"
-  end
-
-  browser_factory.configure(:build_number) do |build, options|
-    options[:desired_capabilities][:name] += "##{build}"
-  end
 end
 
 After do |scenario|
diff --git a/spec/environment_spec.rb b/spec/environment_spec.rb
index 57c0924..833882a 100644
--- a/spec/environment_spec.rb
+++ b/spec/environment_spec.rb
@@ -396,6 +396,18 @@
       end
     end
 
+    describe '#setup' do
+      subject { env.setup(name: 'Some test name') }
+
+      it 'configures the browser factory to accept `:job_name` and 
`:build_number`' do
+        expect(env.browser_factory).to receive(:configure)
+        expect(env.browser_factory).to receive(:configure).with(:job_name)
+        expect(env.browser_factory).to receive(:configure).with(:build_number)
+
+        subject
+      end
+    end
+
     describe '#teardown' do
       subject { env.teardown(status: status) }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d1434ee94d07c014fc42d399bc5c219dcd769f1
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