@@ -9,6 +9,7 @@ require 'stringio'
99require 'fileutils'
1010require 'open-uri'
1111require 'git'
12+ require 'find'
1213
1314include Rake ::DSL
1415
@@ -593,6 +594,30 @@ namespace :py do
593594 FileUtils . cp_r ( 'bazel-bin/py/selenium/webdriver/.' , 'py/selenium/webdriver' , remove_destination : true )
594595 end
595596
597+ desc 'Update generated Python files for local development'
598+ task :clean do
599+ Bazel . execute ( 'build' , [ ] , '//py:selenium' )
600+ bazel_bin_path = 'bazel-bin/py/selenium/webdriver'
601+ lib_path = 'py/selenium/webdriver'
602+
603+ dirs = %w[ devtools linux mac windows ]
604+ dirs . each { |dir | FileUtils . rm_rf ( "#{ lib_path } /common/#{ dir } " ) }
605+
606+ Find . find ( bazel_bin_path ) do |path |
607+ if File . directory? ( path ) && dirs . any? { |dir | path . include? ( "common/#{ dir } " ) }
608+ Find . prune
609+ next
610+ end
611+ next if File . directory? ( path )
612+
613+ target_file = File . join ( lib_path , path . sub ( /^#{ bazel_bin_path } \/ / , '' ) )
614+ if File . exist? ( target_file )
615+ puts "Removing target file: #{ target_file } "
616+ FileUtils . rm ( target_file )
617+ end
618+ end
619+ end
620+
596621 desc 'Generate Python documentation'
597622 task :docs , [ :skip_update ] do |_task , arguments |
598623 FileUtils . rm_rf ( 'build/docs/api/py/' )
@@ -648,6 +673,23 @@ namespace :py do
648673 task :lint do
649674 `tox -c py/tox.ini -e linting`
650675 end
676+
677+ namespace :test do
678+ desc 'Python unit tests'
679+ task :unit do
680+ Rake ::Task [ 'py:clean' ] . invoke
681+ Bazel . execute ( 'test' , [ '--test_size_filters=small' ] , '//py/...' )
682+ end
683+
684+ %i[ chrome edge firefox safari ] . each do |browser |
685+ desc "Python #{ browser } tests"
686+ task browser do
687+ Rake ::Task [ 'py:clean' ] . invoke
688+ Bazel . execute ( 'test' , [ ] , "//py:common-#{ browser } " )
689+ Bazel . execute ( 'test' , [ ] , "//py:test-#{ browser } " )
690+ end
691+ end
692+ end
651693end
652694
653695def ruby_version
0 commit comments