Best Selenium code snippet using Selenium.WebDriver.DriverExtensions.HasNetworkInterception.fetch_response_body
has_network_interception.rb
Source:has_network_interception.rb
...93 end94 end95 def intercept_response(id, params)96 return devtools.fetch.continue_request(request_id: id) unless block_given?97 body = fetch_response_body(id)98 original = DevTools::Response.from(id, body, params)99 mutable = DevTools::Response.from(id, body, params)100 yield mutable101 if original == mutable102 devtools.fetch.continue_request(request_id: id)103 else104 devtools.fetch.fulfill_request(105 request_id: id,106 body: (Base64.strict_encode64(mutable.body) if mutable.body),107 response_code: mutable.code,108 response_headers: mutable.headers.map do |k, v|109 {name: k, value: v}110 end111 )112 end113 end114 def fetch_response_body(id)115 devtools.fetch.get_response_body(request_id: id).dig('result', 'body')116 rescue Error::WebDriverError117 # CDP fails to get body on certain responses (301) and raises:118 # Can only get response body on requests captured after headers received.119 end120 end # HasNetworkInterception121 end # DriverExtensions122 end # WebDriver123end # Selenium...
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!!