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

Introduce driver registration #133

Merged
merged 10 commits into from
Jan 14, 2022
Prev Previous commit
Next Next commit
Don't delete screenshot dir when creating driver
Could delete screenshots taken from different driver in same suite
matthewmcgarvey committed Jan 13, 2022
commit 5a947fffa9b174f3513bb697e0c530a4e2af4995
8 changes: 6 additions & 2 deletions src/lucky_flow.cr
Original file line number Diff line number Diff line change
@@ -74,9 +74,9 @@ class LuckyFlow

def take_screenshot(filename : String = generate_screenshot_filename, fullsize : Bool = true)
if fullsize
with_fullsized_page { session.screenshot(filename) }
with_fullsized_page { driver.screenshot(filename) }
Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to the driver instead of the session so that the driver could make the screenshot directory if it's missing

else
session.screenshot(filename)
driver.screenshot(filename)
end
end

@@ -213,4 +213,8 @@ class LuckyFlow
def session : Selenium::Session
self.class.session
end

def driver : LuckyFlow::Driver
self.class.driver
end
end
19 changes: 6 additions & 13 deletions src/lucky_flow/driver.cr
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
abstract class LuckyFlow::Driver
@retry_limit : Time = 2.seconds.from_now

getter session : Selenium::Session do
prepare_screenshot_directory
start_session
end
getter session : Selenium::Session { start_session }

abstract def start_session : Selenium::Session
abstract def stop
@@ -18,6 +15,11 @@ abstract class LuckyFlow::Driver
stop
end

def screenshot(path : String)
FileUtils.mkdir_p(File.dirname(path))
session.screenshot(path)
Copy link
Member

Choose a reason for hiding this comment

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

should this also use the instance variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the only places I used the instance variable was places where if it was never started, there's nothing to stop/reset

end

protected def retry_start_session(e)
if Time.utc <= @retry_limit
sleep(0.1)
@@ -26,13 +28,4 @@ abstract class LuckyFlow::Driver
raise e
end
end

private def prepare_screenshot_directory
FileUtils.rm_rf(screenshot_directory)
FileUtils.mkdir_p(screenshot_directory)
end

private def screenshot_directory
LuckyFlow.settings.screenshot_directory
end
end