0.0.4 • Published 4 months ago

@dlenroc/appium-html-driver v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Appium HTML Driver · NPM Version Node.js Version

Appium HTML Driver is a WebDriver that allows controlling applications written using web technologies, regardless of the device they are running on.

Installation

appium driver install --source npm @dlenroc/appium-html-driver

Connection

DevTools Protocol

If target supports the devtools protocol, then we can connect to it via chrome-remote-interface.

  1. Get the DevTools target address (sample with Google Chrome)

    $ "<browser.path>" --user-data-dir="$(mktemp -d)" --remote-debugging-port="9222"
    
    DevTools listening on ws://127.0.0.1:9222/devtools/browser/c8f3b64d-aa40-4c56-b1d4-b4796fb24eae
  2. Attach and run test

    await driver = await remote({
      'capabilities': {
        'platformName': 'html',
        'appium:automationName': 'html',
        'appium:debuggingAddress': 'ws://127.0.0.1:9222/devtools/browser/c8f3b64d-aa40-4c56-b1d4-b4796fb24eae'
      },
    });
    
    // Attach to target
    const handles = await driver.getWindowHandles();
    await driver.switchToWindow(handles[0]);
    
    // Conduct testing
    await driver.getUrl()
      .should.eventually.be.fulfilled;

On-Device Component

If target doesn't support DevTools Protocol or you need access to pages it can't access, then ODC may be what you need.

  1. Instrumentation

    Inject the following code in every HTML file that belongs to your application.

    <script src="{origin}/appium-html-driver/js/{udid}/{handle}"></script>

    Where:

    • origin - address of the Appium server, for example: http://192.168.0.2:4723.
    • udid - identifier that represent your device, for > example: {device-name}-{serial-number}.
    • handle (optional) - identifier that will represent the window handle.
  2. Attach and run test

    await driver = await remote({
      'capabilities': {
        'platformName': 'html',
        'appium:automationName': 'html',
        'appium:debuggingAddress': `odc://${udid}/${handle}`
      },
    });
    
    /**
     * Load instrumented page manually, via cli or in any other way
     *
     * NOTE: that is not driver's responsibility
     */
    
    // Attach to target
    const handles = await driver.getWindowHandles();
    await driver.switchToWindow(handles[0]);
    
    // Conduct testing
    await driver.getUrl()
      .should.eventually.be.fulfilled;

NOTE: Because of how the instrumentation process works, the test session should start first, and then the application.

If this is a problem, you can initialize the driver yourself once and then not care about the mentioned limitation:

curl 'http://localhost:4723/session' \
  -H 'content-type: application/json;charset=utf-8' \
  -d '{ "capabilities": { "alwaysMatch": { "platformName": "html", "appium:automationName": "html", "appium:debuggingAddress": "odc://init" } } }'

Capabilities

CapabilityRequiredTypeDescription
platformName+stringMust be html
appium:automationName+stringMust be html
appium:debuggingAddress+stringSee Connection

Commands

CommandDescription
activeGet active element
backBack
clearElement clear
clickElement click
closeWindowClose window
createSessionNew session
createNewWindowNew window
deleteCookieDelete cookie
deleteCookiesDelete all cookies
elementDisplayedIs element displayed
elementEnabledIs element enabled
elementSelectedIs element selected
executeExecute script
executeAsyncExecute async script
findElementFind element
findElementFromElementFind element form element
findElementsFind elements
findElementsFromElementFind elements from element
forwardForward
getAttributeGet element attribute
getCookieGet named cookie
getCookiesGet all cookies
getCssPropertyGet element CSS value
getElementRectGet element rect
getNameGet element tag name
getPageSourceGet page source
getPropertyGet element property
getTextGet element text
getTimeoutsGet timeouts
getUrlGet current URL
getWindowHandleGet window handle
getWindowHandlesGet window handles
getWindowRectGet window rect
maximizeWindowMaximize window
refreshRefresh
setCookieAdd cookie
setFrameSwitch to frame
setParentFrameSwitch to parent frame
setUrlNavigate to URL
setValueElement send keys
setWindowSwitch to window
setWindowRectSet window rect
timeoutsSet timeouts
titleGet title