Skip to content
Open
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
55 changes: 39 additions & 16 deletions .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,24 @@ concurrency:
jobs:
# pull_request branch filters apply to the base branch, so skip release PRs here.
ios_test:
name: iOS ${{ matrix.test_targets.name }} (Appium ${{ matrix.appium.version }})
if: github.event_name != 'pull_request' || !startsWith(github.head_ref, 'release-please--')
strategy:
fail-fast: false
matrix:
appium: &appium_versions
- version: 3
xcuitest: xcuitest@12
uiautomator2: uiautomator2@8
espresso: espresso@9
images: images@5
execute_driver: execute-driver@7
- version: 4
xcuitest: xcuitest@13
uiautomator2: uiautomator2@10
espresso: espresso@11
images: images@6
execute_driver: execute-driver@9
test_targets:
- target: test/functional/ios/driver_test.rb,test/functional/ios/patch_test.rb
name: test1
Expand Down Expand Up @@ -95,11 +109,11 @@ jobs:
shutdown_after_job: false

# Start Appium
- run: npm install -g appium
- run: npm install -g appium@${{ matrix.appium.version }}
- run: |
appium driver install xcuitest
appium plugin install images
appium plugin install execute-driver
appium driver install ${{ matrix.appium.xcuitest }}
appium plugin install ${{ matrix.appium.images }}
appium plugin install ${{ matrix.appium.execute_driver }}
nohup appium --use-plugins=images,execute-driver --relaxed-security --log-timestamp --log-no-colors 2>&1 > appium.log &

- run: |
Expand All @@ -117,6 +131,7 @@ jobs:
- run: bundle exec rake test:func:ios TESTS=${{matrix.test_targets.target}}
name: Run tests
env:
APPIUM_VERSION: ${{ matrix.appium.version }}
IGNORE_VERSION_SKIP: true
CI: true
LOCAL_PREBUILT_WDA: ${{ github.workspace }}/wda/${{matrix.test_targets.wdaName}}
Expand All @@ -125,12 +140,17 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@master
with:
name: appium-ios-${{matrix.test_targets.name}}.log
name: appium-${{ matrix.appium.version }}-ios-${{matrix.test_targets.name}}.log
path: |
appium.log
test/report/

ios_test_with_other_deps:
name: iOS with other dependencies (Appium ${{ matrix.appium.version }})
strategy:
fail-fast: false
matrix:
appium: *appium_versions
if: github.event_name != 'pull_request' || !startsWith(github.head_ref, 'release-please--')
runs-on: macos-26

Expand Down Expand Up @@ -171,16 +191,16 @@ jobs:
- run: npm root -g
- name: Install appium and mjpeg-consumer
run: |
npm install -g appium
npm install -g appium@${{ matrix.appium.version }}
npm install -g mjpeg-consumer
- run: |
appium driver install xcuitest
appium plugin install images
appium plugin install execute-driver
appium driver install ${{ matrix.appium.xcuitest }}
appium plugin install ${{ matrix.appium.images }}
appium plugin install ${{ matrix.appium.execute_driver }}
nohup appium --use-plugins=images,execute-driver --relaxed-security --log-timestamp --log-no-colors 2>&1 > appium.log &

- run: |
npx appium driver run xcuitest download-wda-sim --platform=ios --outdir=${{github.workspace}}/wda
appium driver run xcuitest download-wda-sim --platform=ios --outdir=${{github.workspace}}/wda
name: Downloading prebuilt WDA

- name: Set up Ruby
Expand All @@ -201,18 +221,20 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@master
with:
name: appium-ios_test_with_other_deps.log
name: appium-${{ matrix.appium.version }}-ios_test_with_other_deps.log
path: |
appium.log
test/report/

android_test:
name: Android ${{ matrix.test_targets.automation_name }} ${{ matrix.test_targets.name }} (Appium ${{ matrix.appium.version }})
if: github.event_name != 'pull_request' || !startsWith(github.head_ref, 'release-please--')
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
appium: *appium_versions
test_targets:
- target: test/functional/android/driver_test.rb,test/functional/android/patch_test.rb,test/functional/android/android/device_test.rb,test/functional/android/android/search_context_test.rb
automation_name: uiautomator2
Expand Down Expand Up @@ -269,11 +291,11 @@ jobs:
node-version: 'lts/*'

# Start Appium
- run: npm install -g appium
- run: npm install -g appium@${{ matrix.appium.version }}
- run: |
appium driver install ${{matrix.test_targets.automation_name}}
appium plugin install images
appium plugin install execute-driver
appium driver install ${{ matrix.appium[matrix.test_targets.automation_name] }}
appium plugin install ${{ matrix.appium.images }}
appium plugin install ${{ matrix.appium.execute_driver }}
nohup appium --use-plugins=images,execute-driver --relaxed-security --log-timestamp --log-no-colors 2>&1 > appium.log &

- name: Enable KVM group perms
Expand Down Expand Up @@ -324,6 +346,7 @@ jobs:
disable-animations: true
env:
ANDROID_SDK_VERSION: ${{ env.API_LEVEL }}
APPIUM_VERSION: ${{ matrix.appium.version }}
APPIUM_DRIVER: ${{matrix.test_targets.automation_name}}
IGNORE_VERSION_SKIP: true
CI: true
Expand All @@ -332,7 +355,7 @@ jobs:
if: ${{ always() }}
uses: actions/upload-artifact@master
with:
name: appium-android-${{matrix.test_targets.automation_name}}-${{matrix.test_targets.name}}.log
name: appium-${{ matrix.appium.version }}-android-${{matrix.test_targets.automation_name}}-${{matrix.test_targets.name}}.log
path: |
appium.log
test/report/
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ This library wraps [selenium-webdriver](https://github.com/SeleniumHQ/selenium/w

- https://www.rubydoc.info/gems/appium_lib_core
- You can find working API examples in test code, [test/functional](test/functional)
- Appium 2.0
- https://appium.github.io/appium/docs/en/2.0/ (Not completed yet)
- [Migrating to Appium 4](https://appium.io/docs/en/latest/guides/migrating-3-to-4/)

# Migration from v13 to v14

Expand Down Expand Up @@ -58,14 +57,17 @@ $ UNIT_TEST=1 bundle exec rake test:unit
### Functional Tests
Run functional tests which require the Appium server and real device, Simulator/Emulator.

- Start Appium server (Appium 2.0 base)
- Start an Appium 4 server
```bash
$ npm install --location=global appium
$ npm install --location=global appium@4
$ appium driver install xcuitest
$ appium driver install uiautomator2 # etc
$ appium --relaxed-security # To run all tests in local
```

With Appium 4, use the WinCore driver (`appium driver install wincore`) for Windows sessions.
Set `automationName` to `Wincore`. Event timings are available through `driver.logs.events`.

- Conduct tests
```bash
$ bundle install
Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/common/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
require_relative 'device/orientation'

# The following files have selenium-webdriver related stuff.
require_relative 'base/capabilities'
require_relative 'base/bridge'
require_relative 'base/driver'
require_relative 'base/capabilities'
require_relative 'base/http_default'
require_relative 'base/search_context'
require_relative 'base/platform'
33 changes: 18 additions & 15 deletions lib/appium_lib_core/common/base/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Bridge < ::Selenium::WebDriver::Remote::Bridge
# Prefix for extra capability defined by W3C
APPIUM_PREFIX = 'appium:'

STANDARD_CAPABILITY_NAMES = ::Appium::Core::Base::Capabilities::KNOWN.to_h do |key|
[key.to_s, ::Appium::Core::Base::Capabilities.camel_case(key)]
end.freeze

# No 'browserName' means the session is native appium connection
APPIUM_NATIVE_BROWSER_NAME = 'appium'

Expand Down Expand Up @@ -154,6 +158,13 @@ def connection
bidi.ws # steep:ignore
end

# Selenium 4.46 accesses generated BiDi commands through a transport.
if ::Selenium::WebDriver::Remote::Bridge.method_defined?(:transport)
def transport
::Selenium::WebDriver::BiDi::Transport.new(connection) # steep:ignore
end
end

# Override
def quit
super
Expand All @@ -178,7 +189,13 @@ def add_appium_prefix(capabilities)

capabilities.each do |name, value|
capability_name = name.to_s
w3c_name = extension_prefix?(capability_name) ? name : "#{APPIUM_PREFIX}#{capability_name}"
w3c_name = if STANDARD_CAPABILITY_NAMES.key?(capability_name)
STANDARD_CAPABILITY_NAMES.fetch(capability_name)
elsif STANDARD_CAPABILITY_NAMES.value?(capability_name) || capability_name.include?(':')
name
else
"#{APPIUM_PREFIX}#{capability_name}"
end

w3c_capabilities[w3c_name] = value
end
Expand Down Expand Up @@ -216,20 +233,6 @@ def selenium_bridge_accepts_url?
end
end

def camel_case(str_or_sym)
str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase }
end

def extension_prefix?(capability_name)
snake_cased_capability_names = ::Appium::Core::Base::Capabilities::KNOWN.map(&:to_s)
camel_cased_capability_names = snake_cased_capability_names.map { |v| camel_case(v) }

# Check 'EXTENSION_CAPABILITY_PATTERN'
snake_cased_capability_names.include?(capability_name) ||
camel_cased_capability_names.include?(capability_name) ||
capability_name.match(':')
end

def json_create(value)
::Appium::Core::Base::Capabilities.json_create(value)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def set_appium_lib_specific_values(appium_lib_opts)
# @private
def set_appium_device
# https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile
@device = get_cap 'platformName'
@device = get_cap('platformName') || @caps[:platform_name] || @caps['platform_name']
return unless @device

@device = convert_to_symbol(convert_downcase(@device))
Expand Down
2 changes: 1 addition & 1 deletion sig/gems/selenium/remote/capabilities.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Selenium
def []: (untyped key) -> untyped
def []=: (untyped key, untyped value) -> untyped

# Add this:
def self.camel_case: (String | Symbol key) -> String
def self.json_create: (Hash[untyped, untyped] value) -> Capabilities
end
end
Expand Down
8 changes: 4 additions & 4 deletions sig/lib/appium_lib_core/common/base/bridge.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Appium
class Bridge < ::Selenium::WebDriver::Remote::Bridge
include _Bridge

STANDARD_CAPABILITY_NAMES: Hash[String, String]

@browser: untyped

@session_id: untyped
Expand Down Expand Up @@ -102,6 +104,8 @@ module Appium

def connection: () -> untyped

def transport: () -> untyped

def quit: () -> untyped

def close: () -> untyped
Expand All @@ -121,10 +125,6 @@ module Appium

def selenium_bridge_accepts_url?: () -> bool

def camel_case: (untyped str_or_sym) -> untyped

def extension_prefix?: (untyped capability_name) -> untyped

def json_create: (untyped value) -> untyped

public
Expand Down
1 change: 1 addition & 0 deletions test/functional/android/android/device_data_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_save_element_screenshot

def test_viewport_screenshot
skip 'Espresso does not support save_viewport_screenshot' if @@core.automation_name == :espresso
skip_viewport_screenshot_on_appium_3_ci
skip_as_appium_version '1.8.0'

file = @driver.save_viewport_screenshot 'android_viewport_screenshot_test.png'
Expand Down
11 changes: 8 additions & 3 deletions test/functional/android/android/image_comparison_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ def test_image_elements

@driver.rotation = :landscape

el = @driver.find_element :accessibility_id, 'App'
@driver.save_element_screenshot el, 'test/functional/data/test_android_app.png'
screenshot = AppiumLibCoreTest.path_of('test/functional/data/test_android_app.png')
errors = [::Selenium::WebDriver::Error::NoSuchElementError, ::Selenium::WebDriver::Error::StaleElementReferenceError]
el = @driver.wait(ignored: errors) do
element = @driver.find_element :accessibility_id, 'App'
@driver.save_element_screenshot element, screenshot
element
end

image_elements = @driver.find_elements_by_image AppiumLibCoreTest.path_of('test/functional/data/test_android_app.png')
image_elements = @driver.find_elements_by_image screenshot
image_element = image_elements.last

assert image_element.inspect
Expand Down
7 changes: 5 additions & 2 deletions test/functional/android/webdriver/w3c_actions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ def test_tap_scroll
w3c_scroll @driver

if @@core.automation_name == :espresso
el = @driver.find_element(:accessibility_id, 'Lists')
assert_equal 'Lists', el.text
# ListView can recycle a row between the lookup and the text request while scrolling.
errors = [::Selenium::WebDriver::Error::NoSuchElementError, ::Selenium::WebDriver::Error::StaleElementReferenceError]
assert @driver.wait_true(ignored: errors, message: 'Expected the Lists row after scrolling') {
@driver.find_element(:accessibility_id, 'Lists').text == 'Lists'
}
else
@driver.manage.timeouts.implicit_wait = 3
assert_raises ::Selenium::WebDriver::Error::NoSuchElementError do
Expand Down
7 changes: 6 additions & 1 deletion test/functional/ios/ios/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def test_device_time
end

def test_context_related
w3c_scroll @@driver
catalog_back = 'type == "XCUIElementTypeButton" AND name == "BackButton" AND label == "UIKitCatalog"'
@@driver.find_elements(:predicate, catalog_back).first&.click
@@core.wait { @@driver.find_element(:predicate, 'type == "XCUIElementTypeNavigationBar" AND name == "UIKitCatalog"') }
table = @@core.wait { @@driver.find_element(:class_name, 'XCUIElementTypeTable') }
@@driver.execute_script('mobile: scroll', elementId: table.id, name: 'Web View')

e = @@core.wait { @@driver.find_element :accessibility_id, 'Web View' }
e.click
Expand Down Expand Up @@ -233,6 +237,7 @@ def test_within_context
end

def test_viewport_screenshot
skip_viewport_screenshot_on_appium_3_ci
skip_as_appium_version '1.8.0'

file = @@driver.save_viewport_screenshot AppiumLibCoreTest.path_of('ios_viewport_screenshot_test.png')
Expand Down
Loading
Loading