Best Selenium code snippet using Selenium.WebDriver.IE.expect_request
driver_spec.rb
Source:driver_spec.rb
...26 {status: 200,27 body: {value: {sessionId: 0, capabilities: Remote::Capabilities.ie}}.to_json,28 headers: {"content_type": "application/json"}}29 end30 def expect_request(body: nil, endpoint: nil)31 body = (body || {capabilities: {firstMatch: [browserName: "internet explorer",32 platformName: 'windows']}}).to_json33 endpoint ||= "#{service_manager.uri}/session"34 stub_request(:post, endpoint).with(body: body).to_return(valid_response)35 end36 before do37 allow(Service).to receive_messages(new: service)38 end39 it 'does not require any parameters' do40 expect_request41 expect { Driver.new }.not_to raise_exception42 end43 context 'with :desired capabilities' do44 it 'accepts value as a Symbol' do45 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",46 platformName: 'windows']}})47 expect {48 expect { Driver.new(desired_capabilities: :ie) }.to have_deprecated(:desired_capabilities)49 }.not_to raise_exception50 end51 it 'accepts Capabilities.ie' do52 capabilities = Remote::Capabilities.ie(invalid: 'foobar')53 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",54 platformName: 'windows',55 invalid: 'foobar']}})56 expect {57 expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)58 }.not_to raise_exception59 end60 it 'accepts constructed Capabilities with Snake Case as Symbols' do61 capabilities = Remote::Capabilities.new(browser_name: 'internet explorer', invalid: 'foobar')62 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",63 invalid: 'foobar']}})64 expect {65 expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)66 }.not_to raise_exception67 end68 it 'accepts constructed Capabilities with Camel Case as Symbols' do69 capabilities = Remote::Capabilities.new(browserName: 'internet explorer', invalid: 'foobar')70 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",71 invalid: 'foobar']}})72 expect {73 expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)74 }.not_to raise_exception75 end76 it 'accepts constructed Capabilities with Camel Case as Strings' do77 capabilities = Remote::Capabilities.new('browserName' => 'internet explorer', 'invalid' => 'foobar')78 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",79 invalid: 'foobar']}})80 expect {81 expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)82 }.not_to raise_exception83 end84 it 'accepts Hash with Camel Case keys as Symbols' do85 capabilities = {browserName: 'internet explorer', invalid: 'foobar'}86 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",87 invalid: 'foobar']}})88 expect {89 expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)90 }.not_to raise_exception91 end92 it 'accepts Hash with Camel Case keys as Strings' do93 capabilities = {"browserName" => 'internet explorer', "invalid" => 'foobar'}94 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",95 invalid: 'foobar']}})96 expect {97 expect { Driver.new(desired_capabilities: capabilities) }.to have_deprecated(:desired_capabilities)98 }.not_to raise_exception99 end100 end101 it 'accepts provided Options as sole parameter' do102 opts = {invalid: 'foobar', args: ['-f']}103 expect_request(body: {capabilities: {firstMatch: ["browserName": "internet_explorer",104 "se:ieOptions": {"invalid": "foobar",105 "nativeEvents": true,106 "ie.browserCommandLineSwitches": "-f"}]}})107 expect {108 expect { Driver.new(options: Options.new(**opts)) }.to have_deprecated(:browser_options)109 }.not_to raise_exception110 end111 it 'accepts combination of Options and Capabilities' do112 caps = Remote::Capabilities.ie(invalid: 'foobar')113 browser_opts = {args: ['-f']}114 expect_request(body: {capabilities: {firstMatch: ["browserName": "internet_explorer",115 "platformName": "windows",116 "invalid": "foobar",117 "se:ieOptions": {"nativeEvents": true,118 "ie.browserCommandLineSwitches": "-f"}]}})119 expect {120 expect {121 Driver.new(options: Options.new(**browser_opts), desired_capabilities: caps)122 }.to have_deprecated(%i[browser_options desired_capabilities])123 }.not_to raise_exception124 end125 it 'raises an ArgumentError if parameter is not recognized' do126 msg = 'Unable to create a driver with parameters: {:invalid=>"foo"}'127 expect { Driver.new(invalid: 'foo') }.to raise_error(ArgumentError, msg)128 end129 context 'with :capabilities' do130 it 'accepts value as a Symbol' do131 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",132 platformName: 'windows']}})133 expect { Driver.new(capabilities: :ie) }.not_to raise_exception134 end135 it 'accepts Capabilities.ie' do136 capabilities = Remote::Capabilities.ie(invalid: 'foobar')137 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer",138 platformName: 'windows',139 invalid: 'foobar']}})140 expect { Driver.new(capabilities: capabilities) }.not_to raise_exception141 end142 it 'accepts constructed Capabilities with Snake Case as Symbols' do143 capabilities = Remote::Capabilities.new(browser_name: 'internet explorer', invalid: 'foobar')144 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer", invalid: 'foobar']}})145 expect { Driver.new(capabilities: capabilities) }.not_to raise_exception146 end147 it 'accepts constructed Capabilities with Camel Case as Symbols' do148 capabilities = Remote::Capabilities.new(browserName: 'internet explorer', invalid: 'foobar')149 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer", invalid: 'foobar']}})150 expect { Driver.new(capabilities: capabilities) }.not_to raise_exception151 end152 it 'accepts constructed Capabilities with Camel Case as Strings' do153 capabilities = Remote::Capabilities.new('browserName' => 'internet explorer', 'invalid' => 'foobar')154 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer", invalid: 'foobar']}})155 expect { Driver.new(capabilities: capabilities) }.not_to raise_exception156 end157 it 'accepts Hash with Camel Case keys as Symbols but is deprecated' do158 capabilities = {browserName: 'internet explorer', invalid: 'foobar'}159 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer", invalid: 'foobar']}})160 expect {161 expect { Driver.new(capabilities: capabilities) }.to have_deprecated(:capabilities_hash)162 }.not_to raise_exception163 end164 it 'accepts Hash with Camel Case keys as Strings but is deprecated' do165 capabilities = {"browserName" => 'internet explorer', "invalid" => 'foobar'}166 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer", invalid: 'foobar']}})167 expect {168 expect { Driver.new(capabilities: capabilities) }.to have_deprecated(:capabilities_hash)169 }.not_to raise_exception170 end171 context 'when value is an Array' do172 let(:as_json_object) do173 Class.new do174 def as_json(*)175 {'company:key': 'value'}176 end177 end178 end179 it 'with Options instance' do180 browser_opts = {start_page: 'http://selenium.dev'}181 expect_request(body: {capabilities: {firstMatch: [browserName: "internet_explorer",182 'se:ieOptions': {"startPage": 'http://selenium.dev',183 'nativeEvents': true}]}})184 expect { Driver.new(capabilities: [Options.new(**browser_opts)]) }.not_to raise_exception185 end186 it 'with Capabilities instance' do187 capabilities = Remote::Capabilities.new(browser_name: 'internet explorer', invalid: 'foobar')188 expect_request(body: {capabilities: {firstMatch: [browserName: "internet explorer", invalid: 'foobar']}})189 expect { Driver.new(capabilities: [capabilities]) }.not_to raise_exception190 end191 it 'with Options instance and an instance of a custom object responding to #as_json' do192 expect_request(body: {capabilities: {firstMatch: [browserName: "internet_explorer",193 'se:ieOptions': {"nativeEvents": true},194 'company:key': 'value']}})195 expect { Driver.new(capabilities: [Options.new, as_json_object.new]) }.not_to raise_exception196 end197 it 'with Options instance, Capabilities instance and instance of a custom object responding to #as_json' do198 capabilities = Remote::Capabilities.new(browser_name: 'internet explorer', invalid: 'foobar')199 options = Options.new(start_page: 'http://selenium.dev')200 expect_request(body: {capabilities: {firstMatch: [browserName: "internet_explorer",201 invalid: 'foobar',202 'se:ieOptions': {"startPage": 'http://selenium.dev',203 'nativeEvents': true},204 'company:key': 'value']}})205 expect { Driver.new(capabilities: [capabilities, options, as_json_object.new]) }.not_to raise_exception206 end207 end208 end209 end210 end # IE211 end # WebDriver212end # Selenium...
expect_request
Using AI Code Generation
1ie_drivrrefind_elemenq(:name, "q").send_keys "Selenium WebDriver"2ie_driver.find_element(:name, "btnG").click3expect_request.wait_for_request("Selenium WebDriver", 10)
expect_request
Using AI Code Generation
1search_text = driver.find_element(:name, 'q')2search_results = driver.find_elements(:xpath, '//h3/a')3search_text = driver.find_element(:name, 'q')4search_results = driver.find_elements(:xpath, '//h3/a')5search_text = driver.find_element(:name, 'q')
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!!