Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion lib/ferrum/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ def in_viewport?(of: nil)
end

def select_file(value)
page.command("DOM.setFileInputFiles", slowmoable: true, nodeId: node_id, files: Array(value))
page.command(
"DOM.setFileInputFiles",
slowmoable: true,
backendNodeId: description["backendNodeId"],
files: Array(value)
)
end

def at_xpath(selector)
Expand Down
31 changes: 31 additions & 0 deletions spec/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,37 @@
end
end

describe "#select_file" do
it "selects a file" do
browser.go_to("/form")
input = browser.at_css("#form_image")

input.select_file(File.expand_path(__FILE__))

expect(input.value).to eq("C:\\fakepath\\node_spec.rb")
end

it "uses the backend node id for the file input" do
page = instance_double(Ferrum::Page)
frame = instance_double(Ferrum::Frame, page: page)
node = described_class.new(
frame,
"target-id",
{ "nodeName" => "INPUT", "backendNodeId" => 42 },
node_id: 7
)

expect(page).to receive(:command).with(
"DOM.setFileInputFiles",
slowmoable: true,
backendNodeId: 42,
files: ["spec/tmp/upload.txt"]
)

node.select_file("spec/tmp/upload.txt")
end
end

describe "#drag_to", skip: true do
before { browser.go_to("/drag") }

Expand Down
Loading