Class: Maze::Option::Validator
- Inherits:
-
Object
- Object
- Maze::Option::Validator
- Defined in:
- lib/maze/option/validator.rb
Overview
Validates command line options
Instance Method Summary collapse
-
#validate(options) ⇒ Object
Validates all provided options.
-
#validate_bitbar(options, errors) ⇒ Object
Validates BitBar device options.
-
#validate_bs(options, errors) ⇒ Object
Validates BrowserStack options.
-
#validate_local(options, errors) ⇒ Object
Validates Local device options.
Instance Method Details
#validate(options) ⇒ Object
Validates all provided options
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/maze/option/validator.rb', line 12 def validate() errors = [] # # Common options # # --farm farm = [Option::FARM] if farm && !%w[bs local bb].include?(farm) errors << "--#{Option::FARM} must be 'bs', 'bb' or 'local' if provided" end # --capabilities begin JSON.parse([Option::CAPABILITIES]) rescue JSON::ParserError errors << "--#{Option::CAPABILITIES} must be valid JSON (given #{[Option::CAPABILITIES]})" end # --repeater-api-key key = [Option::BUGSNAG_REPEATER_API_KEY] if key&.empty? $logger.warn "A repeater-api-key option was provided with an empty string. This won't be used during this test run" key = nil end key_regex = /^[0-9a-fA-F]{32}$/ if key && !key_regex.match?(key) errors << "--#{Option::BUGSNAG_REPEATER_API_KEY} must be set to a 32-character hex value" end # --hub-repeater-api-key key = [Option::HUB_REPEATER_API_KEY] if key&.empty? $logger.warn "A hub-repeater-api-key option was provided with an empty string. This won't be used during this test run" key = nil end key_regex = /^[0-9a-fA-F]{32}$/ if key && !key_regex.match?(key) errors << "--#{Option::HUB_REPEATER_API_KEY} must be set to a 32-character hex value" end # Farm specific options validate_bs , errors if farm == 'bs' , errors if farm == 'bb' validate_local , errors if farm == 'local' errors end |
#validate_bitbar(options, errors) ⇒ Object
Validates BitBar device options
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/maze/option/validator.rb', line 106 def (, errors) browser = [Option::BROWSER] device = [Option::DEVICE] errors << "--#{Option::USERNAME} must be specified" if [Option::USERNAME].nil? errors << "--#{Option::ACCESS_KEY} must be specified" if [Option::ACCESS_KEY].nil? # Device if browser.empty? && device.empty? errors << "Either --#{Option::BROWSER} or --#{Option::DEVICE} must be specified" elsif !browser.empty? && device.empty? # Desktop browsers (Selenium) browsers = YAML.safe_load(File.read("#{__dir__}/../client/selenium/bb_browsers.yml")) rejected_browsers = browser.reject { |br| browsers.include? br } if rejected_browsers.empty? if [Option::BROWSER_VERSION].nil? browser.each do |br| next if browsers[br].include?('browserVersion') errors << "--#{Option::BROWSER_VERSION} must be specified for browser '#{br}'" end end else browser_list = browsers.keys.join ', ' errors << "Browser types '#{rejected_browsers.join(', ')}' unknown on BitBar. Must be one of: #{browser_list}." end elsif browser.empty? && !device.empty? # Mobile app testing app = Maze::Helper.read_at_arg_file [Option::APP] if app.nil? errors << "--#{Option::APP} must be provided when running on a device" else uuid_regex = /\A[0-9]+\z/ unless uuid_regex.match? app app = Maze::Helper. app errors << "app file '#{app}' not found" unless File.exist?(app) end end else # TODO - Mobile browser testing end end |
#validate_bs(options, errors) ⇒ Object
Validates BrowserStack options
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/maze/option/validator.rb', line 65 def validate_bs(, errors) # BS local binary bs_local = Maze::Helper. [Option::BS_LOCAL] errors << "BrowserStack local binary '#{bs_local}' not found" unless File.exist? bs_local # Device browser = [Option::BROWSER] device = [Option::DEVICE] if browser.empty? && device.empty? errors << "Either --#{Option::BROWSER} or --#{Option::DEVICE} must be specified" elsif !browser.empty? browsers = YAML.safe_load(File.read("#{__dir__}/../client/selenium/bs_browsers.yml")) rejected_browsers = browser.reject { |br| browsers.include? br } unless rejected_browsers.empty? browser_list = browsers.keys.join ', ' errors << "Browser types '#{rejected_browsers.join(', ')}' unknown on BrowserStack. Must be one of: #{browser_list}." end elsif !device.empty? device.each do |device_key| next if Maze::Client::Appium::BrowserStackDevices::DEVICE_HASH.key? device_key errors << "Device type '#{device_key}' unknown on BrowserStack. Must be one of #{Maze::Client::Appium::BrowserStackDevices::DEVICE_HASH.keys}" end # App app = Maze::Helper.read_at_arg_file [Option::APP] if app.nil? errors << "--#{Option::APP} must be provided when running on a device" else unless app.start_with?('bs://') app = Maze::Helper. app errors << "app file '#{app}' not found" unless File.exist?(app) end end end # Credentials errors << "--#{Option::USERNAME} must be specified" if [Option::USERNAME].nil? errors << "--#{Option::ACCESS_KEY} must be specified" if [Option::ACCESS_KEY].nil? end |
#validate_local(options, errors) ⇒ Object
Validates Local device options
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/maze/option/validator.rb', line 151 def validate_local(, errors) if [Option::BROWSER].empty? errors << "--#{Option::APP} must be specified" if [Option::APP].nil? # OS if [Option::OS].nil? errors << "--#{Option::OS} must be specified" else os = [Option::OS].downcase errors << 'os must be android, ios, macos or windows' unless %w[android ios macos windows].include? os if os == 'ios' errors << "--#{Option::APPLE_TEAM_ID} must be specified for iOS" if [Option::APPLE_TEAM_ID].nil? errors << "--#{Option::UDID} must be specified for iOS" if [Option::UDID].nil? end end # OS Version unless [Option::OS_VERSION].nil? # Ensure OS version is a valid float so that notifier tests can perform numeric checks # e.g 'Maze.config.os_version > 7' unless /^[1-9][0-9]*(\.[0-9])?/.match? [Option::OS_VERSION] errors << "--#{Option::OS_VERSION} must be a valid version matching '/^[1-9][0-9]*(\\.[0-9])?/'" end end else # TODO Validate browser options end end |