Git Product home page Git Product logo

ruby_lib's Introduction

appium_lib

Gem Version

Downloads

Helper methods for writing cross platform (iOS, Android) tests in Ruby using Appium. Note that user waits should not exceed 120 seconds if they're going to run on Sauce Labs.

Recommend to use ruby_lib_core, which works as a Ruby client for Appium. ruby_lib wraps the core library with some additional helpful methods, but some of wrapped methods may have unexpected complexity. Ordinary, ruby_lib worked with class driver, $driver, mainly. We can avoid the class driver with current ruby_lib, but if you'd like to implement your test cases based on instance driver, @driver, you can consider using ruby_lib_core first.

Setup

Requirement

Ruby Lib and Appium

  • Ruby library version over 12.0.0 is based on Selenium v4
  • Ruby library version over 9.8.0 requires Appium over 1.8
  • Ruby library version under 9.7.5 can work with Appium under 1.7

Start appium server

Appium 2

$ npm install --location=global appium
$ appium driver install xcuitest  # proper driver name to install
$ appium server

Note Please set server_url properly like the below since the appium 2 changed the default WebDriver URL to without /wd/hub to follow W3C.

 opts = {
   caps: {
     automationName: 'xcuitest'
     platformName: 'ios',
     app: '/path/to/MyiOS.app'
   },
   appium_lib: {
     server_url: 'http://127.0.0.1:4723'
   }
 }
 appium_driver = Appium::Driver.new(opts)
 appium_driver.start_driver

Or please start the appium server with appium server --base-path=/wd/hub

Appium 1

$ npm install -g appium
$ appium

Install / Upgrade

gem install appium_lib
  • SAUCE_USERNAME Sauce username
  • SAUCE_ACCESS_KEY Sauce API key
  • SAUCE_ENDPOINT Alternative Sauce Appium Server endpoint (only use if directed)

(Note: If these variables are set, all tests will use Sauce Labs unless over-ridden in configuration.)

Documentation

Related libraries

  • ruby_lib_core: Bridged commands, WebDriver dependencies
    • We add new endpoints for Appium in the core library, and ruby_lib call the methods.
  • ruby_console: Appium Ruby Console
  • appium_capybara: Gem enabling appium support in capybara

Load Pry

Pry.config.pager = false is set if you have no .pryrc files and Pry is defined.

Run tests in parallel

This repository has examples for running tests in parallel. Read ios_tests to see them.

Contribute

How to add new commands for driver

How to add new helpful methods

  • Add the new methods in this library

ruby_lib's People

Contributors

bayandin avatar bootstraponline avatar daipresents avatar dependabot-preview[bot] avatar dependabot[bot] avatar dpgraham avatar dylanlacey avatar edgpaez avatar emen avatar janijegoroff avatar jcavar avatar jlipps avatar jmaeso avatar jonahss avatar jskswamy avatar kazucocoa avatar kieferrm avatar misttar avatar montdidier avatar ndmanvar avatar norekinc avatar randoum avatar sbonebrake avatar sergey-plevako-badoo avatar sofaking avatar srinivasantarget avatar titusfortner avatar tommeier avatar waynema avatar whoward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby_lib's Issues

bad appended to session_id

$driver.session_id
=> "efac972c-941a-499c-803c-d7d008749bad"

Why is selenium webdriver appending bad to the session_id?

Search by text iOS

execute_script %(UIATarget.localTarget().frontMostApp().mainWindow().elements().firstWithPredicate("name contains[c] 'some text'").name())

Use APK_PATH

Android should not have to set APP_PATH. APK_PATH should be used for Android and APP_PATH for iOS.

Appium textfield tag includes secure

Appium now returns secure when searching for textfield tag. This is a great change however ruby_lib has to be updated because the existing search of (textfield + secure) will now be transformed into (textfield + secure + secure).

Use XPath Index

Appium supports XPath index now so we don't have to get all elements from the server to find a particular index on the client.

Methods to update

Add find_name

def find_name name
  find_element :name, 'name'
end

find only works on main window

find is unable to locate elements that aren't attached to the main window.

find should search webview first and skip it if it doesn't exist.

UIAWebView

  • $driver.window_handles see hybrid apps wiki
    • execute_script 'au.mainApp.windows().length' window 0 is the main window. window 1 is another window. webviews are usually .windows()[windowIndex].scrollViews()[0].webViews()[0]
  • find_element :name, 'name' will search in webviews so that should be called if the regular name method returns no results.
  • find_elements :tag_name, :text also searches into webviews.
  • text is empty on webview text. name and value are filled in.
  • xpath "text[contains(@name, 'legal')]" works.
execute_script 'UIATarget.localTarget().frontMostApp().windows()[0].scrollViews()[0].webViews().length'

Optional main method generation

It's helpful for a console to have global methods so there's no driver prefix required. In production though, it'd be nice to use the driver object directly and have zero global methods.

if exists method

Add a helper method to easily check if an element exists or not. It should return true or false.

alert_accept fails on selendroid

> alert_accept
post /element
{
    :using => "xpath",
    :value => "//button[last()]"
}
post /ele

Workaround: find_element(:link_text, 'Yes').click

Selendroid requires a new mode.

Improve Android vs iOS selection

Setting APP_PATH once isn't a great user experience. There should be a way to dynamically switch the app path to run iOS and Android within the same run.

Organize OS specific code

Individual methods shouldn't require if $os == :android or if $os == :ios. OS specific code should be located in a dedicated file.

Support selendroid

Selendroid launch is supported however that's not very useful if commands can't be issued.

page and source on selendroid errors

> page
get /source
JSON::NestingError: nesting of 20 is too deep
from /lib/ruby/1.9.1/json/common.rb:148:in `parse'
> source
get /source
JSON::NestingError: nesting of 20 is too deep

Add txt method

txt method to search all text.

find_elements :xpath, "//*[contains(@text, 'sign in')]"

find_eles_attr android

bc1cdb1 relies on classNameMatches which doesn't work that well. Instead multiple exact class searches should be performed.

This issue is specific to Android.

Name methods

name( element_name ) find_element :name, element_name
names( element_name )``find_elements :name, element_name

fast_duration now invalid

duration value must be greater than or equal to 0.5 or less than 60

mobile :swipe, startX: 0.85, endX: 0.3, startY: 0.85, endY: 0.3, duration: 0.5

Change start/end to get different results.

Automated testing

Automated testing should ensure the commands work. It'll be possible to automate the tests once Sauce Labs launches Android support on the hosted service.

Find by resource id using AOT discovery of strings.xml

strings.xml can be recreated from an APK and used to search for strings. This means tests won't fail when text changes as is currently the case with uiautomator.

  • Tasks
    • Java jar that generates strings.xml from an APK
    • Parse jar output into Ruby
    • Enable client side mapping of key pairs to string text.
# populate the resource method.
load_resources_from_apk 'path/to/apk'

# find element using the resource id 'sign in'
find_element :name, r('sign in')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.