Skip to content

Commit

Permalink
Improve DevTools request interception test by loading different JS
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Oct 11, 2021
1 parent 94c8c11 commit c9a2ef6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
15 changes: 15 additions & 0 deletions common/src/web/devToolsRequestInterceptionTest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>

<html lang="en">
<head>
<title>DevTools Request Interception Test</title>
<script language="javascript" type="text/javascript" src="devtools_request_interception_test/one.js"></script>
</head>

<body>
<div id="result"></div>
<button onClick="printScriptName()">
Click me to print script name
</button>
</body>
</html>
3 changes: 3 additions & 0 deletions common/src/web/devtools_request_interception_test/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function printScriptName() {
document.getElementById('result').innerHTML = 'one';
}
3 changes: 3 additions & 0 deletions common/src/web/devtools_request_interception_test/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function printScriptName() {
document.getElementById('result').innerHTML = 'two';
}
9 changes: 5 additions & 4 deletions rb/spec/integration/selenium/webdriver/devtools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ module WebDriver
it 'changes requests' do
driver.intercept do |request, &continue|
uri = URI(request.url)
if uri.path.match?(%r{/html5/.*\.jpg})
uri.path = '/beach.jpg'
if uri.path.end_with?('one.js')
uri.path = '/devtools_request_interception_test/two.js'
request.url = uri.to_s
end
continue.call(request)
end
driver.navigate.to url_for('html5Page.html')
expect(driver.find_elements(tag_name: 'img').map(&:size).uniq).to eq([Dimension.new(640, 480)])
driver.navigate.to url_for('devToolsRequestInterceptionTest.html')
driver.find_element(tag_name: 'button').click
expect(driver.find_element(id: 'result').text).to eq('two')
end

it 'continues responses' do
Expand Down

0 comments on commit c9a2ef6

Please sign in to comment.