Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@amadeus-it-group/protractor-to-playwright
Advanced tools
Command line tool that automatically migrates tests from protractor to playwright.
This tool is designed to automatically migrate code from Protractor to Playwright. It is inspired by the "Migrating from Protractor" guide in Playwright documentation.
The migration can be done directly by executing the following command in the e2e root folder:
npx @amadeus-it-group/protractor-to-playwright@latest --dst='relative/path/to/e2e-playwright-folder' --tsconfig='relative/path/to/tsconfig.conf.ts'
Basically, it takes these arguments:
You can get the help on the usage with npx @amadeus-it-group/protractor-to-playwright@latest --help
A file 'playwright-utils' is added at the root of destination folder. It contains useful functions to help the conversion.
In protractor, there is a notion of current page from where you can do actions. In Playwright, this page is given in the callback function parameter of a test. In order to reproduce the Protractor behaviour, the setPage
function (of playwright-utils) must be used at the start of each test to store the current page, which can be retrieved at any time with the getPage
function. The test
object of playwright-utils must be used as well, in order to clear the current page at the end of the test.
You can adopt different migration strategies depending on your project. This is an example of how it can be done:
npx @amadeus-it-group/protractor-to-playwright@latest --src=e2e --dst='e2e-playwright' --tsconfig='e2e/tsconfig.conf.ts'
(e2e contains the protractor suite, e2e-playwright the folder for Playwright, e2e/tsconfig.conf.ts is the tsconfig for your protractor tests),The new code will not work directly and will require manual changes. At this point, either you detect that something can be improved in the tool, so you can contact us or open a PR, or the migration can be finished on your side in a reasonable time. At any time, you can use the 'file' parameter to migrate only a set of files.
At this point you can either wait for a new release with fixes or finish the work on your side (and you will not need the migration tool anymore :).
The test functions (replacement of 'it') are run with isolation, meaning that a new browser page is recreated for each test. After the conversion, you should check that:
beforeAll and afterAll would probably need to be converted in beforeEach and afterEach.
Your tests are independent. If it's not the case, they will need to be converted in 'test.step' inside a test (you can use the test parameter to convert them globally, if it's easier to finish the conversion).
For example, after the migration, you can have:
test('test 1', async({page}) => {
...
});
test('test 2', async({page}) => {
// Test 2 depends on the actions done in test 1
...
});
As test 2 depends on test 1, you will need to convert the code this way:
import { setPage } from "../../playwright-utils"; // Path to be adapted
...
test('Global description', async ({page}) => {
setPage(page);
await test.step('test 1', async () => {
...
});
await test.step('test 2', async () => {
// Test 2 depends on the actions done in test 1
...
});
});
ElementArrayFinder.filter : This function returns a ElementArrayFinder, which can be chained with usual protractor methods. It will probably need to be refactored.
ExpectedConditions : even if a lot of these utility methods have been translated, the code would probably not need it and be refactored.
For example, in the following code:
const button = this.page.locator('#buttonId');
await browser.wait(ExpectedConditions.presenceOf(button));
await button.click();
The line browser.wait
is not needed at all, as Playwright provides all this waiting actions in the button.click.
Or:
await browser.wait(ExpectedConditions.titleIs('My title'));
Must be replaced by:
await expect(page).toHaveTitle('My title')
by.model(...)
and by.repeater(...)
are converted into [ng-model="..."]
and [ng-repeat*="..."]
selectors, but the logic in Protractor is more complex (see here for ng-model and here for ng-repeat). You'll have to adapt them if needed.This tool is designed to help the migration by doing as much as possible, but the migration may have to be completed manually.
If you detect a generic case which can be handled by the tool, don't hesitate to contact us. Some specific cases are project dependant, and must be managed by the project developers to finish the migration.
FAQs
Command line tool that automatically migrates tests from protractor to playwright.
The npm package @amadeus-it-group/protractor-to-playwright receives a total of 5 weekly downloads. As such, @amadeus-it-group/protractor-to-playwright popularity was classified as not popular.
We found that @amadeus-it-group/protractor-to-playwright demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.