Git Product home page Git Product logo

testcafe-browser-provider-electron's Introduction

testcafe-browser-provider-electron

Build Status

This is the electron browser provider plugin for TestCafe.

Install

npm install testcafe-browser-provider-electron

Usage

First, create a .testcafe-electron-rc file in the root directory of your Electron app. For more info, see the Config section.

{
  "mainWindowUrl": "./index.html"
}

When you run tests from the command line, specify the path to the Electron app prefixed with "electron:" -

testcafe "electron:/home/user/electron-app" "path/to/test/file.js"

When you use API, pass the app path to the browsers() method:

testCafe
    .createRunner()
    .src('path/to/test/file.js')
    .browsers('electron:/home/user/electron-app')
    .run();

Config

Below is a list of configuration options that you can specify in .testcafe-electron-rc.

  • mainWindowUrl (required) - specifies URL used for the main window page of the appplication. If you use file:// urls, you can also specify a relative (to the application directory) or an absolute path to the file of the page.
  • appPath (optional) - alters path to the application. By default, the application path is specified after the electron: prefix in the string passed to the command line or API. You can override it by specifying an absolute path, or append a relative path from appPath.
  • appArgs (optional) - overrides application command line arguments with the values specified in this option. It should be an array or an object with numeric keys.
  • disableNavigateEvents (optional) - if you use did-navigate or will-navigate webContent events to prevent navigation, you should disable it by setting this option to true.
  • openDevTools (optional) - if true, DevTools will be opened just before tests start.

Helpers

You can use helper functions from the provider in your test files. Use ES6 import statement to access them.

import { getMainMenu, clickOnMenuItem } from 'testcafe-browser-provider-electron';
  • async function getMenuItem (menuItemSelector) - gets a snapshot of the specified menu item. menuItemSelector is a string that consists of the menu type and menu item labels, separated by the > sign, e.g. Main Menu > File > Open or Context Menu > Undo. The Main Menu menu type can be skipped. If there are several menu items with the same label on the same level, you can specify a one-based index in square brackets, e.g. Main Menu > Window > My Window [2] selects the second menu item with label My Window in the Window menu. Check the properties available in the snapshot here.

  • async function getMainMenu () - gets a snapshot of the application main menu. You can check properties available in the snapshot here.

  • async function getContextMenu () - gets a snapshot of the context menu. You can check properties available in the snapshot here,

  • async function clickOnMenuItem (menuItem, modifiers) - performs a click on the given menuItem. It can be a string, in this case it will be passed to the getMenuItem function and the returned value will be used; or a value retrieved with getMenuItem, getMainMenu, getContextMenu functions. Also, you can pass the state of the control keys (Shift, Ctrl, Alt, Meta) in the modifiers argument, e.g. the default is { shift: false, ctrl: false, alt: false, meta: false}. Examples: clickOnMenuItem('Main Menu > File > Open'), clickOnMenuItem('File > Open'), clickOnMenuItem((await getMainMenu()).items[0].submenu.items[0]),

  • async function setElectronDialogHandler (handler, dependencies) - sets a function function handler (type, ...args) that will handle native Electron dialogs. Specify the function's global variables in the dependencies argument. The handler function must be synchronous and will be invoked with the dialog type type, and the arguments args from the original dialog function.

Author

Developer Express Inc. (https://devexpress.com)

testcafe-browser-provider-electron's People

Contributors

andreybelym avatar

Watchers

 avatar  avatar

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.