{"id":20617944,"url":"https://github.com/applitools/jest-environment-selenium","last_synced_at":"2025-04-15T11:36:26.361Z","repository":{"id":31926348,"uuid":"130844691","full_name":"applitools/jest-environment-selenium","owner":"applitools","description":"Jest environment for running Selenium WebDriver tests","archived":false,"fork":false,"pushed_at":"2023-03-04T03:41:35.000Z","size":193,"stargazers_count":29,"open_issues_count":5,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-28T19:37:55.382Z","etag":null,"topics":["environment","jest","selenium","webdriver"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/applitools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-24T11:37:48.000Z","updated_at":"2024-06-18T15:10:23.000Z","dependencies_parsed_at":"2024-06-18T15:52:16.039Z","dependency_job_id":null,"html_url":"https://github.com/applitools/jest-environment-selenium","commit_stats":{"total_commits":46,"total_committers":5,"mean_commits":9.2,"dds":"0.32608695652173914","last_synced_commit":"2798819b7ebfd2ad7931c5bb79c4266277a306e7"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applitools%2Fjest-environment-selenium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applitools%2Fjest-environment-selenium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applitools%2Fjest-environment-selenium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applitools%2Fjest-environment-selenium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/applitools","download_url":"https://codeload.github.com/applitools/jest-environment-selenium/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557847,"owners_count":21124168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["environment","jest","selenium","webdriver"],"created_at":"2024-11-16T12:06:35.895Z","updated_at":"2025-04-15T11:36:26.332Z","avatar_url":"https://github.com/applitools.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-environment-selenium \u0026middot; [![npm version](https://img.shields.io/npm/v/jest-environment-selenium.svg)](https://www.npmjs.com/package/jest-environment-selenium) [![Build Status](https://travis-ci.org/applitools/jest-environment-selenium.svg?branch=master)](https://travis-ci.org/applitools/jest-environment-selenium)  ![License](https://img.shields.io/npm/l/jest-environment-selenium.svg)  \nJest environment for running Selenium WebDriver tests\n\n### Installation\n\nI like using [yarn](https://github.com/yarnpkg/yarn) for installations.\n\n```\nyarn add -D jest-environment-selenium\n```\n\nBut npm works too!\n\n```\nnpm install --save-dev jest-environment-selenium\n```\n\n### Setup\n\nAdd this to the `package.json`:\n\n```js\n\"jest\": {\n    \"testEnvironment\": \"jest-environment-selenium\",\n    \"setupTestFrameworkScriptFile\": \"jest-environment-selenium/dist/setup.js\"\n}\n```\n\nBy default tests will run against a local `chromedriver`, but you can easily specify something else.\n\n\n```js\n\"jest\": {\n    \"testEnvironmentOptions\": {\n      \"capabilities\": {\n        \"browserName\": \"firefox\"\n      },\n      \"server\": \"http://localhost:4444/wd/hub\",\n      \"proxyType\": \"manual\",\n      \"proxyOptions\": {\n        \"https\": \"http://127.0.0.1:3218\"\n      }\n    }\n}\n```\n\n### Jest Environment Selenium\n\nTests will be initialized with a `driver` according to the options (or a default chrome one)\n```js\ntest('load wikipedia', () =\u003e {\n  driver.get('https://en.wikipedia.org/wiki/Base64');\n});\n```\n\n#### `cleanup`\nKills the used session and starts a new one.\n\n```js\nafterEach(async () =\u003e (cleanup()));\n```\n\nFailing to call `cleanup` will result in non \"idempotent\" tests, which reuse the same WebDriver session (which can lead to difficult to debug errors in your tests).\n\n#### Caveats\nSince the tests are [async](https://facebook.github.io/jest/docs/en/asynchronous.html#resolves-rejects) make sure you return a `Promise` so that `jest` won't bail early\n\n\n```js\ntest('load wikipedia', () =\u003e {\n  driver.get('https://en.wikipedia.org/wiki/Base64');\n  return driver.getTitle().then(title =\u003e {expect(title).toBeDefined();});\n});\n```\n\n### Matchers\nCustom WebDriver matchers designed for ease of use with jest\n\n#### expect.resolves[.not].toBePresent()\n`toBePresent` checks that an element appears on a page, it expects to receive a `WebElementPromise`\n```js\ntest('link appears in the page', () =\u003e {\n  driver.get('https://en.wikipedia.org/wiki/Base64');\n  return expect(driver.findElements(By.linkText(\"binary-to-text encoding\"))).resolves.toBePresent();\n});\n```\n\n#### expect.resolves[.not].toBeChecked()\n`toBeChecked` checks that a checkbox is checked (many checks wow! :scream:), it expects to receive a `WebElementPromise`\n```js\ntest('a checkbox is checked', () =\u003e {\n  driver.get('somewhere');\n  return expect(driver.findElements(By.css('input[type=\"checkbox\"]'))).resolves.toBeChecked();\n});\n```\n\n#### expect.resolves[.not].toBeEditable()\n`toBeEditable` checks that an input is editable (enabled and not readonly), it expects to receive a `WebElementPromise`\n```js\ntest('an input is editable', () =\u003e {\n  driver.get('somewhere');\n  return expect(driver.findElements(By.css('input'))).resolves.toBeEditable();\n});\n```\n\n#### expect.resolves[.not].toHaveValue(value)\n`toHaveValue` checks that an input value is what you expect, it expects to receive a `WebElementPromise`\n```js\ntest('an input has the value', () =\u003e {\n  driver.get('somewhere');\n  return expect(driver.findElements(By.css('input'))).resolves.toHaveValue('test');\n});\n```\n\n#### expect.resolves[.not].toHaveSelectedValue(value)\n`toHaveValue` checks that a select value is what you expect (will fail on other inputs), it expects to receive a `WebElementPromise`\n```js\ntest('a select has the right value', () =\u003e {\n  driver.get('somewhere');\n  return expect(driver.findElements(By.css('select'))).resolves.toHaveSelectedValue('test');\n});\n```\n\n#### expect.resolves[.not].toHaveText(value)\n`toHaveValue` checks that an element `innetText` is what you expect, it expects to receive a `WebElementPromise`\n```js\ntest('the paragraph has the correct text', () =\u003e {\n  driver.get('somewhere');\n  return expect(driver.findElements(By.css('p'))).resolves.toHaveText('some nice text, maybe lorem ipsum');\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplitools%2Fjest-environment-selenium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapplitools%2Fjest-environment-selenium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplitools%2Fjest-environment-selenium/lists"}