How to use bazel method of Rake.DSL Package

Best Selenium code snippet using Rake.DSL.bazel

Rakefile

Source:Rakefile Github

copy

Full Screen

...28# Our modifications to the Rake / Bazel libraries29require 'rake/task'30require 'rake_tasks/rake/task'31require 'rake_tasks/rake/dsl'32require 'rake_tasks/bazel/task'33# These are the final items mixed into the global NS34# These need moving into correct namespaces, and not be globally included35require 'rake_tasks/bazel'36require 'rake_tasks/copyright'37require 'rake_tasks/python'38$DEBUG = orig_verbose != Rake::FileUtilsExt::DEFAULT ? true : false39$DEBUG = true if ENV['debug'] == 'true'40verbose($DEBUG)41def release_version42 '4.1'43end44def version45 "#{release_version}.1"46end47# The build system used by webdriver is layered on top of rake, and we call it48# "crazy fun" for no readily apparent reason.49# First off, create a new CrazyFun object.50crazy_fun = SeleniumRake::CrazyFun.new51# Secondly, we add the handlers, which are responsible for turning a build52# rule into a (series of) rake tasks. For example if we're looking at a file53# in subdirectory "subdir" contains the line:54#55# java_library(:name => "example", :srcs => ["foo.java"])56#57# we would generate a rake target of "//subdir:example" which would generate58# a Java JAR at "build/subdir/example.jar".59#60# If crazy fun doesn't know how to handle a particular output type ("java_library"61# in the example above) then it will throw an exception, stopping the build62CrazyFun::Mappings::RakeMappings.new.add_all(crazy_fun)63# Finally, find every file named "build.desc" in the project, and generate64# rake tasks from them. These tasks are normal rake tasks, and can be invoked65# from rake.66# FIXME: the rules for the targets were removed and build files won't load67# crazy_fun.create_tasks(Dir['**/build.desc'])68#  If it looks like a bazel target, build it with bazel69rule /\/\/.*/ do |task|70 task.out = Bazel.execute('build', %w[--workspace_status_command scripts/build-info.py], task.name)71end72# Spoof tasks to get CI working with bazel73task '//java/test/org/openqa/selenium/environment/webserver:webserver:uber' => [74 '//java/test/org/openqa/selenium/environment:webserver'75]76# Java targets required for release. These should all be java_export targets.77# Generated from: bazel query 'kind(maven_publish, set(//java/... //third_party/...))' | sort78JAVA_RELEASE_TARGETS = %w[79 //java/src/com/thoughtworks/selenium/webdriven:webdriven.publish80 //java/src/org/openqa/selenium/chrome:chrome.publish81 //java/src/org/openqa/selenium/chromium:chromium.publish82 //java/src/org/openqa/selenium/devtools/v85:v85.publish83 //java/src/org/openqa/selenium/devtools/v95:v95.publish84 //java/src/org/openqa/selenium/devtools/v96:v96.publish85 //java/src/org/openqa/selenium/devtools/v97:v97.publish86 //java/src/org/openqa/selenium/edge:edge.publish87 //java/src/org/openqa/selenium/firefox/xpi:xpi.publish88 //java/src/org/openqa/selenium/firefox:firefox.publish89 //java/src/org/openqa/selenium/grid/sessionmap/jdbc:jdbc.publish90 //java/src/org/openqa/selenium/grid/sessionmap/redis:redis.publish91 //java/src/org/openqa/selenium/grid:grid.publish92 //java/src/org/openqa/selenium/ie:ie.publish93 //java/src/org/openqa/selenium/json:json.publish94 //java/src/org/openqa/selenium/lift:lift.publish95 //java/src/org/openqa/selenium/opera:opera.publish96 //java/src/org/openqa/selenium/remote/http:http.publish97 //java/src/org/openqa/selenium/remote:remote.publish98 //java/src/org/openqa/selenium/safari:safari.publish99 //java/src/org/openqa/selenium/support:support.publish100 //java/src/org/openqa/selenium:client-combined.publish101 //java/src/org/openqa/selenium:core.publish102]103# Notice that because we're using rake, anything you can do in a normal rake104# build can also be done here. For example, here we set the default task105task default: [:grid]106task all: [107 :"selenium-java",108 '//java/test/org/openqa/selenium/environment:webserver'109]110task all_zip: [:'prep-release-zip']111task tests: [112 '//java/test/org/openqa/selenium/htmlunit:htmlunit',113 '//java/test/org/openqa/selenium/firefox:test-synthesized',114 '//java/test/org/openqa/selenium/ie:ie',115 '//java/test/org/openqa/selenium/chrome:chrome',116 '//java/test/org/openqa/selenium/edge:edge',117 '//java/test/org/openqa/selenium/opera:opera',118 '//java/test/org/openqa/selenium/support:small-tests',119 '//java/test/org/openqa/selenium/support:large-tests',120 '//java/test/org/openqa/selenium/remote:small-tests',121 '//java/test/org/openqa/selenium/remote/server/log:test',122 '//java/test/org/openqa/selenium/remote/server:small-tests'123]124task chrome: ['//java/src/org/openqa/selenium/chrome']125task grid: [:'selenium-server-standalone']126task ie: ['//java/src/org/openqa/selenium/ie']127task firefox: ['//java/src/org/openqa/selenium/firefox']128task remote: %i[remote_server remote_client]129task remote_client: ['//java/src/org/openqa/selenium/remote']130task remote_server: ['//java/src/org/openqa/selenium/remote/server']131task safari: ['//java/src/org/openqa/selenium/safari']132task selenium: ['//java/src/org/openqa/selenium:core']133task support: [134 '//java/src/org/openqa/selenium/lift',135 '//java/src/org/openqa/selenium/support'136]137desc 'Build the standalone server'138task 'selenium-server-standalone' => '//java/src/org/openqa/selenium/grid:executable-grid'139task test_javascript: [140 '//javascript/atoms:test-chrome:run',141 '//javascript/webdriver:test-chrome:run',142 '//javascript/selenium-atoms:test-chrome:run',143 '//javascript/selenium-core:test-chrome:run'144]145task test_chrome: ['//java/test/org/openqa/selenium/chrome:chrome:run']146task test_edge: ['//java/test/org/openqa/selenium/edge:edge:run']147task test_chrome_atoms: [148 '//javascript/atoms:test-chrome:run',149 '//javascript/chrome-driver:test-chrome:run',150 '//javascript/webdriver:test-chrome:run'151]152task test_htmlunit: [153 '//java/test/org/openqa/selenium/htmlunit:htmlunit:run'154]155task test_grid: [156 '//java/test/org/openqa/grid/common:common:run',157 '//java/test/org/openqa/grid:grid:run',158 '//java/test/org/openqa/grid/e2e:e2e:run',159 '//java/test/org/openqa/selenium/remote:remote-driver-grid-tests:run'160]161task test_ie: [162 '//cpp/iedriverserver:win32',163 '//cpp/iedriverserver:x64',164 '//java/test/org/openqa/selenium/ie:ie:run'165]166task test_jobbie: [:test_ie]167task test_firefox: ['//java/test/org/openqa/selenium/firefox:marionette:run']168task test_opera: ['//java/test/org/openqa/selenium/opera:opera:run']169task test_remote_server: [170 '//java/test/org/openqa/selenium/remote/server:small-tests:run',171 '//java/test/org/openqa/selenium/remote/server/log:test:run'172]173task test_remote: [174 '//java/test/org/openqa/selenium/json:small-tests:run',175 '//java/test/org/openqa/selenium/remote:common-tests:run',176 '//java/test/org/openqa/selenium/remote:client-tests:run',177 '//java/test/org/openqa/selenium/remote:remote-driver-tests:run',178 :test_remote_server179]180task test_safari: ['//java/test/org/openqa/selenium/safari:safari:run']181task test_support: [182 '//java/test/org/openqa/selenium/lift:lift:run',183 '//java/test/org/openqa/selenium/support:small-tests:run',184 '//java/test/org/openqa/selenium/support:large-tests:run'185]186# TODO(simon): test-core should go first, but it's changing the least for now.187task test_selenium: [:'test-rc']188task 'test-rc': ['//java/test/com/thoughtworks/selenium:firefox-rc-test:run']189task 'test-rc': ['//java/test/com/thoughtworks/selenium:ie-rc-test:run'] if SeleniumRake::Checks.windows?190task test_java_webdriver: %i[191 test_htmlunit192 test_firefox193 test_remote_server194]195task test_java_webdriver: [:test_ie] if SeleniumRake::Checks.windows?196task test_java_webdriver: [:test_chrome] if SeleniumRake::Checks.chrome?197task test_java_webdriver: [:test_edge] if SeleniumRake::Checks.edge?198task test_java_webdriver: [:test_opera] if SeleniumRake::Checks.opera?199task test_java: [200 '//java/test/org/openqa/selenium/atoms:test:run',201 :test_java_small_tests,202 :test_support,203 :test_java_webdriver,204 :test_selenium,205 'test_grid'206]207task test_java_small_tests: [208 '//java/test/org/openqa/selenium:small-tests:run',209 '//java/test/org/openqa/selenium/json:small-tests:run',210 '//java/test/org/openqa/selenium/support:small-tests:run',211 '//java/test/org/openqa/selenium/remote:common-tests:run',212 '//java/test/org/openqa/selenium/remote:client-tests:run',213 '//java/test/org/openqa/grid/selenium/node:node:run',214 '//java/test/org/openqa/grid/selenium/proxy:proxy:run',215 '//java/test/org/openqa/selenium/remote/server:small-tests:run',216 '//java/test/org/openqa/selenium/remote/server/log:test:run'217]218task test_rb: ['//rb:unit-test', :test_rb_local, :test_rb_remote]219task test_rb_local: [220 '//rb:chrome-test',221 '//rb:firefox-test',222 ('//rb:firefox-nightly-test' if ENV['FIREFOX_NIGHTLY_BINARY']),223 ('//rb:safari-preview-test' if SeleniumRake::Checks.mac?),224 ('//rb:safari-test' if SeleniumRake::Checks.mac?),225 ('//rb:ie-test' if SeleniumRake::Checks.windows?),226 ('//rb:edge-test' unless SeleniumRake::Checks.linux?)227].compact228task test_rb_remote: [229 '//rb:remote-chrome-test',230 '//rb:remote-firefox-test',231 ('//rb:remote-firefox-nightly-test' if ENV['FIREFOX_NIGHTLY_BINARY']),232 ('//rb:remote-safari-test' if SeleniumRake::Checks.mac?),233 # BUG - https://github.com/SeleniumHQ/selenium/issues/6791234 # ('//rb:remote-safari-preview-test' if SeleniumRake::Checks.mac?),235 ('//rb:remote-ie-test' if SeleniumRake::Checks.windows?),236 ('//rb:remote-edge-test' unless SeleniumRake::Checks.linux?)237].compact238task test_py: [:py_prep_for_install_release, 'py:marionette_test']239task test: %i[test_javascript test_java test_rb]240task test: [:test_py] if SeleniumRake::Checks.python?241task build: %i[all firefox remote selenium tests]242desc 'Clean build artifacts.'243task :clean do244 rm_rf 'build/'245 rm_rf 'java/build/'246 rm_rf 'dist/'247end248# Create a new IEGenerator instance249ie_generator = SeleniumRake::IEGenerator.new250# Generate a C++ Header file for mapping between magic numbers and #defines251# in the C++ code.252ie_generator.generate_type_mapping(253 name: 'ie_result_type_cpp',254 src: 'cpp/iedriver/result_types.txt',255 type: 'cpp',256 out: 'cpp/iedriver/IEReturnTypes.h'257)258task javadocs: %i[//java/src/org/openqa/selenium/grid:all-javadocs] do259 rm_rf 'build/javadoc'260 mkdir_p 'build/javadoc'261 # Temporary hack, bazel is not outputting where things are so we need to do it manually.262 # This will only work on Posix based OSes263 Rake::Task['//java/src/org/openqa/selenium/grid:all-javadocs']264 out = 'bazel-bin/java/src/org/openqa/selenium/grid/all-javadocs.jar'265 cmd = %{cd build/javadoc && jar xf "../../#{out}" 2>&1}266 if SeleniumRake::Checks.windows?267 cmd = cmd.gsub(/\//, '\\').gsub(/:/, ';')268 end269 ok = system(cmd)270 ok or raise "could not unpack javadocs"271 File.open('build/javadoc/stylesheet.css', 'a') { |file|272 file.write(<<~EOF273 /* Custom selenium-specific styling */274 .blink {275 animation: 2s cubic-bezier(0.5, 0, 0.85, 0.85) infinite blink;276 }277 @keyframes blink {278 50% {279 opacity: 0;280 }281 }282 EOF283 )284 }285end286file 'cpp/iedriver/sizzle.h' => ['//third_party/js/sizzle:sizzle:header'] do287 cp 'build/third_party/js/sizzle/sizzle.h', 'cpp/iedriver/sizzle.h'288end289task sizzle_header: ['cpp/iedriver/sizzle.h']290task ios_driver: [291 '//javascript/atoms/fragments:get_visible_text:ios',292 '//javascript/atoms/fragments:click:ios',293 '//javascript/atoms/fragments:back:ios',294 '//javascript/atoms/fragments:forward:ios',295 '//javascript/atoms/fragments:submit:ios',296 '//javascript/atoms/fragments:xpath:ios',297 '//javascript/atoms/fragments:xpaths:ios',298 '//javascript/atoms/fragments:type:ios',299 '//javascript/atoms/fragments:get_attribute:ios',300 '//javascript/atoms/fragments:clear:ios',301 '//javascript/atoms/fragments:is_selected:ios',302 '//javascript/atoms/fragments:is_enabled:ios',303 '//javascript/atoms/fragments:is_shown:ios',304 '//javascript/atoms/fragments:stringify:ios',305 '//javascript/atoms/fragments:link_text:ios',306 '//javascript/atoms/fragments:link_texts:ios',307 '//javascript/atoms/fragments:partial_link_text:ios',308 '//javascript/atoms/fragments:partial_link_texts:ios',309 '//javascript/atoms/fragments:get_interactable_size:ios',310 '//javascript/atoms/fragments:scroll_into_view:ios',311 '//javascript/atoms/fragments:get_effective_style:ios',312 '//javascript/atoms/fragments:get_element_size:ios',313 '//javascript/webdriver/atoms/fragments:get_location_in_view:ios'314]315task 'prep-release-zip': [316 '//java/src/org/openqa/selenium:client-zip',317 '//java/src/org/openqa/selenium/grid:server-zip',318 '//java/src/org/openqa/selenium/grid:executable-grid',319 '//java/src/org/openqa/selenium/server/htmlrunner:selenium-runner_deploy.jar'320] do321 ["build/dist/selenium-server-#{version}.zip", "build/dist/selenium-java-#{version}.zip",322 "build/dist/selenium-server-#{version}.jar", "build/dist/selenium-html-runner-#{version}.jar"].each do |f|323 rm_f(f) if File.exists?(f)324 end325 mkdir_p 'build/dist'326 File.delete327 cp Rake::Task['//java/src/org/openqa/selenium/grid:server-zip'].out, "build/dist/selenium-server-#{version}.zip", preserve: false328 chmod 0666, "build/dist/selenium-server-#{version}.zip"329 cp Rake::Task['//java/src/org/openqa/selenium:client-zip'].out, "build/dist/selenium-java-#{version}.zip", preserve: false330 chmod 0666, "build/dist/selenium-java-#{version}.zip"331 cp Rake::Task['//java/src/org/openqa/selenium/grid:executable-grid'].out, "build/dist/selenium-server-#{version}.jar", preserve: false332 chmod 0666, "build/dist/selenium-server-#{version}.jar"333 cp Rake::Task['//java/src/org/openqa/selenium/server/htmlrunner:selenium-runner_deploy.jar'].out, "build/dist/selenium-html-runner-#{version}.jar", preserve: false334 chmod 0666, "build/dist/selenium-html-runner-#{version}.jar"335end336task 'release-java': %i[prep-release-zip publish-maven]337def read_user_pass_from_m2_settings338 settings = File.read(ENV['HOME'] + '/.m2/settings.xml')339 found_section = false340 user = nil341 pass = nil342 settings.each_line do |line|343 if !found_section344 found_section = line.include? '<id>sonatype-nexus-staging</id>'345 else346 if (user.nil?) && line.include?('<username>')347 user = line.split('<username>')[1].split('</')[0]348 elsif (pass.nil?) && line.include?('<password>')349 pass = line.split('<password>')[1].split('</')[0]350 end351 end352 end353 return [user, pass]354end355task 'publish-maven': JAVA_RELEASE_TARGETS + %w[//java/src/org/openqa/selenium/server/htmlrunner:selenium-runner_deploy.jar] do356 creds = read_user_pass_from_m2_settings357 JAVA_RELEASE_TARGETS.each do |p|358 Bazel::execute('run', ['--stamp', '--define', 'maven_repo=https://oss.sonatype.org/service/local/staging/deploy/maven2', '--define', "maven_user=#{creds[0]}", '--define', "maven_password=#{creds[1]}", '--define', 'gpg_sign=true'], p)359 end360end361task :'maven-install' do362 JAVA_RELEASE_TARGETS.each do |p|363 Bazel::execute('run', ['--stamp', '--define', "maven_repo=file://#{ENV['HOME']}/.m2/repository", '--define', 'gpg_sign=true'], p)364 end365end366desc 'Build the selenium client jars'367task 'selenium-java' => '//java/src/org/openqa/selenium:client-combined'368namespace :safari do369 desc 'Build the SafariDriver java client'370 task build: [371 '//java/src/org/openqa/selenium/safari'372 ]373end374task :authors do375 puts 'Generating AUTHORS file'376 sh "(git log --use-mailmap --format='%aN <%aE>' ; cat .OLD_AUTHORS) | sort -uf > AUTHORS"377end378namespace :copyright do379 task :update do380 Copyright.new.update(381 FileList['javascript/**/*.js'].exclude(382 'javascript/atoms/test/jquery.min.js',383 'javascript/jsunit/**/*.js',384 'javascript/node/selenium-webdriver/node_modules/**/*.js',385 'javascript/selenium-core/lib/**/*.js',386 'javascript/selenium-core/scripts/ui-element.js',387 'javascript/selenium-core/scripts/ui-map-sample.js',388 'javascript/selenium-core/scripts/user-extensions.js',389 'javascript/selenium-core/scripts/xmlextras.js',390 'javascript/selenium-core/xpath/**/*.js'391 )392 )393 Copyright.new(comment_characters: '#').update(FileList['py/**/*.py'])394 Copyright.new(comment_characters: '#', prefix: ["# frozen_string_literal: true\n", "\n"])395 .update(FileList['rb/**/*.rb'])396 Copyright.new.update(FileList['java/**/*.java'])397 end398end399namespace :side do400 task atoms: [401 '//javascript/atoms/fragments:find-element'402 ] do403 # TODO: move directly to IDE's directory once the repositories are merged404 baseDir = 'build/javascript/atoms'405 mkdir_p baseDir406 [407 Rake::Task['//javascript/atoms/fragments:find-element'].out408 ].each do |atom|409 name = File.basename(atom)410 puts "Generating #{atom} as #{name}"411 File.open(File.join(baseDir, name), 'w') do |f|412 f << "// GENERATED CODE - DO NOT EDIT\n"413 f << 'module.exports = '414 f << IO.read(atom).strip415 f << ";\n"416 end417 end418 end419end420namespace :node do421 atom_list = %w[422 //javascript/atoms/fragments:find-elements423 //javascript/atoms/fragments:is-displayed424 //javascript/webdriver/atoms:get-attribute425 ]426 task atoms: atom_list do427 baseDir = 'javascript/node/selenium-webdriver/lib/atoms'428 mkdir_p baseDir429 puts 'rake outs are below'430 p rake_outs = [431 Rake::Task['//javascript/atoms/fragments:is-displayed'].out,432 Rake::Task['//javascript/webdriver/atoms:get-attribute'].out,433 Rake::Task['//javascript/atoms/fragments:find-elements'].out434 ]435 rake_outs.each do |atom|436 puts "atom is #{atom}\n"437 name = File.basename(atom)438 puts "Generating #{atom} as #{name}"439 File.open(File.join(baseDir, name), 'w') do |f|440 f << "// GENERATED CODE - DO NOT EDIT\n"441 f << 'module.exports = '442 f << IO.read(atom).strip443 f << ";\n"444 end445 end446 end447 task :build do448 sh 'bazel build //javascript/node/selenium-webdriver'449 end450 task 'dry-run': [451 'node:build'452 ] do453 sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.pack'454 end455 task deploy: [456 'node:build'457 ] do458 sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.publish'459 end460 task :docs do461 sh 'node javascript/node/gendocs.js'462 end463end464namespace :py do465 task prep: [466 '//javascript/atoms/fragments:is-displayed',467 '//javascript/webdriver/atoms:get-attribute',468 '//third_party/js/selenium:webdriver_xpi'469 ] do470 py_home = 'py/'471 remote_py_home = py_home + 'selenium/webdriver/remote/'472 firefox_py_home = py_home + 'selenium/webdriver/firefox/'473 if SeleniumRake::Checks.windows?474 remote_py_home = remote_py_home.gsub(/\//, '\\')475 firefox_py_home = firefox_py_home .gsub(/\//, '\\')476 end477 cp Rake::Task['//javascript/atoms/fragments:is-displayed'].out, remote_py_home + 'isDisplayed.js', verbose: true478 cp Rake::Task['//javascript/webdriver/atoms:get-attribute'].out, remote_py_home + 'getAttribute.js', verbose: true479 cp Rake::Task['//third_party/js/selenium:webdriver_xpi'].out, firefox_py_home, verbose: true480 cp 'third_party/js/selenium/webdriver.json', firefox_py_home + 'webdriver_prefs.json', verbose: true481 cp 'LICENSE', py_home + 'LICENSE', verbose: true482 end483 bazel :unit do484 Bazel.execute('test', [], '//py:unit')485 end486 task docs: :prep do487 sh 'tox -c py/tox.ini -e docs', verbose: true488 end489 task install: :prep do490 Dir.chdir('py') do491 sh py_exe + ' setup.py install', verbose: true492 end493 end494 %w[chrome ff marionette ie edge remote_firefox safari].each do |browser|495 browser_data = SeleniumRake::Browsers::BROWSERS[browser]496 deps = browser_data[:deps] || []497 deps += [:prep]...

Full Screen

Full Screen

dsl.rb

Source:dsl.rb Github

copy

Full Screen

1module Rake2 module DSL3 def bazel(*args, &block)4 Bazel::Task.define_task(*args, &block)5 end6 end7end...

Full Screen

Full Screen

bazel

Using AI Code Generation

copy

Full Screen

1 def bazel(*args)2 task = Rake::Task.define_task(*args) do3 def bazel(*args)4 task = Rake::Task.define_task(*args) do5 def bazel(*args)6 task = Rake::Task.define_task(*args) do7 def bazel(*args)8 task = Rake::Task.define_task(*args) do9 def bazel(*args)10 task = Rake::Task.define_task(*args) do11 def bazel(*args)12 task = Rake::Task.define_task(*args) do

Full Screen

Full Screen

bazel

Using AI Code Generation

copy

Full Screen

1 def bazel(*args, &block)2 def bazel(*args, &block)3 def bazel(*args, &block)4 def bazel(*args, &block)5 def bazel(*args, &block)6 def bazel(*args, &block)7 def bazel(*args, &block)8 def bazel(*args, &block)

Full Screen

Full Screen

bazel

Using AI Code Generation

copy

Full Screen

1 def bazel(*args, &block)2 def bazel(*args, &block)3 def bazel(*args, &block)4 def bazel(*args, &block)5 def bazel(*args, &block)6 def bazel(*args, &block)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful