Skip to content

Commit

Permalink
Add azure pipeline to run tests on windows (#169)
Browse files Browse the repository at this point in the history
* add yml

* convert a path to windows style

* add appium_lib_session

* tweak displayname

* add a badge for azure

* fix rubocop

* update changelog, add a URL for the platform
  • Loading branch information
KazuCocoa authored Nov 24, 2018
1 parent 44a0fff commit 3e21f36
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Read `release_notes.md` for commit level details.

## [Unreleased]
### Enhancements
- Add `::Appium::Core::Base.platform` to call `::Selenium::WebDriver::Platform`
- Can identify platform using `::Appium::Core::Base.platform.windows?` for example

### Bug fixes

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Gem Version](https://badge.fury.io/rb/appium_lib_core.svg)](https://badge.fury.io/rb/appium_lib_core)


[![Build Status](https://travis-ci.org/appium/ruby_lib_core.svg?branch=master)](https://travis-ci.org/appium/ruby_lib_core)

| Travis, Ubuntu | Azure, Windows |
|:---:|:---:|
|[![Build Status](https://travis-ci.org/appium/ruby_lib_core.svg?branch=master)](https://travis-ci.org/appium/ruby_lib_core)|[![Build Status](https://dev.azure.com/kazucocoa/ruby_lib_core_windows/_apis/build/status/appium.ruby_lib_core)](https://dev.azure.com/kazucocoa/ruby_lib_core_windows/_build/latest?definitionId=4)|

This library is a Ruby client for Appium. The gem is available via [appium_lib_core](https://rubygems.org/gems/appium_lib_core).

Expand Down
23 changes: 23 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Ruby
# Package your Ruby project.
# Add steps that install rails, analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/ruby
pool:
vmImage: 'vs2017-win2016'

steps:
- task: UseRubyVersion@0
inputs:
versionSpec: '>= 2.5'

- script: gem install bundler
displayName: 'Install bundler'

- script: bundle install --retry=3 --jobs=4
displayName: 'Call bundle install'

- script: gem uninstall --force eventmachine && gem install eventmachine --platform ruby
displayName: 'bundle re-install eventmachine for Windows because of Windows environment issue'

- script: bundle exec parallel_test test/unit/ -n 4
displayName: 'bundle exec parallel_test test/unit/ -n 4'
1 change: 1 addition & 0 deletions lib/appium_lib_core/common/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
require_relative 'base/http_default'
require_relative 'base/search_context'
require_relative 'base/command'
require_relative 'base/platform'
18 changes: 18 additions & 0 deletions lib/appium_lib_core/common/base/platform.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Appium
module Core
class Base
# Return ::Selenium::WebDriver::Platform module methods
# Read https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/platform.rb
#
# @return [::Selenium::WebDriver::Platform]
#
# @example
#
# ::Appium::Core::Base.platform.windows? #=> `true` or `false`
#
def self.platform
::Selenium::WebDriver::Platform
end
end
end
end
8 changes: 7 additions & 1 deletion lib/appium_lib_core/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def set_appium_lib_specific_values(appium_lib_opts)

# bump current session id into a particular file
@export_session = appium_lib_opts.fetch :export_session, false
@export_session_path = appium_lib_opts.fetch :export_session_path, '/tmp/appium_lib_session'
@export_session_path = appium_lib_opts.fetch :export_session_path, default_tmp_appium_lib_session

@port = appium_lib_opts.fetch :port, DEFAULT_APPIUM_PORT

Expand Down Expand Up @@ -487,8 +487,14 @@ def set_automation_name_if_nil
end
end

# @private
def default_tmp_appium_lib_session
::Appium::Core::Base.platform.windows? ? 'C:\\\\Windows\\Temp\\appium_lib_session' : '/tmp/appium_lib_session'
end

# @private
def write_session_id(session_id, export_path = '/tmp/appium_lib_session')
export_path.tr!('/', '\\') if ::Appium::Core::Base.platform.windows?
File.write(export_path, session_id)
rescue IOError => e
::Appium::Logger.warn e
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_take_element_screenshot
end

def test_viewport_screenshot
file = @driver.save_viewport_screenshot './android_viewport_screenshot_test.png'
file = @driver.save_viewport_screenshot 'android_viewport_screenshot_test.png'

assert File.exist?(file.path)

Expand Down
12 changes: 6 additions & 6 deletions test/functional/android/android/image_comparison_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def teardown
end

def test_image_comparison_match_result
image1 = File.read './test/functional/data/test_normal.png'
image2 = File.read './test/functional/data/test_has_blue.png'
image1 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_normal.png')
image2 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_has_blue.png')

match_result = @driver.match_images_features first_image: image1, second_image: image2
assert_equal %w(points1 rect1 points2 rect2 totalCount count), match_result.keys
Expand All @@ -31,8 +31,8 @@ def test_image_comparison_match_result
end

def test_image_comparison_find_result
image1 = File.read './test/functional/data/test_normal.png'
image2 = File.read './test/functional/data/test_has_blue.png'
image1 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_normal.png')
image2 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_has_blue.png')

find_result = @driver.find_image_occurrence full_image: image1, partial_image: image2
assert_equal({ 'rect' => { 'x' => 0, 'y' => 0, 'width' => 750, 'height' => 1334 } }, find_result)
Expand All @@ -46,8 +46,8 @@ def test_image_comparison_find_result
end

def test_image_comparison_get_images_result
image1 = File.read './test/functional/data/test_normal.png'
image2 = File.read './test/functional/data/test_has_blue.png'
image1 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_normal.png')
image2 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_has_blue.png')

get_images_result = @driver.get_images_similarity first_image: image1, second_image: image2
assert_equal({ 'score' => 0.891606867313385 }, get_images_result)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_platform_version
end

def test_screenshot
file = @@core.screenshot './android_test.png'
file = @@core.screenshot 'android_test.png'

assert File.exist?(file.path)

Expand Down
2 changes: 1 addition & 1 deletion test/functional/ios/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_platform_version
end

def test_screenshot
file = @@core.screenshot './ios_test.png'
file = @@core.screenshot 'ios_test.png'

assert File.exist?(file.path)

Expand Down
14 changes: 8 additions & 6 deletions test/functional/ios/ios/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_image_element
fixImageTemplateSize: true,
autoUpdateImageElementPosition: true })

e = @@driver.find_element_by_image './test/functional/data/test_button_image_ios.png'
e = @@driver.find_element_by_image AppiumLibCoreTest.path_of('test/functional/data/test_button_image_ios.png')

assert e.inspect
assert e.hash
Expand All @@ -40,7 +40,7 @@ def test_image_elements
@@driver.update_settings({ fixImageTemplateSize: true,
autoUpdateImageElementPosition: true })

e = @@driver.find_elements_by_image './test/functional/data/test_arrow_multiple_ios.png'
e = @@driver.find_elements_by_image AppiumLibCoreTest.path_of('test/functional/data/test_arrow_multiple_ios.png')

assert e[0].inspect
assert e[0].hash
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_within_context
end

def test_viewport_screenshot
file = @@driver.save_viewport_screenshot './ios_viewport_screenshot_test.png'
file = @@driver.save_viewport_screenshot AppiumLibCoreTest.path_of('ios_viewport_screenshot_test.png')

assert File.exist?(file.path)

Expand All @@ -282,7 +282,7 @@ def test_viewport_screenshot

# Requires --relaxed-security server flag
def test_start_performance_record_and_stop
file_path = './test_start_performance_record_and_stop.zip'
file_path = AppiumLibCoreTest.path_of('test_start_performance_record_and_stop.zip')
File.delete file_path if File.exist? file_path

@@driver.start_performance_record(timeout: 300_000, profile_name: 'Time Profiler')
Expand All @@ -293,8 +293,10 @@ def test_start_performance_record_and_stop
sleep 1

# Get .zip file
file = @@driver.get_performance_record(save_file_path: './test_start_performance_record_and_stop',
profile_name: 'Time Profiler')
file = @@driver.get_performance_record(
save_file_path: AppiumLibCoreTest.path_of('test_start_performance_record_and_stop'),
profile_name: 'Time Profiler'
)

assert File.exist?(file.path)
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def self.required_appium_version?(core_driver, required)
v[0] >= required.to_s
end

def self.path_of(path)
path_dup = path.dup
path_dup.tr!('/', '\\') if ::Appium::Core::Base.platform.windows?
path_dup
end

class Caps
def self.ios
new.ios
Expand Down
2 changes: 1 addition & 1 deletion test/unit/script/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def setup
end

def test_get_all_command_path
@c.get_all_command_path './test/unit/script/test_routes.js'
@c.get_all_command_path AppiumLibCoreTest.path_of('test/unit/script/test_routes.js')
assert_equal 143, @c.spec_commands.length
assert_equal ['status', [:get]], @c.spec_commands.first
assert_equal %i(get post delete), @c.spec_commands['session/:session_id/cookie']
Expand Down

0 comments on commit 3e21f36

Please sign in to comment.