{"_id":"@amilajack/testcafe-browser-provider-electron","_rev":"1-c8a0f96209909de7d26bfbc82aae5713","name":"@amilajack/testcafe-browser-provider-electron","dist-tags":{"latest":"0.0.15-alpha.1"},"versions":{"0.0.15-alpha.1":{"name":"@amilajack/testcafe-browser-provider-electron","version":"0.0.15-alpha.1","description":"TestCafe browser provider plugin for testing applications built with Electron.","repository":{"type":"git","url":"git+https://github.com/DevExpress/testcafe-browser-provider-electron.git"},"homepage":"https://github.com/DevExpress/testcafe-browser-provider-electron","author":{"name":"Developer Express Inc.","url":"https://devexpress.com"},"main":"lib/index.js","scripts":{"test":"gulp test","publish-please":"del-cli package-lock.json node_modules && npm i && publish-please"},"keywords":["testcafe","browser provider","plugin","electron"],"license":"MIT","dependencies":{"babel-runtime":"^6.25.0","chrome-remote-interface":"^0.27.0","debug":"4.1.1","dedent":"^0.7.0","endpoint-utils":"^1.0.2","lodash":"^4.17.4","mustache":"^2.3.0","node-ipc":"^9.1.0","os-family":"^1.0.0","pify":"^2.3.0","pinkie":"^2.0.4","promisify-event":"^1.0.0","proxyquire":"^1.7.10"},"peerDependencies":{"testcafe":"*"},"devDependencies":{"asar":"^2.0.1","babel-eslint":"^7.2.3","babel-plugin-add-module-exports":"^0.2.1","babel-plugin-transform-runtime":"^6.23.0","babel-preset-env":"^1.6.0","del":"^2.0.0","del-cli":"^3.0.0","electron":"^8.2.3","gulp":"^4.0.0","gulp-babel":"^7.0.0","gulp-eslint":"^3.0.1","publish-please":"^5.4.3","testcafe":"*","tmp":"0.0.28"},"types":"./ts-defs/index.d.ts","gitHead":"70a58d43b73e5fc04b6cabbfb1382278cf60e8d4","bugs":{"url":"https://github.com/DevExpress/testcafe-browser-provider-electron/issues"},"_id":"@amilajack/testcafe-browser-provider-electron@0.0.15-alpha.1","_nodeVersion":"13.7.0","_npmVersion":"6.14.3","dist":{"integrity":"sha512-05JwzcV59rxArehDWPM0Lw4YNvVr5c3J/j2ikJeQKHAQSoA0TsRSdqSMjGDaT8LGem0HAATPLh7hRhI481alIQ==","shasum":"506080ec623c1509fae489b13cb2a2894ec6fbb9","tarball":"https://registry.npmjs.org/@amilajack/testcafe-browser-provider-electron/-/testcafe-browser-provider-electron-0.0.15-alpha.1.tgz","fileCount":22,"unpackedSize":113265,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJetgGdCRA9TVsSAnZWagAApgMP/jmrWZl5zo6QmIylz0nc\n28MAONHR1M+W+vnyQ8SLeb6t+e0lBYrrikbSXNz3w28L8ereOlMSsTkSwVk7\nrfnDlZVnkpj23OpiBxF6Owh1NRT0f6C/gVWfjvnc+h9m5gPnUVZAccES0+oa\nJU1i6e83EMRCvGBs7pjvQXXKu+hK6GuOsDYIXWOgfirMf9K0fQgF1dp/exK9\nzvriojfhoCChM7LuApegFVK1SVgw/9gpt9lQofrAjgSmirv2f+nvnItMbQrq\nKtIvnoCSd52Tv7mB+mawkHFoLDkmPq7DksUDihBQo18m/4i+krue7UtF8tCJ\n6oornjN62C9k5FRtKZNBzyOmuOwpsZ8nDCMSDuZSJD1kcPsFzE+nqF+y72bY\nvSlJTXE4Z/IIb3oiRsQ9KLxM+9nI4FVmYfPGASmZyfmbmEKsfA4wmO1wfZZO\n/THfQy0eu+XwXOGFPC3ITI3rbTXLGN4+M0hIjA1mdyQZHJul/M9+8//XiwgB\nWDC3sX0HppUS2lTdGWP7eq/5ZDoXcLEpgLipU4MZ5jrXRLFBi8EXt6q59d+1\n+WnICe1pNa0KJyb14GM8ZDRPctiu9UtYUHdIji2ZDKgw6agh6CGoR1i60Y/3\noF/PIqKFVHQ5n/y5R/NXauBlNiTq9s1HEOtxmGAafFN7XLt306UffY3NWONT\nKA5y\r\n=bJEP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDA81fcip6UDKxlv5IBXGFaLzzr/R3dzH+yuwdPM856UwIhAPnhYRlud+teGf/tlmsDT6GJDAfsNKTF+HT3reqH7md4"}]},"maintainers":[{"name":"amilajack","email":"amilajack@gmail.com"}],"_npmUser":{"name":"amilajack","email":"amilajack@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/testcafe-browser-provider-electron_0.0.15-alpha.1_1588986268983_0.6722583420269297"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-09T01:04:28.897Z","0.0.15-alpha.1":"2020-05-09T01:04:29.177Z","modified":"2022-04-04T13:48:51.193Z"},"maintainers":[{"name":"amilajack","email":"amilajack@gmail.com"}],"description":"TestCafe browser provider plugin for testing applications built with Electron.","homepage":"https://github.com/DevExpress/testcafe-browser-provider-electron","keywords":["testcafe","browser provider","plugin","electron"],"repository":{"type":"git","url":"git+https://github.com/DevExpress/testcafe-browser-provider-electron.git"},"author":{"name":"Developer Express Inc.","url":"https://devexpress.com"},"bugs":{"url":"https://github.com/DevExpress/testcafe-browser-provider-electron/issues"},"license":"MIT","readme":"# testcafe-browser-provider-electron\n[![Build Status](https://travis-ci.org/DevExpress/testcafe-browser-provider-electron.svg)](https://travis-ci.org/DevExpress/testcafe-browser-provider-electron)\n\nUse this plugin to test **Electron** applications with [TestCafe](http://devexpress.github.io/testcafe).\n\n## Getting Started\n\n### Installation\n\n```sh\nnpm install testcafe-browser-provider-electron\n```\n\n### Testing a JavaScript Application\n\nIf your JavaScript application runs in Electron, follow these steps to set up testing.\n\n1. Create a `.testcafe-electron-rc` file in the root application directory. Include the following settings to this file.\n\n    ```json\n    {\n      \"mainWindowUrl\": \"./index.html\"\n    }\n    ```\n\n    An Electron app has a file that is loaded as a startup page. TestCafe waits until Electron loads this page and then runs tests. Specify the path to this file with `mainWindowUrl` option. If a relative path is specified, it is resolved from the `.testcafe-electron-rc` file location.\n\n    For information about other options, see the [Configuration](#configuration) section.\n\n2. Install the Electron module of the required version.\n\n    ```sh\n    npm install electron@latest\n    ```\n\n    The command above installs the latest version of the Electron executable.\n\n3. Define the path to the config file. Use browser provider postfix: `electron:<path_to_testcafe-electron-rc_directory>`. Then run tests.\n\n    ```sh\n    testcafe \"electron:/home/user/electron-app\" \"<tests_directory>/**/*.js\"\n    ```\n\n4. The `.testcafe-electron-rc` file might be not in the application root directory. In that case specify the path to the configuration file like this:\n\n    ```json\n    {\n      \"mainWindowUrl\": \"./index.html\",\n      \"appPath\":       \"/home/user/my_app\"  \n    }\n    ```\n    \n    In this instance, the `appPath` directory will be used as a working directory of the Electron application.\n    \n### Testing an Executable Electron Application\n\nIf your Electron app is built it has `<your_app_name>.exe` or `electron.exe` file. In that case you don't need an Electron module to run tests. Perform the following steps instead.\n\n1. In the application directory, create a `.testcafe-electron-rc` file with the following settings.\n\n    ```json\n    {\n        \"mainWindowUrl\": \"./index.html\",\n        \"electronPath\":  \"/home/user/myElectronApp/electron\"\n    }\n    ```\n    \n    `mainWindowUrl` points to the application startup page; `electronPath` defines the path to your application's executable file. If you specify relative paths, they will be resolved from the `.testcafe-electron-rc` file location.\n    \n2. When you run tests, define the path to the configuration file. To do so, add the browser provider postfix: `electron:<path_to_testcafe-electron-rc_directory>`.\n\n    ```sh\n    testcafe \"electron:/home/user/electron-app\" \"<tests_directory>/**/*.js\"\n    ```\n    \n### Launching Tests from API\n\nTo launch tests through the API, specify the application path with `electron:` prefix and pass it to the `browsers` method.\n\n```js\ntestCafe\n    .createRunner()\n    .src('path/to/test/file.js')\n    .browsers('electron:/home/user/electron-app')\n    .run();\n```\n\n### Specifying Target Webpage in Test Code\n\nIn most cases, the target webpage is the main application page specified via the `mainWindowUrl` configuration option. \n\n```json\n{\n  \"mainWindowUrl\": \"./index.html\"\n}\n```\n\n```js\nfixture `Electron test`\n    .page('./index.html');\n```\nHowever, you can specify any application page if your app contains more than one.\n\n```js\nfixture `Electron test`\n    .page('./views/detail.html');\n```\n\n## Configuration\n\nYou can specify the following options in the `.testcafe-electron-rc` configuration file.\n\n### mainWindowUrl\n\n__Required.__ Specifies the URL of the application's main window page.\n For local application pages, you can also specify a relative (to the application directory) or an absolute path to the file of the page.\n\n### appPath\n\n__Optional.__ Alters path to the application, which, by default, must be located at the [default Electron app directory](https://github.com/electron/electron/blob/master/docs/tutorial/application-distribution.md#application-distribution).\nYou can use the `appPath` option to override the default path by specifying a new absolute path. Alternatively, you can append a relative path to the path specified after the \"electron:\" prefix.\n\n### appArgs\n\n__Optional.__ Overrides application command line arguments with the values specified in this option. It should be an array or an object with numeric keys.\n\n### electronPath\n\n__Optional__. Specifies a path to the electron binary. If `electronPath` is not specified, the [electron package](https://www.npmjs.com/package/electron) should be installed.\n On macOS, it can be either a path to the `electron` binary, or a path to the entire Electron.app (e.g. `/Applications/Electron.app`). It may be necessary to stop all other running \n instances of the specified Electron binary.\n\n### enableNavigateEvents\n\n__Optional.__ `testcafe-browser-provider-electron` suppresses `did-navigate` and `will-navigate`  webContent events because you will be unable to run tests if these events are used to prevent navigation. You can enable them back by setting this option to `true`.\n\n### openDevTools\n\n__Optional.__ If `true`, DevTools will be opened just before tests start.\n\n## Helpers\nYou can use helper functions from the provider in your test files. Use ES6 import statement to access them.\n\n```js\nimport { getMainMenu, clickOnMenuItem } from 'testcafe-browser-provider-electron';\n```\n\n### getMainMenuItem\n\nGets a snapshot of the specified application's main menu item.\n\n```js\nasync function getMainMenuItem (menuItemSelector)\n```\n\nParameter          | Type   | Description\n------------------ | ------ | -----\n`menuItemSelector` | String | An array of menu item labels and/or objects with properties \"label\" and \"index\".\n\n For example, you can pass the following values in the `menuItemSelector` parameter.\n\n * `['File', 'Open']`\n * `['File', { label: 'Open' }]`\n * `Context Menu > Undo`\n\n\n If there are several menu items with the same label on the same level, you can specify a one-based \"index\"\n property:\n\n * `['Window', {label: 'My Window', index: 2}]`\n\n This value corresponds to the second menu item with label `My Window` in the `Window` menu.\n\n Check the properties available in the snapshot\n [here](https://github.com/electron/electron/blob/master/docs/api/menu-item.md).\n\n**Example**\n\n```js\nimport { getMainMenuItem } from 'testcafe-browser-provider-electron';\n\nfixture `Electron test`\n    .page('./index.html');\n\ntest('Check the menu item role', async t => {\n    const menuItem = await getMainMenuItem(['Main Menu', 'Edit', 'Undo']);\n    \n    await t.expect(menuItem.role).eql('undo');    \n});\n```\n\n### getContextMenuItem\n\nGets a snapshot of the specified menu item from the **most recently** opened context menu.\n\n```js\nasync function getContextMenuItem (menuItemSelector)\n```\n\nParameter          | Type   | Description\n------------------ | ------ | -----\n`menuItemSelector` | String | An array of menu item labels and/or objects with properties \"label\" and \"index\".\n\n For example, you can pass the following values in the `menuItemSelector` parameter.\n\n * `['Go To', 'Declaration']`\n * `['Go To', { label: 'Declaration' }]`\n\n If there are several menu items with the same label on the same level, you can specify a one-based \"index\"\n property:\n\n * `['Go To', {label: 'My Function', index: 2}]`\n\n This value corresponds to the second menu item with label `My Function` in the `Go To` submenu.\n\n Check the properties available in the snapshot\n [here](https://github.com/electron/electron/blob/master/docs/api/menu-item.md).\n\n**Example**\n\n```js\nimport { getContextMenuItem } from 'testcafe-browser-provider-electron';\n\nfixture `Electron test`\n    .page('./index.html');\n\ntest('Check the menu item role', async t => {\n    await t.rightClick('.el');\n    \n    const menuItem = await getContextMenuItem(['Go To', {label: 'My Function', index: 2}]);\n    \n    await t.expect(menuItem.visible).ok();    \n});\n```\n\n ### getMainMenuItems\n\nGets an array of snapshots of the application's main menu items. If an item has a submenu, it will also be represented as an array of snapshots.\n\n ```js\n async function getMainMenuItems ()\n ```\n\n You can check properties available in snapshots\n [here](https://github.com/electron/electron/blob/master/docs/api/menu-item.md).\n\n**Example**\n\n```js\nimport { getMainMenuItems } from 'testcafe-browser-provider-electron';\n\nfixture `Electron test`\n    .page('./index.html');\n\ntest('Menu should contains the proper list of items', async t => {\n    const menuItems = (await getMainMenuItems()).map(item => item.label);\n    \n    await t.expect(menuItems).eql(['File', 'Edit', 'Help']);\n});\n```\n\n ### getContextMenuItems\n\nGets an array of item snapshots from the **most recently** opened context menu. If an item has a submenu, it will also be represented as an array of snapshots.\n\n ```js\n async function getContextMenuItems ()\n ```\n\n You can check properties available in snapshots\n [here](https://github.com/electron/electron/blob/master/docs/api/menu.md),\n\n**Example**\n\n```js\nimport { getContextMenuItems } from 'testcafe-browser-provider-electron';\n\nfixture `Electron test`\n    .page('./index.html');\n\ntest('Context menu should contains the proper list of items', async t => {\n    await t.rightClick('.element-with-context-menu');\n    \n    const menuItems = (await getContextMenuItems()).map(item => item.label);\n    \n    await t.expect(menuItems).eql(['Cut', 'Copy', 'Properties']);\n});\n```\n\n ### clickOnMainMenuItem\n\n Performs a click on the specified main menu item (`menuItem`).\n\n ```js\n async function clickOnMainMenuItem (menuItem, modifiers)\n ```\n\n Parameter          | Type   | Description\n------------------ | ------ | -----\n`menuItem` | String &#124; Object | The main menu item to click.\n`modifiers` | Object | Control keys held when clicking the menu item.\n\n If you specify a string in the `menuItem` parameter, it will be passed to the [getMainMenuItem](#getmainmenuitem) function and the returned value will be used. Alternatively, you can pass a value returned by the [getMainMenuItem](#getmainmenuitem) or [getMainMenuItems](#getmainmenuitems) function.\n\n Use the `modifiers` parameter to specify state of the control keys (`Shift`, `Ctrl`, `Alt`, `Meta`). The default value is\n\n ```json\n {\n     \"shift\": false,\n     \"ctrl\":  false,\n     \"alt\":   false,\n     \"meta\":  false\n }\n  ```\n\n **Examples**\n\n```js\nimport { clickOnMainMenuItem } from 'testcafe-browser-provider-electron';\n\nfixture `Test Electron`\n   .page('./index.html');\n\ntest('Should open search panel', async t => {\n   await clickOnMainMenuItem(['Main Menu', 'Edit', 'Find...']);\n   \n   await searchPanel = Selector('.search-panel');\n   \n   await expect(searchPanel.count).eql(1);\n});\n```\n\n```js\nimport { clickOnMainMenuItem, getMainMenuItems } from 'testcafe-browser-provider-electron';\n\nfixture `Test Electron`\n    .page('./index.html');\n\ntest('Should create new file', async t => {\n    await clickOnMainMenuItem(['File', 'New']);\n    //Or\n    await clickOnMainMenuItem((await getMainMenuItems())[0].submenu[0])\n    \n    await newFile = Selector('.file-item').withText('New File');\n    \n    await expect(newFile.count).eql(1);\n});\n```\n\n### clickOnContextMenuItem\n\nPerforms a click on the specified menu item (`menuItem`) of the **most recently** opened context menu.\n\n ```js\n async function clickOnContextMenuItem (menuItem, modifiers)\n ```\n\n Parameter          | Type   | Description\n------------------ | ------ | -----\n`menuItem` | String &#124; Object | The main menu item to click.\n`modifiers` | Object | Control keys held when clicking the menu item.\n\n If you specify a string in the `menuItem` parameter, it will be passed to the [getContextMenuItem](#getcontextmenuitem) function and the returned value will be used. Alternatively, you can pass a value returned by the [getContextMenuItem](#getcontextmenuitem) or [getContextMenuItems](#getcontextmenuitems) function.\n\n Use the `modifiers` parameter to specify state of the control keys (`Shift`, `Ctrl`, `Alt`, `Meta`). The default value is\n\n ```json\n {\n     \"shift\": false,\n     \"ctrl\":  false,\n     \"alt\":   false,\n     \"meta\":  false\n }\n  ```\n\n **Examples**\n\n```js\nimport { clickOnContextMenuItem } from 'testcafe-browser-provider-electron';\n\nfixture `Test Electron`\n    .page('./index.html');\n\ntest('Should open properties of element', async t => {\n    await t.rightClick('.el');\t   \n    await clickOnContextMenuItem(['Properties...']);\n    \n    await elPropsPanel = Selector('.item-properties-panel');\n    \n    await expect(elPropsPanel.count).eql(1);\n});\n```\n\n ### setElectronDialogHandler\n\n Sets a function that will handle native Electron dialogs.\n\n ```js\n async function setElectronDialogHandler (handler, dependencies) \n ```\n\n  Parameter          | Type   | Description\n------------------ | ------ | -----\n`handler` | Function | A function that will handle Electron dialogs.\n`dependencies` | Object | Variables passed to the `handler` function's scope as global variables.\n\n The `handler` function has the following signature.\n\n ```js\n function handler (type, ...args)\n ```\n\n This function must be synchronous. It will be invoked with the dialog type `type`, and the arguments `args`\n from the original dialog function.\n \n The `type` parameter takes one of the following values: \n \n * `open-dialog`,\n * `save-dialog`,\n * `message-box`,\n * `error-box`,\n * `certificate-trust-dialog`.\n \n **Example**\n \n ```js\n import { setElectronDialogHandler } from 'testcafe-browser-provider-electron';\n\nfixture `Electron test`\n    .page('./index.html');\n\ntest('Test project opening', async t => {\n    await setElectronDialogHandler((type, browserWindow, options) => {\n    \t//browserWindow, options are standard arguments of the opening dialog, you can use it for your purposes\n        if(type !== 'open-dialog') \n            return;\n\n        //it returns the file path from the open dialog\n        return ['/home/user/project_name'];\n    });\n\n    await t\n        .click('.open-project')\n        //Here the open directory dialog opens and returns the path '/home/user/project_name'\n        //After this, we check that the project was opened to get its name\n        .expect('.project-name').eql('project_name');        \n});\n```\n \n## Author\nDeveloper Express Inc. (https://devexpress.com)\n","readmeFilename":"README.md"}