Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specs failing on main (ignore favicon requests, expect new error) #273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions spec/features/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def session_url(path)
"http://#{server.host}:#{server.port}#{path}"
end

def non_favicon_exchanges(network_exchanges)
network_exchanges.reject { _1.url == session_url('/favicon.ico') }
end

it "supports a custom path" do
original_path = "#{PROJECT_ROOT}/spec/support/chrome_path"
File.write(original_path, @driver.browser.process.path)
Expand Down Expand Up @@ -716,40 +720,40 @@ def create_screenshot(file, *args)

it "captures responses" do
@session.visit("/cuprite/with_js")
request = @driver.network_traffic.last
request = non_favicon_exchanges(@driver.network_traffic).last

expect(request.response.status).to eq(200)
end

it "captures errors" do
@session.visit("/cuprite/with_ajax_fail")
expect(@session).to have_css("h1", text: "Done")
error = @driver.network_traffic.last.error
error = non_favicon_exchanges(@driver.network_traffic).last.error

expect(error).to be
end

it "keeps a running list between multiple web page views" do
@session.visit("/cuprite/with_js")
expect(@driver.network_traffic.length).to eq(4)
expect(non_favicon_exchanges(@driver.network_traffic).length).to eq(4)

@session.visit("/cuprite/with_js")
expect(@driver.network_traffic.length).to eq(8)
expect(non_favicon_exchanges(@driver.network_traffic).length).to eq(8)
end

it "gets cleared on restart" do
@session.visit("/cuprite/with_js")
expect(@driver.network_traffic.length).to eq(4)
expect(non_favicon_exchanges(@driver.network_traffic).length).to eq(4)

@driver.restart

@session.visit("/cuprite/with_js")
expect(@driver.network_traffic.length).to eq(4)
expect(non_favicon_exchanges(@driver.network_traffic).length).to eq(4)
end

it "gets cleared when being cleared" do
@session.visit("/cuprite/with_js")
expect(@driver.network_traffic.length).to eq(4)
expect(non_favicon_exchanges(@driver.network_traffic).length).to eq(4)

@driver.clear_network_traffic

Expand Down Expand Up @@ -787,21 +791,24 @@ def create_screenshot(file, *args)
@driver.clear_memory_cache

@session.visit("/cuprite/cacheable")
expect(@driver.network_traffic.length).to eq(1)
expect(@driver.network_traffic.last.response.status).to eq(200)
expect(@driver.network_traffic.last.response.params.dig("response", "fromDiskCache")).to be_falsey
network_exchanges = non_favicon_exchanges(@driver.network_traffic)
expect(network_exchanges.length).to eq(1)
expect(network_exchanges.last.response.status).to eq(200)
expect(network_exchanges.last.response.params.dig("response", "fromDiskCache")).to be_falsey

@session.click_link "click me"
expect(@driver.network_traffic.length).to eq(2)
expect(@driver.network_traffic.last.response.status).to eq(200)
expect(@driver.network_traffic.last.response.params.dig("response", "fromDiskCache")).to be_truthy
network_exchanges = non_favicon_exchanges(@driver.network_traffic)
expect(network_exchanges.length).to eq(2)
expect(network_exchanges.last.response.status).to eq(200)
expect(network_exchanges.last.response.params.dig("response", "fromDiskCache")).to be_truthy

@driver.clear_memory_cache

@session.click_link "click me"
expect(@driver.network_traffic.length).to eq(3)
expect(@driver.network_traffic.last.response.status).to eq(200)
expect(@driver.network_traffic.last.response.params.dig("response", "fromDiskCache")).to be_falsey
network_exchanges = non_favicon_exchanges(@driver.network_traffic)
expect(network_exchanges.length).to eq(3)
expect(network_exchanges.last.response.status).to eq(200)
expect(network_exchanges.last.response.params.dig("response", "fromDiskCache")).to be_falsey
end

context "status code support" do
Expand Down Expand Up @@ -1071,8 +1078,11 @@ def create_screenshot(file, *args)
end

context "basic http authentication" do
it "denies without credentials" do
@session.visit "/cuprite/basic_auth"
it "raises an error and denies without credentials" do
expect { @session.visit "/cuprite/basic_auth" }.to raise_error(
Ferrum::StatusError,
%r{Request to .*/basic_auth failed \(net::ERR_INVALID_AUTH_CREDENTIALS\)}
)

expect(@session.status_code).to eq(401)
expect(@session).not_to have_content("Welcome, authenticated client")
Expand Down