Best Selenium code snippet using SeleniumRake.chrome
Rakefile
Source:Rakefile
...102 //java/client/src/org/openqa/selenium/devtools/v86:v86.publish103 //java/client/src/org/openqa/selenium/devtools/v85:v85.publish104 //java/client/src/org/openqa/selenium/devtools:devtools.publish105 //java/client/src/org/openqa/selenium/chromium:chromium.publish106 //java/client/src/org/openqa/selenium/chrome:chrome.publish107 //java/client/src/org/openqa/selenium:core.publish108 //java/client/src/org/openqa/selenium:client-combined.publish109]110# Notice that because we're using rake, anything you can do in a normal rake111# build can also be done here. For example, here we set the default task112task default: [:grid]113task all: [114 :"selenium-java",115 '//java/client/test/org/openqa/selenium/environment:webserver'116]117task all_zip: [:'prep-release-zip']118task tests: [119 '//java/client/test/org/openqa/selenium/htmlunit:htmlunit',120 '//java/client/test/org/openqa/selenium/firefox:test-synthesized',121 '//java/client/test/org/openqa/selenium/ie:ie',122 '//java/client/test/org/openqa/selenium/chrome:chrome',123 '//java/client/test/org/openqa/selenium/edge:edge',124 '//java/client/test/org/openqa/selenium/opera:opera',125 '//java/client/test/org/openqa/selenium/support:small-tests',126 '//java/client/test/org/openqa/selenium/support:large-tests',127 '//java/client/test/org/openqa/selenium/remote:small-tests',128 '//java/server/test/org/openqa/selenium/remote/server/log:test',129 '//java/server/test/org/openqa/selenium/remote/server:small-tests'130]131task chrome: ['//java/client/src/org/openqa/selenium/chrome']132task grid: [:'selenium-server-standalone']133task ie: ['//java/client/src/org/openqa/selenium/ie']134task firefox: ['//java/client/src/org/openqa/selenium/firefox']135task remote: %i[remote_server remote_client]136task remote_client: ['//java/client/src/org/openqa/selenium/remote']137task remote_server: ['//java/server/src/org/openqa/selenium/remote/server']138task safari: ['//java/client/src/org/openqa/selenium/safari']139task selenium: ['//java/client/src/org/openqa/selenium:core']140task support: [141 '//java/client/src/org/openqa/selenium/lift',142 '//java/client/src/org/openqa/selenium/support'143]144desc 'Build the standalone server'145task 'selenium-server-standalone' => '//java/server/src/org/openqa/selenium/grid:executable-grid'146task test_javascript: [147 '//javascript/atoms:test-chrome:run',148 '//javascript/webdriver:test-chrome:run',149 '//javascript/selenium-atoms:test-chrome:run',150 '//javascript/selenium-core:test-chrome:run'151]152task test_chrome: ['//java/client/test/org/openqa/selenium/chrome:chrome:run']153task test_edge: ['//java/client/test/org/openqa/selenium/edge:edge:run']154task test_chrome_atoms: [155 '//javascript/atoms:test-chrome:run',156 '//javascript/chrome-driver:test-chrome:run',157 '//javascript/webdriver:test-chrome:run'158]159task test_htmlunit: [160 '//java/client/test/org/openqa/selenium/htmlunit:htmlunit:run'161]162task test_grid: [163 '//java/server/test/org/openqa/grid/common:common:run',164 '//java/server/test/org/openqa/grid:grid:run',165 '//java/server/test/org/openqa/grid/e2e:e2e:run',166 '//java/client/test/org/openqa/selenium/remote:remote-driver-grid-tests:run'167]168task test_ie: [169 '//cpp/iedriverserver:win32',170 '//cpp/iedriverserver:x64',171 '//java/client/test/org/openqa/selenium/ie:ie:run'172]173task test_jobbie: [:test_ie]174task test_firefox: ['//java/client/test/org/openqa/selenium/firefox:marionette:run']175task test_opera: ['//java/client/test/org/openqa/selenium/opera:opera:run']176task test_remote_server: [177 '//java/server/test/org/openqa/selenium/remote/server:small-tests:run',178 '//java/server/test/org/openqa/selenium/remote/server/log:test:run'179]180task test_remote: [181 '//java/client/test/org/openqa/selenium/json:small-tests:run',182 '//java/client/test/org/openqa/selenium/remote:common-tests:run',183 '//java/client/test/org/openqa/selenium/remote:client-tests:run',184 '//java/client/test/org/openqa/selenium/remote:remote-driver-tests:run',185 :test_remote_server186]187task test_safari: ['//java/client/test/org/openqa/selenium/safari:safari:run']188task test_support: [189 '//java/client/test/org/openqa/selenium/lift:lift:run',190 '//java/client/test/org/openqa/selenium/support:small-tests:run',191 '//java/client/test/org/openqa/selenium/support:large-tests:run'192]193# TODO(simon): test-core should go first, but it's changing the least for now.194task test_selenium: [:'test-rc']195task 'test-rc': ['//java/client/test/com/thoughtworks/selenium:firefox-rc-test:run']196task 'test-rc': ['//java/client/test/com/thoughtworks/selenium:ie-rc-test:run'] if SeleniumRake::Checks.windows?197task test_java_webdriver: %i[198 test_htmlunit199 test_firefox200 test_remote_server201]202task test_java_webdriver: [:test_ie] if SeleniumRake::Checks.windows?203task test_java_webdriver: [:test_chrome] if SeleniumRake::Checks.chrome?204task test_java_webdriver: [:test_edge] if SeleniumRake::Checks.edge?205task test_java_webdriver: [:test_opera] if SeleniumRake::Checks.opera?206task test_java: [207 '//java/client/test/org/openqa/selenium/atoms:test:run',208 :test_java_small_tests,209 :test_support,210 :test_java_webdriver,211 :test_selenium,212 'test_grid'213]214task test_java_small_tests: [215 '//java/client/test/org/openqa/selenium:small-tests:run',216 '//java/client/test/org/openqa/selenium/json:small-tests:run',217 '//java/client/test/org/openqa/selenium/support:small-tests:run',218 '//java/client/test/org/openqa/selenium/remote:common-tests:run',219 '//java/client/test/org/openqa/selenium/remote:client-tests:run',220 '//java/server/test/org/openqa/grid/selenium/node:node:run',221 '//java/server/test/org/openqa/grid/selenium/proxy:proxy:run',222 '//java/server/test/org/openqa/selenium/remote/server:small-tests:run',223 '//java/server/test/org/openqa/selenium/remote/server/log:test:run'224]225task test_rb: ['//rb:unit-test', :test_rb_local, :test_rb_remote]226task test_rb_local: [227 '//rb:chrome-test',228 '//rb:firefox-test',229 ('//rb:firefox-nightly-test' if ENV['FIREFOX_NIGHTLY_BINARY']),230 ('//rb:safari-preview-test' if SeleniumRake::Checks.mac?),231 ('//rb:safari-test' if SeleniumRake::Checks.mac?),232 ('//rb:ie-test' if SeleniumRake::Checks.windows?),233 ('//rb:edge-test' unless SeleniumRake::Checks.linux?)234].compact235task test_rb_remote: [236 '//rb:remote-chrome-test',237 '//rb:remote-firefox-test',238 ('//rb:remote-firefox-nightly-test' if ENV['FIREFOX_NIGHTLY_BINARY']),239 ('//rb:remote-safari-test' if SeleniumRake::Checks.mac?),240 # BUG - https://github.com/SeleniumHQ/selenium/issues/6791241 # ('//rb:remote-safari-preview-test' if SeleniumRake::Checks.mac?),242 ('//rb:remote-ie-test' if SeleniumRake::Checks.windows?),243 ('//rb:remote-edge-test' unless SeleniumRake::Checks.linux?)244].compact245task test_py: [:py_prep_for_install_release, 'py:marionette_test']246task test: %i[test_javascript test_java test_rb]247task test: [:test_py] if SeleniumRake::Checks.python?248task build: %i[all firefox remote selenium tests]249desc 'Clean build artifacts.'250task :clean do251 rm_rf 'build/'252 rm_rf 'java/client/build/'253 rm_rf 'dist/'254end255# Create a new IEGenerator instance256ie_generator = SeleniumRake::IEGenerator.new257# Generate a C++ Header file for mapping between magic numbers and #defines258# in the C++ code.259ie_generator.generate_type_mapping(260 name: 'ie_result_type_cpp',261 src: 'cpp/iedriver/result_types.txt',262 type: 'cpp',263 out: 'cpp/iedriver/IEReturnTypes.h'264)265task javadocs: %i[//java/server/src/org/openqa/selenium/grid:all-javadocs] do266 rm_rf 'build/javadoc'267 mkdir_p 'build/javadoc'268 out = Rake::Task['//java/server/src/org/openqa/selenium/grid:all-javadocs'].out269 cmd = %{cd build/javadoc && jar xf "../../#{out}" 2>&1}270 if SeleniumRake::Checks.windows?271 cmd = cmd.gsub(/\//, '\\').gsub(/:/, ';')272 end273 ok = system(cmd)274 ok or raise "could not unpack javadocs"275 File.open('build/javadoc/stylesheet.css', 'a') { |file|276 file.write(<<~EOF277 /* Custom selenium-specific styling */278 .blink {279 animation: 2s cubic-bezier(0.5, 0, 0.85, 0.85) infinite blink;280 }281 @keyframes blink {282 50% {283 opacity: 0;284 }285 }286 EOF287 )288 }289end290file 'cpp/iedriver/sizzle.h' => ['//third_party/js/sizzle:sizzle:header'] do291 cp 'build/third_party/js/sizzle/sizzle.h', 'cpp/iedriver/sizzle.h'292end293task sizzle_header: ['cpp/iedriver/sizzle.h']294task ios_driver: [295 '//javascript/atoms/fragments:get_visible_text:ios',296 '//javascript/atoms/fragments:click:ios',297 '//javascript/atoms/fragments:back:ios',298 '//javascript/atoms/fragments:forward:ios',299 '//javascript/atoms/fragments:submit:ios',300 '//javascript/atoms/fragments:xpath:ios',301 '//javascript/atoms/fragments:xpaths:ios',302 '//javascript/atoms/fragments:type:ios',303 '//javascript/atoms/fragments:get_attribute:ios',304 '//javascript/atoms/fragments:clear:ios',305 '//javascript/atoms/fragments:is_selected:ios',306 '//javascript/atoms/fragments:is_enabled:ios',307 '//javascript/atoms/fragments:is_shown:ios',308 '//javascript/atoms/fragments:stringify:ios',309 '//javascript/atoms/fragments:link_text:ios',310 '//javascript/atoms/fragments:link_texts:ios',311 '//javascript/atoms/fragments:partial_link_text:ios',312 '//javascript/atoms/fragments:partial_link_texts:ios',313 '//javascript/atoms/fragments:get_interactable_size:ios',314 '//javascript/atoms/fragments:scroll_into_view:ios',315 '//javascript/atoms/fragments:get_effective_style:ios',316 '//javascript/atoms/fragments:get_element_size:ios',317 '//javascript/webdriver/atoms/fragments:get_location_in_view:ios'318]319task 'prep-release-zip': [320 '//java/client/src/org/openqa/selenium:client-zip',321 '//java/server/src/org/openqa/selenium/grid:server-zip',322 '//java/server/src/org/openqa/selenium/grid:executable-grid',323 '//java/server/src/org/openqa/selenium/server/htmlrunner:selenium-runner_deploy.jar'324] do325 ["build/dist/selenium-server-#{version}.zip", "build/dist/selenium-java-#{version}.zip",326 "build/dist/selenium-server-#{version}.jar", "build/dist/selenium-html-runner-#{version}.jar"].each do |f|327 rm_f(f) if File.exists?(f)328 end329 mkdir_p 'build/dist'330 File.delete331 cp Rake::Task['//java/server/src/org/openqa/selenium/grid:server-zip'].out, "build/dist/selenium-server-#{version}.zip", preserve: false332 chmod 0666, "build/dist/selenium-server-#{version}.zip"333 cp Rake::Task['//java/client/src/org/openqa/selenium:client-zip'].out, "build/dist/selenium-java-#{version}.zip", preserve: false334 chmod 0666, "build/dist/selenium-java-#{version}.zip"335 cp Rake::Task['//java/server/src/org/openqa/selenium/grid:executable-grid'].out, "build/dist/selenium-server-#{version}.jar", preserve: false336 chmod 0666, "build/dist/selenium-server-#{version}.jar"337 cp Rake::Task['//java/server/src/org/openqa/selenium/server/htmlrunner:selenium-runner_deploy.jar'].out, "build/dist/selenium-html-runner-#{version}.jar", preserve: false338 chmod 0666, "build/dist/selenium-html-runner-#{version}.jar"339end340task 'release-java': %i[publish-maven push-release]341def read_user_pass_from_m2_settings342 settings = File.read(ENV['HOME'] + '/.m2/settings.xml')343 found_section = false344 user = nil345 pass = nil346 settings.each_line do |line|347 if !found_section348 found_section = line.include? '<id>sonatype-nexus-staging</id>'349 else350 if (user.nil?) && line.include?('<username>')351 user = line.split('<username>')[1].split('</')[0]352 elsif (pass.nil?) && line.include?('<password>')353 pass = line.split('<password>')[1].split('</')[0]354 end355 end356 end357 return [user, pass]358end359task 'publish-maven': JAVA_RELEASE_TARGETS + %w[//java/server/src/org/openqa/selenium/server/htmlrunner:selenium-runner_deploy.jar] do360 creds = read_user_pass_from_m2_settings361 JAVA_RELEASE_TARGETS.each do |p|362 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)363 end364end365task :'maven-install' do366 JAVA_RELEASE_TARGETS.each do |p|367 Bazel::execute('run', ['--stamp', '--define', "maven_repo=file://#{ENV['HOME']}/.m2/repository", '--define', 'gpg_sign=true'], p)368 end369end370task 'push-release': [:'prep-release-zip'] do371 py = 'java -jar third_party/py/jython.jar'372 py = 'python' if SeleniumRake::Checks.python?373 sh "#{py} third_party/py/googlestorage/publish_release.py --project_id google.com:webdriver --bucket selenium-release --acl public-read --publish_version #{google_storage_version} --publish build/dist/selenium-server-#{version}.jar --publish build/dist/selenium-java-#{version}.zip --publish build/dist/selenium-server-#{version}.jar --publish build/dist/selenium-html-runner-#{version}.jar"374end375desc 'Build the selenium client jars'376task 'selenium-java' => '//java/client/src/org/openqa/selenium:client-combined'377namespace :safari do378 desc 'Build the SafariDriver java client'379 task build: [380 '//java/client/src/org/openqa/selenium/safari'381 ]382end383task :authors do384 puts 'Generating AUTHORS file'385 sh "(git log --use-mailmap --format='%aN <%aE>' ; cat .OLD_AUTHORS) | sort -uf > AUTHORS"386end387namespace :copyright do388 task :update do389 Copyright.new.update(390 FileList['javascript/**/*.js'].exclude(391 'javascript/atoms/test/jquery.min.js',392 'javascript/jsunit/**/*.js',393 'javascript/node/selenium-webdriver/node_modules/**/*.js',394 'javascript/selenium-core/lib/**/*.js',395 'javascript/selenium-core/scripts/ui-element.js',396 'javascript/selenium-core/scripts/ui-map-sample.js',397 'javascript/selenium-core/scripts/user-extensions.js',398 'javascript/selenium-core/scripts/xmlextras.js',399 'javascript/selenium-core/xpath/**/*.js'400 )401 )402 Copyright.new(comment_characters: '#').update(FileList['py/**/*.py'])403 Copyright.new(comment_characters: '#', prefix: ["# frozen_string_literal: true\n", "\n"])404 .update(FileList['rb/**/*.rb'])405 Copyright.new.update(FileList['java/**/*.java'])406 end407end408namespace :side do409 task atoms: [410 '//javascript/atoms/fragments:find-element'411 ] do412 # TODO: move directly to IDE's directory once the repositories are merged413 baseDir = 'build/javascript/atoms'414 mkdir_p baseDir415 [416 Rake::Task['//javascript/atoms/fragments:find-element'].out417 ].each do |atom|418 name = File.basename(atom)419 puts "Generating #{atom} as #{name}"420 File.open(File.join(baseDir, name), 'w') do |f|421 f << "// GENERATED CODE - DO NOT EDIT\n"422 f << 'module.exports = '423 f << IO.read(atom).strip424 f << ";\n"425 end426 end427 end428end429namespace :jruby do430 desc 'Update jruby version'431 task :update do432 jruby_version = '9.2.8.0'433 jruby_gems = { 'inifile' => '3.0.0' }434 jar_name = "jruby-complete-#{jruby_version}.jar"435 url = "https://repo1.maven.org/maven2/org/jruby/jruby-complete/#{jruby_version}/#{jar_name}"436 Dir.chdir('third_party/jruby') do437 puts "Downloading #{jar_name} from #{url}..."438 File.open(jar_name, 'wb') do |write_file|439 open(url, 'rb') do |read_file|440 write_file.write(read_file.read)441 end442 end443 puts 'Installing gems...'444 jruby_gems.each do |gem_name, gem_version|445 sh 'java', '-jar', jar_name, '-S', 'gem', 'install', '-i', "./#{gem_name}", gem_name, '-v', gem_version446 sh 'jar', 'uf', jar_name, '-C', gem_name, '.'447 rm_rf gem_name448 end449 puts 'Bumping VERSION...'450 version = `java -jar #{jar_name} -v`.split("\n").first451 File.write('VERSION', "#{version}\n")452 mv jar_name, 'jruby-complete.jar'453 puts 'Done!'454 end455 end456end457namespace :node do458 atom_list = %w[459 //javascript/atoms/fragments:find-elements460 //javascript/atoms/fragments:is-displayed461 //javascript/webdriver/atoms:get-attribute462 ]463 task atoms: atom_list do464 baseDir = 'javascript/node/selenium-webdriver/lib/atoms'465 mkdir_p baseDir466 puts 'rake outs are below'467 p rake_outs = [468 Rake::Task['//javascript/atoms/fragments:is-displayed'].out,469 Rake::Task['//javascript/webdriver/atoms:get-attribute'].out,470 Rake::Task['//javascript/atoms/fragments:find-elements'].out471 ]472 rake_outs.each do |atom|473 puts "atom is #{atom}\n"474 name = File.basename(atom)475 puts "Generating #{atom} as #{name}"476 File.open(File.join(baseDir, name), 'w') do |f|477 f << "// GENERATED CODE - DO NOT EDIT\n"478 f << 'module.exports = '479 f << IO.read(atom).strip480 f << ";\n"481 end482 end483 end484 task :build do485 sh 'bazel build //javascript/node/selenium-webdriver'486 end487 task 'dry-run': [488 'node:build'489 ] do490 sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.pack'491 end492 task deploy: [493 'node:build'494 ] do495 sh 'bazel run javascript/node/selenium-webdriver:selenium-webdriver.publish'496 end497 task :docs do498 sh 'node javascript/node/gendocs.js'499 end500end501namespace :py do502 task prep: [503 '//javascript/atoms/fragments:is-displayed',504 '//javascript/webdriver/atoms:get-attribute',505 '//third_party/js/selenium:webdriver_xpi'506 ] do507 py_home = 'py/'508 remote_py_home = py_home + 'selenium/webdriver/remote/'509 firefox_py_home = py_home + 'selenium/webdriver/firefox/'510 if SeleniumRake::Checks.windows?511 remote_py_home = remote_py_home.gsub(/\//, '\\')512 firefox_py_home = firefox_py_home .gsub(/\//, '\\')513 end514 cp Rake::Task['//javascript/atoms/fragments:is-displayed'].out, remote_py_home + 'isDisplayed.js', verbose: true515 cp Rake::Task['//javascript/webdriver/atoms:get-attribute'].out, remote_py_home + 'getAttribute.js', verbose: true516 cp Rake::Task['//third_party/js/selenium:webdriver_xpi'].out, firefox_py_home, verbose: true517 cp 'third_party/js/selenium/webdriver.json', firefox_py_home + 'webdriver_prefs.json', verbose: true518 cp 'LICENSE', py_home + 'LICENSE', verbose: true519 end520 bazel :unit do521 Bazel.execute('test', [], '//py:unit')522 end523 task docs: :prep do524 sh 'tox -c py/tox.ini -e docs', verbose: true525 end526 task install: :prep do527 Dir.chdir('py') do528 sh py_exe + ' setup.py install', verbose: true529 end530 end531 %w[chrome ff marionette ie edge remote_firefox safari].each do |browser|532 browser_data = SeleniumRake::Browsers::BROWSERS[browser]533 deps = browser_data[:deps] || []534 deps += [:prep]535 driver = browser_data[:driver]536 task "#{browser}_test" => deps do537 tox_test driver538 end539 end540end541at_exit do542 if File.exist?('.git') && !SeleniumRake::Checks.windows?543 system 'sh', '.git-fixfiles'544 end545end...
chrome
Using AI Code Generation
1 Selenium::WebDriver.for :firefox, binary: 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'2 Selenium::WebDriver.for :firefox, profile: 'default', binary: 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'3 Selenium::WebDriver.for :chrome, options: {detach: true}
chrome
Using AI Code Generation
1 Selenium::WebDriver.for :firefox, binary: 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'2 Selenium::WebDriver.for :firefox, profile: 'default', binary: 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'3 Selenium::WebDriver.for :chrome, options: {detach: true}
chrome
Using AI Code Generation
1 Selenium::WebDriver.for :firefox, binary: 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'2 Selenium::WebDriver.for :firefox, profile: 'default', binary: 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'3 Selenium::WebDriver.for :chrome, options: {detach: true}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!