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

add some methods for w3c #37

Merged
merged 5 commits into from
Dec 25, 2017
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
16 changes: 16 additions & 0 deletions lib/appium_lib_core/common/base/w3c_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ def action(async = false)
end
alias actions action

# override
def page_source
# For W3C
# execute_script('var source = document.documentElement.outerHTML;' \
# 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \
# 'return source;')
execute :get_page_source
end

# override
def element_attribute(element, name)
# For W3C
# execute_atom :getAttribute, element, name
execute :get_element_attribute, id: element.ref, name: name
end

# override
def find_element_by(how, what, parent = nil)
how, what = convert_locators(how, what)
Expand Down
12 changes: 8 additions & 4 deletions lib/appium_lib_core/common/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,31 @@ module Commands
COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).merge(COMMAND_IOS)
.merge(COMMAND_NO_ARG).freeze

COMMANDS_EXTEND_MJSONWP = COMMANDS.merge(
COMMANDS_EXTEND_MJSONWP = COMMANDS.merge(::Appium::Core::Base::Commands::OSS).merge(
{
# W3C already has.
take_element_screenshot: [:get, 'session/:session_id/element/:id/screenshot'.freeze]
}
).merge(::Appium::Core::Base::Commands::OSS).freeze
COMMANDS_EXTEND_W3C = COMMANDS.merge(
).freeze
COMMANDS_EXTEND_W3C = COMMANDS.merge(::Appium::Core::Base::Commands::W3C).merge(
{
# ::Appium::Core::Base::Commands::OSS has the following commands and Appium also use them.
# Delegated to ::Appium::Core::Base::Commands::OSS commands
status: [:get, 'status'.freeze],
is_element_displayed: [:get, 'session/:session_id/element/:id/displayed'.freeze],

# FIXME: remove after apply https://github.com/SeleniumHQ/selenium/pull/5249
# The fix will be included in selenium-3.8.2
get_page_source: [:get, 'session/:session_id/source'.freeze],

# For IME
ime_get_available_engines: [:get, 'session/:session_id/ime/available_engines'.freeze],
ime_get_active_engine: [:get, 'session/:session_id/ime/active_engine'.freeze],
ime_is_activated: [:get, 'session/:session_id/ime/activated'.freeze],
ime_deactivate: [:post, 'session/:session_id/ime/deactivate'.freeze],
ime_activate_engine: [:post, 'session/:session_id/ime/activate'.freeze]
}
).merge(::Appium::Core::Base::Commands::W3C).freeze
).freeze
end
end
end
14 changes: 10 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

ROOT_REPORT_PATH = "#{Dir.pwd}/test/report/".freeze
ROOT_REPORT_PATH = "#{Dir.pwd}/test/report".freeze
START_AT = Time.now.strftime('%Y-%m-%d-%H%M%S').freeze

Dir.mkdir(ROOT_REPORT_PATH) unless Dir.exist? ROOT_REPORT_PATH
FileUtils.mkdir_p("#{ROOT_REPORT_PATH}/#{START_AT}") unless FileTest.exist? "#{ROOT_REPORT_PATH}/#{START_AT}"

class AppiumLibCoreTest
module Function
class TestCase < Minitest::Test
def save_reports(driver)
return if passed?

path = "#{ROOT_REPORT_PATH}#{self.class.name.gsub('::', '_')}-#{name}-error"
File.write "#{path}.xml", driver.page_source
driver.save_screenshot "#{path}.png"
# Save failed view's screenshot and source
base_path = "#{ROOT_REPORT_PATH}/#{START_AT}/#{self.class.name.gsub('::', '_')}"
FileUtils.mkdir_p(base_path) unless FileTest.exist? base_path

File.write "#{base_path}/#{name}-failed.xml", driver.page_source
driver.save_screenshot "#{base_path}/#{name}-failed.png"
end
end
end
Expand Down