Skip to content

Commit

Permalink
Update Service & Driver class to run multiple instances of same drive…
Browse files Browse the repository at this point in the history
…r on different port (#30)
  • Loading branch information
Dakad committed May 8, 2023
1 parent dc082a3 commit c73022f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/features/session_spec.cr
@@ -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
end
end
end
end
7 changes: 7 additions & 0 deletions src/selenium/service.cr
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

0 comments on commit c73022f

Please sign in to comment.