Commit Graph
282 Commits
Author SHA1 Message Date
Christopher Hiller 94b727eaf1 docs: update migration guide to reflect changes to configuration files, arguments, etc.
- add a JS example config file
2021-11-09 11:57:26 -08:00
Christopher Hiller 5b8c448648 docs(appium): update example configuration files 2021-11-09 11:57:26 -08:00
Christopher Hiller d52c36e1ea feat(appium): configuration file and schema support
Summary: This PR adds support for configuration files (e.g., `.appiumrc.json`) and schema definitions.  Command-line options _and_ configuration is now derived from the schema(s), for Appium _and_ its extensions (both plugins and drivers).

## Dependencies
### Development
- Added `through2` for a custom gulp task to convert `appium/lib/appium-config-schema.js` to a JSON file
- Added `json-schema-to-typescript` for converting aforementioned JSON file to a `.d.ts` file (which gets published)

### Production (applies to `appium` only)
- Added `libconfig` for multi-format config file loading, which is a smaller drop-in replacement for `cosmiconfig`
- Added `ajv` for schema support and validation
- Added `ajv-formats` to understand optional value formats (e.g., `ipv4`)
- Added `@sidvind/better-ajv-errors` which provides nice error output on the CLI if the config file is invalid
- Added `@oclif/errors` for better error output on the CLI if _arguments_ are invalid

## New Modules of Note

- `lib/schema.js` consumes `ajv` to create and modify a schema
    - It exposes a handful of public API functions, so that consumers can query the schemas without actually running Appium.
    - The flow is basically this: read the base schema (`appium-config-schema.js`).  When extensions load and have schemas, add those to a pot.  When `finalizeSchema()` is called, throw the base schema into the pot as well, stir, and add to singleton `ajv` instance.  Now we can validate against the stew.
    - The schema for an extension is read and registered via `readExtensionSchema()`
    - Provides a way to get at default (for showing those "non-default" options) and `flattenSchema()` which squishes the finalized schema into a single `Record` key/value object, for use by the CLI.  This may make sense to move into `schema-args.js`
    - Provides access to ajv-and-JSON-schema-defined _formatters_ (which are basically just validation functions).  For example, if we want any string, it's just a `string`.  But if we want the string to match a regexp, that's a formatter.  (e.g., the `hostname` type)
-  lib/config-file.js` consumes `lilconfig` to read config files, validate them against the schema, and provide the result as CLI args
    - Handles conversion between kebab-case and camelCase
    - Contains `formatErrors()` which will be called after validation of a config file fails, which shows _exactly_ where the config file is wrong (usually).
- `lib/cli/schema-args.js` which serves as an adapter between the schema and `argparse`
    - Translates between JSON schema and `argparse`, which...well, I did what I could.  It's pretty close.
    - Wraps the formatters as mentioned above, and provides custom ones.
    - We cannot, unfortunately, wholly use schema validation against CLI args.  The flag names are different, the structure is different, there's no actual _file_ to compare against, and `argparse` does not help.  We _can_ use anything `argparse` natively provides, in addition to `ajv` formatters, and any custom ones (e.g., allowable number ranges).
    - Will likely end up adding more formatters corresponding to various JSON schema features later.  We _may_ be able to use _more_ of Ajv to do this (e.g., reuse its internal validators, if they are public APIs).
- `lib/appium-config-schema.js` which is the root schema. Extensions add to this before it is registered & compiled by `ajv`.
    - The basic shape is that there are three top-level props, `server`, `driver`, and `plugin`.  `server` contains all of the server options as you'd expect, and `driver` and `plugin` will be filled in by extensions.  Each will have properties corresponding to the extension name.  You can find examples in `sample-code` and the test fixtures
    - There's a gulp task that takes this file, rewrites it as JSON, then pipes it into another tool which outputs a `.d.ts` file, nicely described using all of the metadata from the schema.  This will be useful for mainly contributors, extension authors, and consumers of Appium (though not end-users).
- `lib/ext-config-io.js`
    - A new module which handles reading/writing of YAML extension config files only.
    - This class is a singleton.
    - Some logic pulled out of `extension-config.js` and into here
    - Previously, we would read/write this file multiple times (once per subclass of `ExtensionConfig`)
    - This module uses a naive dirty-tracker to persist the extension data automatically.
    - Subclasses of `ExtensionConfig` only have access to their "portion" of the config file; drivers can't see plugins and vice-versa.
    - `DRIVER_TYPE` and `PLUGIN_TYPE` originate here, mainly to avoid a circular dependency

## Modifications

- The single source of truth for the CLI _and_ config file options is the schema, with the caveats that:
    - Command-line arguments (for `appium server` are effectively a flat list, but the schema/config file is not.
    - Extension-specific configuration lives in an extension-type-specific property (`driver` or `plugin`) in the config file
        - Under each (`driver` or `plugin`), each extension may have a configuration section corresponding to the extension name
        - The shape of the extension-specific options _can_ be defined by a schema (and referenced in the `appium.schema` prop of the extension's `package.json`)
        - If an extension does not provide a schema, no validation will occur on any options found here -- TODO needs tests
    - This does _not_ affect _CLI commands_ added by extensions; only options for `server`.
- The `--appium-home` flag is now removed, as we can't find extensions without `APPIUM_HOME`, which means we can't parse arguments (because extensions may have added some).
- `--plugin-args` and `--driver-args` are removed.  These are replaced by individual flags for each argument, defined by the extension in its schema, e.g., `--driver-fake-host=127.0.0.1`
- Extensions can still define argument "constraints" using `argConstraints`, but this is considered deprecated
- `lib/main.js`
    - Now exports a few public APIs
    - split into functions `init` and `main`.  `init` is intended to be run via a consumer, which does what the old `main` did up to starting the server.  This bisection is not perfect, as `init` still does some CLI-related things; it needs to be further broken up.
    - `driverConfig.read()` and `pluginConfig.read()` are now called in `lib/cli/parser.js`.
    - Merges the CLI args, config file args, and defaults, in that order of precedence.
- `lib/grid-register.js`
    - Supports embedded configuration instead of just a path to a JSON file.
    - Not clear to me if `nodeconfig` is a thing we need to keep?
- `lib/extension-config.js`
    - Given `APPIUM_HOME` is where we keep the extensions, this file now defines `APPIUM_HOME`. It is exported from the `appium` package.
    - Add `getSchemaProblems()` method, which will read/validate/register the schema for an extension, if one exists.
    - Added many type annotations
    - `read()` and `write()` now delegate to the singleton `ExtConfigIO` instnace
    - Re-exports `DRIVER_TYPE` and `PLUGIN_TYPE`
- `lib/driver-config.js`
    - **Fix** the case where two drivers attempt to use the same `automationName`.  It appears this was intended, but did not work correctly.  This involved overloading `read()`.
- `lib/plugin-config.js`
    - Literally nothing, which is neat.
- `lib/config.js`
    - Remove unused validations (now occur via schema validation or are extension-specific)
    - Rename `getNonDefaultArgs` to `getNonDefaultServerArgs` to be more specific
    - Rewrote `getNonDefaultServerArgs`, which became much more complicated due to adding a config file and schema defaults to the mix. Flexed my lodash-fu, which is still kind of crappy because I'm better with `lodas/fp`.
- `lib/cli/parser.js`
    - Created a wrapper for `argparse`: class `ArgParser`, which replaces the monkeypatching we were doing here.
    - This class also stores extension-specific args in a namespace.  For example, `--driver-foo-bar=baz` would normally be stored in prop `driverFooBar`, but this moves it into `driver: {foo: {bar: 'baz'}}`, which will be provided to its associated extension
    - `addExtensionsToParser` renamed to `addExtensionCommandsToParser` which is more specific.
    - Removed `getDefaultServerArgs` since those now come from the schema.
    - Removed "shared args" stuff
    - `getParser` is now async, and constructs an `ArgParser`.  By necessity, the extension config YAML is read here (which is still wonky because we have to call `read()` twice; it only actually ends up reading once)
    - `getParser` also _finalizes_ the schema, which means "katamari-up the base schema and all extension schemas, then tell ajv about the result"
- `lib/cli/parser-helpers.js`
    - Allow security features to just be an array (as allowed in schema)
    - TODO: needs test
- `lib/cli/extension.js`
    - Use `APPIUM_HOME` exported from `lib/extension-config` instead of `args.appiumHome`
    - Avoids re-instantiating `ExtensionConfig` subclasses if not needed
- `lib/cli/args.js`
    - Remove all server argument definitions in lieu of schema; leave a few that do not make sense in a config file (like `--config`, which determines the location of the config file!)
    - Server args are now pulled from the schema via a call to `toParserArgs()` with overrides for various validation functions (which are confusingly "types" in `argparse` parlance).  Overrides can probably be removed or relocated to `schema-args`
    - Instantiates the `DriverConfig` and `PluginConfig` instances, which are exported.   These might want to move somewhere else
- Tests
    - Added unit tests for `extension-config`, `grid-register` which were missing
    - Added unit tests for new `schema` and `schema-args` and `config-file` modules
    - Added e2e test for config file handling
    - Other necessary modifications
    - Fix path to `fake-driver` in `driver-e2e-specs`
    - Removed stuff from `parser-specs` which no longer applies

## Other

- Added `scripts/generate-schema-declarations.js` which uses `json-schema-to-typescript` to create `appium-config.d.ts`
- Added config file samples in `.json` and `.yaml` formats
- Added custom gulp task to `appium/gulpfile.js` to generate schema in JSON format, since its "single source of truth" is actually just a big JS object
- Moved `appium` CLI-related tests into `test/cli`
- Added some declarations into `packages/appium/types`; the schema-related one is generated by the script mentioend above, but `types.d.ts` is just some stuff that was not expressible in a docstring
2021-11-09 11:57:26 -08:00
Christopher Hiller 76d147aba1 chore: configure FOSSA
FOSSA was giving us a bunch of warnings about copyleft licenses, but these licenses are only present in our examples.  This configuration file will tell FOSSA to ignore that stuff.

FOSSA recognizes `examples/` as something it should skip, but not `sample-code`.  It's easier to rename the dir than it is to negotiate a PR with FOSSA.  Why they don't allow the config file to just ignore directories is beyond me...
2021-08-18 12:25:13 -07:00
+1 3e98cc98f3 chore: merge master to 2.0 (#15007)
* fix: fix urls in docs (#14910)

* docs: Update generated docs [ci skip] (#14913)

Co-authored-by: runner <runner@Mac-1606273407156.local>

* feat: Add Mac2Driver (#14911)

* docs: Add Mac2Driver documentation (#14914)

* chore: add scripts for doing releases (#14918)

* docs: Update push-file.yml (#14920)

* chore: fix a link in appium.io (#14929)

* fix links

* fix

* docs: Update generated docs [ci skip] (#14930)

Co-authored-by: runner <runner@Mac-1607067954655.local>

* docs: removed deprecated method (#14934)

assert.equal was deprecated — since v9.9.0 - use strictEqual() instead.

* docs: add links to mac2 driver in caps and settings (#14942)

* cods: add links to mac2 driver in caps and settings

* tweak naming

* chore: remove authorize-ios from package (#14946)

* chore: add 1.19.1 in changelog (#14947)

* feat: add --keep-alive-timeout CLI arg to adjust server keepalive and connection timeout

* rename release-candidate.sh to release

* chore: Switch to GitHub CI (#14978)

* docs: changelog for Appium v1.20 (#14985)

* docs: swap out hamcrest.org reference

* docs: fix example comment (#14995)

changed the app name in a comment for the notepad example from AlarmClock to Notepad

* docs: update README with english tutorial version to learn Appium with Python (#14999)

* update README

* Update README.md

* remove duplicated lib/parser.js

* install fakedriver

Co-authored-by: Appium Triager <maintainers@appium.io>
Co-authored-by: runner <runner@Mac-1606273407156.local>
Co-authored-by: Mykola Mokhnach <mokhnach@gmail.com>
Co-authored-by: Dan Graham <dpgraham.85@gmail.com>
Co-authored-by: Ilija Boshkov <ilija.boshkov@gmail.com>
Co-authored-by: runner <runner@Mac-1607067954655.local>
Co-authored-by: roman-olshevskiy <56480723+roman-olshevskiy@users.noreply.github.com>
Co-authored-by: Jonathan Lipps <jlipps@gmail.com>
Co-authored-by: BoldAsLove <john.wojner@gmail.com>
Co-authored-by: Maria Clara dos Santos Bezerra <clarinhab@gmail.com>
2021-01-11 08:04:13 +09:00
Mykola Mokhnach 2b4cc6b8a9 docs: Add comments to java samples (#14838) 2020-10-24 10:42:15 +02:00
Sri Harsha a370d60ec7 docs: fixing Typos (#14635) 2020-08-10 08:30:52 +09:00
Serhat Bolsu a2950b7dc0 feat: robotframework ios and android test suites are added (#14608) 2020-07-29 09:22:30 +09:00
Paulo Gonçalves 1ed1a6f7e3 docs(python): Include free brazilian tutorial (#14533) 2020-07-10 09:20:37 +09:00
Khanh Do 73bdc164b5 docs: Fix wdio config for webdriverio v6 (#14471) 2020-06-22 15:16:21 +09:00
dependabot-preview[bot] 782526c5b1 chore(deps-dev): bump mocha in /sample-code/javascript-wd (#14438)
Bumps [mocha](https://github.com/mochajs/mocha) from 7.2.0 to 8.0.1.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v7.2.0...v8.0.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-06-11 23:29:51 +09:00
dependabot-preview[bot] 1361411cc7 chore(deps-dev): bump mocha in /sample-code/javascript-webdriverio (#14437)
Bumps [mocha](https://github.com/mochajs/mocha) from 7.2.0 to 8.0.1.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v7.2.0...v8.0.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-06-11 23:29:23 +09:00
dependabot-preview[bot] d5119daba9 chore(deps-dev): bump webdriverio in /sample-code/javascript-webdriverio (#14117)
Bumps [webdriverio](https://github.com/webdriverio/webdriverio) from 5.22.4 to 6.0.5.
- [Release notes](https://github.com/webdriverio/webdriverio/releases)
- [Changelog](https://github.com/webdriverio/webdriverio/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webdriverio/webdriverio/compare/v5.22.4...v6.0.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-03-27 10:26:29 -04:00
greenkeeper[bot] 0cd15541da Update mocha in group sample-code to the latest version 🚀 (#13876)
* chore(package): update mocha to version 7.0.1

* chore(package): update mocha to version 7.0.1
2020-01-27 12:54:04 -08:00
Canhua Li b38ed1efcd docs: add sample for WinAppDriver on Windows (#13157) 2019-08-31 10:00:27 +09:00
Srinivas Vishnubhotla 40cb4f610c docs: Java sample code for Windows Desktop Applications (#13132)
* Windows Desktop Application Java Sample Code
2019-08-29 16:42:56 +09:00
Isaac A. Murchie be967320c2 sample-code: fix python sample (#13107) 2019-08-22 07:57:13 -05:00
Mori Atsushi bdb234db9e fix: sample codes in python (#13091) 2019-08-18 21:28:04 +09:00
Isaac A. Murchie eb4ddafc36 Update python sample code (#12681) 2019-05-23 09:37:40 -04:00
greenkeeper[bot] cd07564127 chore(package): update assert to version 2.0.0 (#12633) 2019-05-13 08:19:06 -04:00
Isaac A. Murchie 4ccc8665f8 Begin running sample code in CI (#12519)
* Make stage in Travis to run wd sample code

* Clean up wd sample code for Sauce runs

* Restrict to master/non-PR builds
2019-04-23 12:58:42 -04:00
Kazuaki Matsuo 906350fd33 update sample apk (#12380) 2019-03-25 09:29:17 -07:00
Isaac A. Murchie 8e5ec38d3f Add function names (#12370) 2019-03-22 15:13:02 -04:00
greenkeeper[bot] 541beecc27 Update mocha in group sample-code to the latest version [ci skip] 🚀 (#12185) 2019-02-19 20:31:07 -08:00
Kazuaki Matsuo 783c5e3c2e ignore .lock file in ruby sample code (#12034) 2019-01-19 15:19:51 +09:00
greenkeeper[bot] 10753839a9 Update eslint-config-appium to the latest version 🚀 (#11952)
* chore(package): update eslint-config-appium to version 4.0.1

* chore: fix linting

* chore: rebase and done
2019-01-08 07:43:50 -06:00
Isaac A. Murchie e0c4106d22 Lint and update JS sample code (#11927)
* Lint and update JS wd sample code

* Lint and update JS webdriverio sample code

* Add JS sample code to greenkeeper
2019-01-03 09:40:53 -05:00
Sai Krishna 4df45addc3 update WDIO test to v5 (#11919)
* update WDIO test to v5

* fix review
2019-01-02 09:57:39 -08:00
Laolu Benson 5103a9a163 Add NUnit Test Adapter 2018-10-29 17:26:27 +00:00
Isaac A. Murchie 37539cb8f8 Fix platformVersion in Java sample code (#11356) 2018-09-12 11:05:39 -04:00
Dan Graham 833daae083 Upgrade rubyzip (#11331) 2018-09-07 08:57:20 -07:00
Kazuaki Matsuo c503f08574 Add csharp sample (#11255)
* add git ignore

* add csharp sample tests

* update readme

* remove comments
2018-08-28 09:21:14 -04:00
Kazuaki Matsuo 7b3b836f77 Tweak ruby sample (#11233)
* define spec_helper

* tweak ios default versions
2018-08-24 00:22:10 +09:00
Kazuaki Matsuo cd12ed9a51 Add python sample code (#11208)
* add initial python sample

* add all of ios and android tests

* apply formatter

* add >=0.28 to avoid version error

* tweak versions of default OS

* convert some tests to unittest based ones

* use single quote mainly

* use {} format style for string

* use format syntax

* apply format and tweak assertions

* use is None

* use assert raise

* speficy a number of elements

* tweak exception

* move app path to helper

* tweak assertion conditions

* remove .close since with open() close file automatically
2018-08-22 11:48:58 -07:00
Kazuaki Matsuo e0af090903 update ruby sample (#11203) 2018-08-18 09:21:52 +09:00
Srinivas Vishnubhotla bec8462016 Added More Tests (#11022)
* Added More Tests

Android Native
Android Browser
Android Sauce Labs
iOS Native
iOS Browser
iOS Sauce Labs

* Removed Duplicate Tests

* Removed Appium Version and changed AutomationName to UIAutomator2
2018-07-10 14:20:17 +01:00
Isaac A. Murchie 04f6543561 Bring Sample Code into master (#10880)
* Sample code stub (#9887)

* WD tests

* WD sample code (#9918)

* WebdriverIO sample code (#10166)

* Ruby sample code (#10331)

* PHP Sample Code (#10209)

* Basic Android java test

* Java sample code (#10427)

* Sample code (#10834)

* Sample code stub (#9887)

* WD tests

* WD sample code (#9918)

* WebdriverIO sample code (#10166)

* Ruby sample code (#10331)

* PHP Sample Code (#10209)

* Basic Android java test

* Java sample code (#10427)

* fixed WDIO test

* Update .npmignore
2018-06-15 08:23:42 -04:00
Dan Graham 36cc935fc5 Revert "Create session and basic interactions samples (#9907)" (#9915)
This reverts commit 061e264800.
2018-01-04 13:52:30 -08:00
Dan Graham 061e264800 Create session and basic interactions samples (#9907)
* Add apps; add create session test
* Android create session tests
* iOS basic interactions test
* Basic web session tests (iOS and Android)
2018-01-04 13:48:24 -08:00
Jonathan Lipps 25efe37e38 remove actual sample app code
this is in a different commit so previous commit can be examined separately
2014-08-12 18:00:21 -07:00
Jonathan Lipps 0483952a0e move sample code and apps out of main repo
and add a grunt task that brings them in for use in dev
2014-08-12 17:58:42 -07:00
bootstraponline deb302b992 Restore sample-code apps 2014-08-11 15:46:41 -04:00
bootstraponline ae67c38bc4 Move sample code to https://github.com/appium/sample-code 2014-08-09 19:45:16 -04:00
Isaac Murchie 54868eb21a Fix tests for real device 2014-08-04 18:09:55 -07:00
bootstraponline a2e0fca11a Fix cucumber 404 2014-07-28 20:00:54 -04:00
Jonathan Lipps 4aa7532c62 Merge pull request #3127 from Erolstt/master
added robot framework contact example
2014-07-14 15:43:14 -07:00
Erol Selitektay e717690e63 added robot framework contact example
robot framework contact example for android added
2014-07-13 13:43:12 +03:00
sebv 1b69662ff6 added element conversion examples 2014-07-04 02:57:37 +08:00
Isaac Murchie 277cc8ee60 Fix webview name in node Android sample 2014-07-03 09:49:59 -07:00
sebv 10250698b0 added protractor bridge example 2014-07-03 22:26:27 +08:00