0.0.42 • Published 2 years ago

@stdspa/appium-linux-driver v0.0.42

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Appium Linux Driver

NPM version Downloads

Release

This is Appium driver for automating linux applications using Linux's AtSpi2 framework. The driver operates in scope of W3C WebDriver protocol with several custom extensions to cover operating-system specific scenarios. Yaoshi technical consultant sponses this project and contributed the underlying linux automation framework. The automation framework is distributed as debian installer.

Requirements

Running a linux automated test requires to install the following three components:

Install and run forked appium

git clone https://github.com/fantonglang/appium
cd appium
yarn install
node ./

The linux driver is referenced as dependency in appium, so no need to install it explicitly.

Yaoshi automation framework

It has been tested on Ubuntu 20.04/18.04 LTS. Here is the download link for installer. Install it with the following instructions:

sudo apt-get install gdebi-core
sudo gdebi stdspalinux-ubuntu_18_04.deb

We have plan to publish the installer for deepin, and also docker image for test automation in the cloud native way.

Any requests, such as support another linux distribution; extend user interaction gestures; build a commercial product with better performance and more capabilities, please always feel free to contact me:

NameEmailWechat
Fan Tongzhao_sun@hotmail.comS597653509

UI Inspector

A custom UI inspector is provided for users. It can:

  • List all the running windows with their names. Window name is used as parameter to switch between windows.
  • Show XML UI hierachy of a window, and validate XPath. The user experience is inspired by Appium Inspector.

Capabilities

Capability NameDescription
platformNameShould be set to linux
automationNameMust always be set to atspi2. Values of automationName are compared case-insensitively.
appium:appNameThe path of the application to automate, for example /bin/yelp, or short-hand yelp because /bin is in the path environment variable. This is a required capability. If the given application is not installed then an error will be thrown on session startup. If the application is already running then it will be killed and restarted.

Element Attributes

Linux driver supports the following element attributes:

NameDescriptionExample
rectCoordinates of bounding element rectangle{x: 1, y: 2, width: 100, height: 200}
sizeSize of bounding element rectangle{width: 100, height: 200}
nameElement's name value. Could be empty'my name'
textElement's text value. Could be empty'my text'

More attributes could be visited via the WebElement.get_property(name: str) API. Here is an example source of UI element: <tree-item name="package.json" pid="2575" toolkit="Chromium__1.0" states="[ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE]" rect="[48,746,368,22]" text-align="left" explicit-name="true" class="monaco-list-row focused selected" display="block" posinset="9" level="2" xml-roles="treeitem" tag="div" id="list_id_2_37" setsize="11" />.

To get the states of an element, use the property states. e.g. to judge if the element is selected or not, write:

if contains(el.get_property('states'), 'SELECTED'):
    print('element is selected')

Element attribute values could be retrieved from the XML page source. UI inspector can also visualize element's attributes. All attributes which present in the XML page source could be used for elements location, including but not limited to the attributes in the table.

Element Location

Linux driver supports the following location strategies:

NameDescriptionExample
nameThe name strategy uses element's name attribute for lookup.driver.find_element(AppiumBy.NAME, 'Find')
xpathFor elements lookup Xpath strategy the driver uses the same XML tree that is generated by page source API. Only Xpath 1.0 is supported (based on xpath.js).driver.find_element(AppiumBy.XPATH, "//document-web")

Check the integration tests for more examples on different location strategies usage.

Other Appium Standard APIs (Python webdriver client)

Element: Set Text / Set Value

Enter text or value in the input element

Arguments

NameTypeRequiredDescriptionExample
keysstringyesThe string value to enter in the input element.'example text'

Example

el.set_text('example text')

el.set_value(12)

Element: Click

Perform click gesture on an element

Arguments

No Arguments

Example

el.click()

Press Key Code

Perform press key code gesture. Key code like 'F1', 'F2', 'Delete', 'Return', 'Up', 'Down', 'Left', 'Right'. Combination key can be performed by combining the metastate like 'CONTROL', 'ALT', 'SHIFT'.

The press key code gesture can also simulate press alphabat keys like 'a', 'b', 'c', ..., 'z'. But then the keycode field should use negative value. e.g. the ascii code for 'a' is 97, then the keycode value is -97.

Arguments

NameTypeRequiredDescriptionExample
keycodeintyesRefer to keycode enumeration65535(DELETE), -97(a)
metastateintnoRefer to metastate enumeration0(None), 64(META), 8(ALT),4(CONTROL), 1(SHIFT)

Example

driver.press_keycode(65473, 8) # alt + f4
driver.press_keycode(-118, 4) # control + v

Keycode Enumeration

namekeycodenamekeycode
NOT_A_KEY9999a-97
BACKSPACE65288b-98
DELETE65535c-99
RETURN65293d-100
TAB65289e-101
ESCAPE65307f-102
UP65362g-103
DOWN65364h-104
RIGHT65363i-105
LEFT65361j-106
HOME65360k-107
END65367l-108
PAGEUP65365m-109
PAGEDOWN65366n-110
F165470o-111
F265471p-112
F365472q-113
F465473r-114
F565474s-115
F665475t-116
F765476u-117
F865477v-118
F965478w-119
F1065479x-120
F1165480y-121
F1265481z-122
F1365482
F1465483
F1565484
F1665485
F1765486
F1865487
F1965488
F2065489
F2165490
F2265491
F2365492
F2465493
META65515
LMETA65515
RMETA65516
ALT65513
LALT65513
RALT65514
CONTROL65507
LCONTROL65507
RCONTROL65508
SHIFT65505
LSHIFT65505
RSHIFT65506
CAPSLOCK65510
SPACE32
INSERT65379
PRINTSCREEN65377
MENU9999
NUMPAD_065456
NUMPAD_165457
NUMPAD_265458
NUMPAD_365459
NUMPAD_465460
NUMPAD_565461
NUMPAD_665462
NUMPAD_765463
NUMPAD_865464
NUMPAD_965465
NUMPAD_LOCK65407
NUMPAD_DECIMAL65454
NUMPAD_PLUS78
NUMPAD_MINUS74
NUMPAD_MUL55
NUMPAD_DIV98
NUMPAD_CLEAR9999
NUMPAD_ENTER96
NUMPAD_EQUAL61
AUDIO_VOLUME_MUTE269025042
AUDIO_VOLUME_DOWN269025041
AUDIO_VOLUME_UP269025043
AUDIO_PLAY269025044
AUDIO_STOP269025045
AUDIO_PAUSE269025073
AUDIO_PREV269025046
AUDIO_NEXT269025047
AUDIO_REWIND269025086
AUDIO_FORWARD269025175
AUDIO_REPEAT269025176
AUDIO_RANDOM269025177
LIGHTS_MON_UP269025026
LIGHTS_MON_DOWN269025027
LIGHTS_KBD_TOGGLE269025028
LIGHTS_KBD_UP269025029
LIGHTS_KBD_DOWN269025030

Metastate Enumeration

namemetastate
None0
META64
ALT8
CONTROL4
SHIFT1

Long Press Key Code

The same with press key code, except for pressing the key for a longer time (0.5s)

Element: Get Property / Attribute

Get the element's property value.

Arguments

NameTypeRequiredDescriptionExample
namestringyesthe property name'states'

Example

name = el.get_property('name') # get the name property value
name = el.get_attribute('name') # get the name property value, equivalent to get_property

Element: Clear

Clear the (input) element's text

Arguments

No arguments

Example

el.clear()

Element: Screenshot

Take screenshot of the element

Arguments

NameTypeRequiredDescriptionExample
filenamestringyesthe path to save the screenshot'.pics/a.png'

Example

el.screenshot('.pics/a.png')

Screenshot

Take screenshot of the window

Arguments

NameTypeRequiredDescriptionExample
filenamestringyesthe path to save the screenshot'.pics/a.png'

Example

driver.get_screenshot_as_file('.pics/a.png')

Platform-Specific Extensions

Beside of standard W3C APIs the driver provides the following custom command extensions to execute platform specific scenarios:

linux: getDisplaySize

Get the width and height of the display

Arguments

No arguments

Example

size = driver.execute_script('linux: getDisplaySize')
print(size) # outputs: {'width': 1440, 'height': 900}

linux: mouseMove

Move the mouse to a given absolute coordinates.

Arguments

NameTypeRequiredDescriptionExample
xintyesthe x coordinate100
yintyesthe y coordinate100

Example

driver.execute_script('linux: mouseMove', {"x": 100, "y": 100})

linux: mouseSwipe

Mouse down at (sx, sy), and move to (ex, ey), and then mouse up.

Effectively swipe from (sx, sy) to (ex, ey)

Arguments

NameTypeRequiredDescriptionExample
sxintyesswipe from x coordinate500
syintyesswipe from y coordinate100
exintyesswipe to x coordinate500
eyintyesswipe to y coordinate700

Example

driver.execute_script('linux: mouseSwipe', {"sx": 500, "sy": 100, "ex": 500, "ey": 700})

linux: rightClick

Right click on a given absolute coordinates.

Arguments

NameTypeRequiredDescriptionExample
xintyesthe x coordinate100
yintyesthe y coordinate100

Example

driver.execute_script('linux: rightClick', {"x": 100, "y": 100})

linux: doubleClick

Double click on a given absolute coordinates.

Arguments

NameTypeRequiredDescriptionExample
xintyesthe x coordinate100
yintyesthe y coordinate100

Example

driver.execute_script('linux: doubleClick', {"x": 100, "y": 100})

linux: mouseScroll

Simulate mouse scroll horizontally and vertically

Arguments

NameTypeRequiredDescriptionExample
moveLeftStepsintnohow much scrolls left, when the value is negative, scrolls right, when the value is 0, doesn't scroll horizontally
moveUpStepsintnohow much scrolls up, when the value is negative, scrolls down, when the value is 0, doesn't scroll vertically.

Example

driver.execute_script('linux: mouseScroll', {"moveLeftSteps": 0, "moveUpSteps": -1}) # scrolls down

linux: copy

Copy a given string to the system clipboard

Arguments

NameTypeRequiredDescriptionExample
strstringyesthe string to be copied'sample copy text'

Example

driver.execute_script('linux: copy', {"str": 'sample copy text'})

linux: getClipboard

Get the clipboard content

Arguments

No Arguments

Example

content = driver.execute_script('linux: getClipboard')

Application Under Test Concept

The Linux driver has the concept of Application Under Test. This is the app, whose path has been passed as appName capability. If this application is unexpectedly terminated during test session execution then an exception is going to be thrown upon any following session command invocation. In such case the driver assumes the application under test is crashed and it is impossible to proceed. Also, the Application Under Test is going to be terminated when the testing session quits.

Examples

# Python3 + PyTest
import pytest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
@pytest.fixture()
def driver():
    drv = webdriver.Remote('http://localhost:4723/wd/hub', {
        # automationName capability presence is mandatory for this Linux Driver to be selected
        'automationName': 'atspi2',
        'platformName': 'linux',
        'bundleId': 'yelp',
    })
    yield drv
    drv.quit()
def test_edit_text(driver):
    find_el = driver.find_element(by=AppiumBy.NAME, value='Find')
    find_el.click()
    edit_field = driver.find_element(by=AppiumBy.XPATH, value='(//text[@name="Search"])[1]')
    edit_field.send_keys('hello world')
    edit_field = driver.find_element(by=AppiumBy.XPATH, value='(//text[@name="Search"])[1]')
    assert edit_field.text == 'hello world'
    edit_field.clear()
    edit_field = driver.find_element(by=AppiumBy.XPATH, value='(//text[@name="Search"])[1]')
    assert edit_field.text == ''

Parallel Execution

Parallel execution of multiple Linux driver instances is highly discouraged. Only one UI test must be running at the same time.

Development & Testing

This module uses the same development tools as the other Appium drivers.

Check out the source. Then run:

npm install
gulp watch

Execute npm run test to run unit tests and npm run e2e-test to run integration tests.

0.0.41

2 years ago

0.0.42

2 years ago

0.0.40

2 years ago

0.0.39

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.31

2 years ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago