-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add failed driver guard to FileManager Appium API #709
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dd7a6ae
Prevent file operations on a failed Appium driver
e0b0951
Require new file
741231c
Add unit test
b6c8a14
Guard against Appium errors
d3773ed
Fail driver on server error
9f93d2c
changelog
54450d6
Return the file read rather than a boolean
3d73022
fix tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Maze | ||
module Api | ||
module Appium | ||
# Base class for all Appium managers. | ||
class Manager | ||
def initialize | ||
@driver = Maze.driver | ||
end | ||
|
||
def failed_driver? | ||
@driver.failed? | ||
end | ||
|
||
def fail_driver | ||
@driver.fail_driver | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require 'selenium-webdriver' | ||
|
||
require_relative '../../test_helper' | ||
require_relative '../../../lib/maze' | ||
require_relative '../../../lib/maze/api/appium/file_manager' | ||
|
||
module Maze | ||
module Api | ||
module Appium | ||
class FileManagerTest < Test::Unit::TestCase | ||
|
||
def setup() | ||
$logger = mock('logger') | ||
@mock_driver = mock('driver') | ||
Maze.driver = @mock_driver | ||
@manager = Maze::Api::Appium::FileManager.new | ||
end | ||
|
||
def test_write_app_file_failed_driver | ||
@mock_driver.expects(:failed?).returns(true) | ||
$logger.expects(:error).with("Cannot write file to device - Appium driver failed.") | ||
|
||
@manager.write_app_file('contents', 'filename.json') | ||
end | ||
|
||
def test_write_app_file_success | ||
@mock_driver.expects(:failed?).returns(false) | ||
@mock_driver.expects(:app_id).returns('app1') | ||
Maze::Helper.expects(:get_current_platform).returns('ios') | ||
$logger.expects(:trace).with("Pushing file to '@app1/Documents/filename.json' with contents: contents") | ||
@mock_driver.expects(:push_file).with('@app1/Documents/filename.json', 'contents') | ||
|
||
assert_true(@manager.write_app_file('contents', 'filename.json')) | ||
end | ||
|
||
def test_write_app_file_failure | ||
@mock_driver.expects(:failed?).returns(false) | ||
@mock_driver.expects(:app_id).returns('app1') | ||
Maze::Helper.expects(:get_current_platform).returns('ios') | ||
$logger.expects(:trace).with("Pushing file to '@app1/Documents/filename.json' with contents: contents") | ||
@mock_driver.expects(:push_file).with('@app1/Documents/filename.json', 'contents').raises(Selenium::WebDriver::Error::UnknownError, 'error') | ||
$logger.expects(:error).with("Error writing file to device: error") | ||
|
||
assert_false(@manager.write_app_file('contents', 'filename.json')) | ||
end | ||
|
||
def test_read_app_file_failed_driver | ||
@mock_driver.expects(:failed?).returns(true) | ||
$logger.expects(:error).with("Cannot read file from device - Appium driver failed.") | ||
|
||
@manager.read_app_file('filename.json') | ||
end | ||
|
||
def test_read_app_file_success | ||
@mock_driver.expects(:failed?).returns(false) | ||
@mock_driver.expects(:app_id).returns('app1') | ||
Maze::Helper.expects(:get_current_platform).returns('ios') | ||
$logger.expects(:trace).with("Attempting to read file from '@app1/Documents/filename.json'") | ||
@mock_driver.expects(:pull_file).with('@app1/Documents/filename.json') | ||
|
||
assert_true(@manager.read_app_file('filename.json')) | ||
end | ||
|
||
def test_read_app_file_failure | ||
@mock_driver.expects(:failed?).returns(false) | ||
@mock_driver.expects(:app_id).returns('app1') | ||
Maze::Helper.expects(:get_current_platform).returns('ios') | ||
$logger.expects(:trace).with("Attempting to read file from '@app1/Documents/filename.json'") | ||
@mock_driver.expects(:pull_file).with('@app1/Documents/filename.json').raises(Selenium::WebDriver::Error::UnknownError, 'error') | ||
|
||
$logger.expects(:error).with("Error reading file from device: error") | ||
|
||
assert_false(@manager.read_app_file('filename.json')) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is attempting to retrieve a file this should be the file pulled rather than the success metric?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gosh, you're absolutely right - I'd assumed the file is written straight to file, but it is returned in memory by the method call. Good spot.