Skip to content

Commit

Permalink
Meta target for building Marionette atoms, marionette:atoms
Browse files Browse the repository at this point in the history
Marionette uses a custom protocol similar, but not identical, to the
WebDriver wire protocol.  This patch adds a Marionette protocol
function lookup table for the relevant atoms that it uses.

This isn't ideal because it introduces a tight coupling between
Mozilla's repository and Selenium's.  Instead Marionette should be
importing the fragments directly so that no upstream patches are
needed if Marionette decides to change its protocol.

Mozilla bug 936204 has been filed about this.
  • Loading branch information
andreastt committed Nov 7, 2013
1 parent 9acb324 commit 2f47941
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ $LOAD_PATH.unshift File.expand_path(".")
require 'rake'
require 'rake-tasks/files'
require 'net/telnet'
require 'stringio'
require 'fileutils'

include Rake::DSL if defined?(Rake::DSL)

Expand Down Expand Up @@ -806,6 +808,52 @@ namespace :safari do
end
end

namespace :marionette do
atoms_file = "build/javascript/marionette/atoms.js"
func_lookup = {"//javascript/atoms/fragments:clear:firefox" => "clearElement",
"//javascript/webdriver/atoms/fragments:get_attribute:firefox" => "getElementAttribute",
"//javascript/webdriver/atoms/fragments:get_text:firefox" => "getElementText",
"//javascript/atoms/fragments:is_enabled:firefox" => "isElementEnabled",
"//javascript/webdriver/atoms/fragments:is_selected:firefox" => "isElementSelected",
"//javascript/atoms/fragments:is_displayed:firefox" => "isElementDisplayed"}

# This task takes all the relevant Marionette atom dependencies
# (listed in func_lookup) and concatenates them to a single atoms.js
# file, where each atom is assigned to a custom function name
# matching the Marionette protocol.
#
# The function names are defined in the func_lookup dictionary of
# target to name.
#
# Instead of having this custom behaviour in Selenium, Marionette
# should use the individually generated .js atom files directly in
# the future.
#
# (See Mozilla bug 936204.)

desc "Generate Marionette atoms"
task :atoms => func_lookup.keys do |task|
b = StringIO.new
b << File.read("javascript/marionette/COPYING") << "\n"
b << "\n"

task.prerequisites.each do |target|
out = Rake::Task[target].out
atom = File.read(out).chop

b << "// target #{target}\n"
b << "var #{func_lookup[target]} = #{atom};\n"
b << "\n"
end

puts "Generating uberatoms file: #{atoms_file}"
FileUtils.mkpath("build/javascript/marionette")
File.open("build/javascript/marionette/atoms.js", "w+") do |h|
h.write(b.string)
end
end
end

at_exit do
if File.exist?(".git") && !Platform.windows?
sh "sh .git-fixfiles"
Expand Down
14 changes: 14 additions & 0 deletions javascript/marionette/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Copyright 2013 Software Freedom Conservancy
* Copyright 2011-2012 WebDriver committers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */

0 comments on commit 2f47941

Please sign in to comment.