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

Update to run multiple instances of same webdriver #30

Merged
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
33 changes: 33 additions & 0 deletions spec/features/session_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "../spec_helper"

module Selenium::Command
describe "session", tags: "feature" do
it "run multiple browsers on separate process" do
TestServer.route "/home", "<h1>The Title</h1>"
TestServer.route "/next-page", "<h1>You made it!</h1>"
TestServer.route "/action-page", <<-HTML
<a href="/next-page">Click Me!</a>
HTML

begin
driver1, args1 = Selenium::TestDriverFactory.build(ENV["SELENIUM_BROWSER"]? || "chrome")
session1 = driver1.not_nil!.create_session(args: args1.not_nil!)
driver2, args2 = Selenium::TestDriverFactory.build(ENV["SELENIUM_BROWSER"]? || "chrome")
session2 = driver2.not_nil!.create_session(args: args2.not_nil!)

session1.navigate_to("http://localhost:3002/home")
session2.navigate_to("http://localhost:3002/action-page")
element = session2.find_element(:link_text, "Click Me!")
element.click
session1.current_url.should eq("http://localhost:3002/home")
session2.current_url.should eq("http://localhost:3002/next-page")
ensure
session1.try &.delete
driver1.try &.stop
session2.try &.delete
driver2.try &.stop
TestServer.reset
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered this error after running the specs. The TestServer port remains open after the test.
It doesn't happen all the time though.
image

end
end
end
end
7 changes: 7 additions & 0 deletions src/selenium/service.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract class Selenium::Service
end

def start
find_free_port
start_process
verify_running
end
Expand All @@ -37,6 +38,12 @@ abstract class Selenium::Service

abstract def default_port : Int32

private def find_free_port
while listening?
@port += 1
end
end

private def start_process
@process = Process.new(
@driver_path,
Expand Down