webdriverio/website/i18n/ar/docusaurus-plugin-content-docs/current/ProtractorMigration.md
Christian Bromann 11242e8f15
New Crowdin updates (#10370)
* New translations GettingStarted.md (Polish)

* New translations GettingStarted.md (Tamil)

* New translations GettingStarted.md (French)

* New translations GettingStarted.md (Spanish)

* New translations GettingStarted.md (German)

* New translations GettingStarted.md (Russian)

* New translations GettingStarted.md (Ukrainian)

* New translations GettingStarted.md (Chinese Simplified)

* New translations GettingStarted.md (Persian)

* New translations GettingStarted.md (Hindi)

* New translations Browser.md (Chinese Simplified)

* New translations BoilerplateProjects.md (Chinese Simplified)

* New translations Capabilities.md (Chinese Simplified)

* New translations Configuration.md (Chinese Simplified)

* New translations Protocols.md (Chinese Simplified)

* New translations GettingStarted.md (Chinese Simplified)

* New translations API.md (Chinese Simplified)

* New translations Accessibility.md (Chinese Simplified)

* New translations Assertion.md (Chinese Simplified)

* New translations AutoWait.md (Chinese Simplified)

* New translations Autocompletion.md (Chinese Simplified)

* New translations AutomationProtocols.md (Chinese Simplified)

* New translations BambooIntegration.md (Chinese Simplified)

* New translations CloudServices.md (Chinese Simplified)

* New translations ComponentTesting.md (Chinese Simplified)

* New translations ConfigurationFile.md (Chinese Simplified)

* New translations CustomCommands.md (Chinese Simplified)

* New translations CustomReporter.md (Chinese Simplified)

* New translations CustomServices.md (Chinese Simplified)

* New translations Debugging.md (Chinese Simplified)

* New translations Docker.md (Chinese Simplified)

* New translations DriverBinaries.md (Chinese Simplified)

* New translations Enterprise.md (Chinese Simplified)

* New translations GithubActions.md (Chinese Simplified)

* New translations JenkinsIntegration.md (Chinese Simplified)

* New translations MocksAndSpies.md (Chinese Simplified)

* New translations Multiremote.md (Chinese Simplified)

* New translations OrganizingTestSuites.md (Chinese Simplified)

* New translations PageObjects.md (Chinese Simplified)

* New translations ProtractorMigration.md (Chinese Simplified)

* New translations Record.md (Chinese Simplified)

* New translations Retry.md (Chinese Simplified)

* New translations Runner.md (Chinese Simplified)

* New translations Selectors.md (Chinese Simplified)

* New translations SetupTypes.md (Chinese Simplified)

* New translations SyncAsyncMigration.md (Chinese Simplified)

* New translations Testrunner.md (Chinese Simplified)

* New translations Timeouts.md (Chinese Simplified)

* New translations TypeScript.md (Chinese Simplified)

* New translations WatchFiles.md (Chinese Simplified)

* New translations WhyWebdriverIO.md (Chinese Simplified)

* New translations Element.md (Chinese Simplified)

* New translations Environment.md (Chinese Simplified)

* New translations Globals.md (Chinese Simplified)

* New translations Mock.md (Chinese Simplified)

* New translations Modules.md (Chinese Simplified)

* New translations Lit.md (Chinese Simplified)

* New translations Preact.md (Chinese Simplified)

* New translations React.md (Chinese Simplified)

* New translations Solid.md (Chinese Simplified)

* New translations Svelte.md (Chinese Simplified)

* New translations Vue.md (Chinese Simplified)

* New translations mocking.md (Chinese Simplified)

* New translations repl.md (Chinese Simplified)

* New translations v6Migration.md (Chinese Simplified)

* New translations v7Migration.md (Chinese Simplified)

* New translations Donate.md (Chinese Simplified)

* New translations Materials.md (Chinese Simplified)

* New translations OpenOfficeHours.md (Chinese Simplified)

* New translations Support.md (Chinese Simplified)

* New translations WebExtensionTesting.md (Chinese Simplified)

* New translations TipsAndTricks.md (Chinese Simplified)

* New translations Donate.md (Tamil)

* New translations Donate.md (Tamil)

* New translations Donate.md (Tamil)

* New translations Materials.md (Tamil)

* New translations OpenOfficeHours.md (Tamil)

* New translations CreateLocalWorkerProcess.md (Tamil)

* New translations HighLevelOverview.md (Tamil)

* New translations TestExecution.md (Tamil)

* New translations Support.md (Tamil)

* New translations Team.md (Tamil)

* New translations TestExecution.md (Tamil)

* New translations WDIOCommands.md (Tamil)

* New translations TipsAndTricks.md (Tamil)

* New translations Appium.md (Tamil)

* New translations code.json (Arabic)

* New translations options.json (Arabic)

* New translations current.json (Arabic)

* New translations current.json (Arabic)

* New translations footer.json (Arabic)

* New translations navbar.json (Arabic)

* New translations API.md (Arabic)

* New translations Accessibility.md (Arabic)

* New translations Assertion.md (Arabic)

* New translations AutoWait.md (Arabic)

* New translations Autocompletion.md (Arabic)

* New translations AutomationProtocols.md (Arabic)

* New translations Babel.md (Arabic)

* New translations BambooIntegration.md (Arabic)

* New translations BoilerplateProjects.md (Arabic)

* New translations Capabilities.md (Arabic)

* New translations CloudServices.md (Arabic)

* New translations ComponentTesting.md (Arabic)

* New translations Configuration.md (Arabic)

* New translations ConfigurationFile.md (Arabic)

* New translations CustomCommands.md (Arabic)

* New translations CustomReporter.md (Arabic)

* New translations CustomServices.md (Arabic)

* New translations Debugging.md (Arabic)

* New translations Docker.md (Arabic)

* New translations DriverBinaries.md (Arabic)

* New translations Enterprise.md (Arabic)

* New translations Flowcharts.md (Arabic)

* New translations Frameworks.md (Arabic)

* New translations GettingStarted.md (Arabic)

* New translations GithubActions.md (Arabic)

* New translations JenkinsIntegration.md (Arabic)

* New translations MocksAndSpies.md (Arabic)

* New translations Multiremote.md (Arabic)

* New translations OrganizingTestSuites.md (Arabic)

* New translations PageObjects.md (Arabic)

* New translations ProtractorMigration.md (Arabic)

* New translations Proxy.md (Arabic)

* New translations Record.md (Arabic)

* New translations Retry.md (Arabic)

* New translations Runner.md (Arabic)

* New translations Selectors.md (Arabic)

* New translations SetupTypes.md (Arabic)

* New translations SyncAsyncMigration.md (Arabic)

* New translations Testrunner.md (Arabic)

* New translations Timeouts.md (Arabic)

* New translations TypeScript.md (Arabic)

* New translations WatchFiles.md (Arabic)

* New translations WhyWebdriverIO.md (Arabic)

* New translations Browser.md (Arabic)

* New translations Element.md (Arabic)

* New translations Environment.md (Arabic)

* New translations Globals.md (Arabic)

* New translations Mock.md (Arabic)

* New translations Modules.md (Arabic)

* New translations Protocols.md (Arabic)

* New translations Lit.md (Arabic)

* New translations Preact.md (Arabic)

* New translations React.md (Arabic)

* New translations Solid.md (Arabic)

* New translations Svelte.md (Arabic)

* New translations Vue.md (Arabic)

* New translations coverage.md (Arabic)

* New translations mocking.md (Arabic)

* New translations CreateLocalWorkerProcess.md (Arabic)

* New translations HighLevelOverview.md (Arabic)

* New translations TestExecution.md (Arabic)

* New translations WDIOCommands.md (Arabic)

* New translations repl.md (Arabic)

* New translations v6Migration.md (Arabic)

* New translations v7Migration.md (Arabic)

* New translations Donate.md (Arabic)

* New translations Materials.md (Arabic)

* New translations OpenOfficeHours.md (Arabic)

* New translations Support.md (Arabic)

* New translations Team.md (Arabic)

* New translations WebExtensionTesting.md (Arabic)

* New translations TipsAndTricks.md (Arabic)

* New translations Appium.md (Arabic)

* New translations Support.md (Polish)

* New translations Browser.md (Polish)

* New translations Support.md (Polish)

* New translations Team.md (Polish)

* New translations Globals.md (Tamil)

* New translations Browser.md (Polish)

* New translations coverage.md (Tamil)

* New translations Browser.md (Polish)

* New translations API.md (Tamil)

* New translations API.md (Tamil)

* New translations Browser.md (Tamil)

* New translations Browser.md (Tamil)

* New translations Browser.md (Tamil)

* New translations Element.md (Tamil)

* New translations Lit.md (Tamil)

* New translations React.md (Tamil)

* New translations React.md (Tamil)

* New translations Solid.md (Tamil)

* New translations Svelte.md (Tamil)

* New translations Preact.md (Tamil)

* New translations Solid.md (Tamil)

* New translations Svelte.md (Tamil)

* New translations Vue.md (Tamil)

* New translations coverage.md (Tamil)

* New translations Autocompletion.md (Tamil)

* New translations Preact.md (Tamil)

* New translations coverage.md (Tamil)

* New translations mocking.md (Tamil)

* New translations JenkinsIntegration.md (Tamil)

* New translations Vue.md (Tamil)

* New translations mocking.md (Tamil)

* New translations TipsAndTricks.md (Tamil)

* New translations JenkinsIntegration.md (Tamil)

* New translations repl.md (Tamil)

* New translations repl.md (Tamil)

* New translations Configuration.md (Persian)

* New translations Babel.md (Tamil)

* New translations BambooIntegration.md (Tamil)

* New translations repl.md (Tamil)

* New translations Configuration.md (Persian)

* New translations BambooIntegration.md (Tamil)

* New translations BambooIntegration.md (Tamil)

* New translations MocksAndSpies.md (Tamil)

* New translations MocksAndSpies.md (Tamil)

* New translations DriverBinaries.md (Tamil)

* New translations Flowcharts.md (Tamil)

* New translations MocksAndSpies.md (Tamil)
2023-05-15 09:01:21 +02:00

6.2 KiB

id title
protractor-migration From Protractor

This tutorial is for people who are using Protractor and want to migrate their framework to WebdriverIO. It was initiated after the Angular team has announced that Protractor won't be longer supported. WebdriverIO has been influenced by a lot of Protractors design decisions which is why it is probably the closest framework to migrate over. The WebdriverIO team appreciates the work of every single Protractor contributor and hopes that this tutorial makes the transition to WebdriverIO easy and straightforward.

While we would love to have a fully automated process for this the reality looks different. Everyone has a different setup and uses Protractor in different ways. Every step should be seen as guidance and less like a step by step instruction. If you have issues with the migration, don't hesitate to contact us.

Setup

The Protractor and WebdriverIO API is actually very similar, to a point where the majority of commands can be rewritten in an automted way through a codemod.

To install the codemod, run:

npm install jscodeshift @wdio/codemod

Strategy

There are many migration strategies. Depending on the size of your team, amount of test files and the urgency to migrate you can try to transform all tests at once or file by file. Given that Protractor will continued to be maintained until Angular version 15 (end of 2022) you still have enough time. You can have Protractor and WebdriverIO tests running at the same time and start writing new tests in WebdriverIO. Given your time budget you can then start migrating the important test cases first and work your way down to tests you might even can delete.

First the Config File

After we have installed the codemod we can start transforming the first file. Have a look first into WebdriverIOs configuration options. Config files can become very complex and it might make sense to only port the essential parts and see how the rest can be added once the corresponding tests that need certain options are being migrated.

For the first migration we only transform the config file and run:

npx jscodeshift -t ./node_modules/@wdio/codemod/protractor ./conf.ts

:::info

Your config can be named differently, however the principle should be the same: start migration the config first.

:::

Install WebdriverIO Dependencies

Next step is to configure a minimal WebdriverIO setup that we start building up as we migrate from one framework to another. First we install the WebdriverIO CLI via:

npm install --save-dev @wdio/cli

Next we run the configuration wizard:

npx wdio config

This will walk you through a couple of questions. For this migration scenario you:

  • pick the default choices
  • we recommend not to auto-generate example files
  • pick a different folder for WebdriverIO files
  • and to choose Mocha above Jasmine.

:::info Why Mocha? Even though you might have been using Protractor with Jasmine before, Mocha however provides better retry mechanisms. The choice is yours! :::

After the little questionaire the wizard will install all necessary packages and stores them in your package.json.

Migrate Configuration File

After we have a transformed conf.ts and a new wdio.conf.ts, it is now time to migrate the configuration from one config to another. Make sure to only port code that is essential for all tests to be able to run. In ours we port the hook function and framework timeout.

We will now continue with our wdio.conf.ts file only and therefore won't need any changes to the original Protractor config anymore. We can revert those so that both frameworks can run next to each other and we can port on file at the time.

Migrate Test File

We are now set to port over the first test file. To start simple, let's start with one that has not many dependencies to 3rd party packages or other files like PageObjects. In our example the first file to migrate is first-test.spec.ts. First create the directory where the new WebdriverIO configuration expects its files and then move it over:

mv mkdir -p ./test/specs/
mv test-suites/first-test.spec.ts ./test/specs

Now let's transform this file:

npx jscodeshift -t ./node_modules/@wdio/codemod/protractor ./test/specs/first-test.spec.ts

That's it! This file is so simple that we don't need any additional changes anymore and directly can try to run WebdriverIO via:

npx wdio run wdio.conf.ts

Congratulations 🥳 you just migrated the first file!

Next Steps

From this point you continue to transform test by test and page object by page object. There are chances that the codemod will fail for certain files with an error such as:

ERR /path/to/project/test/testdata/failing_submit.js Transformation error (Error transforming /test/testdata/failing_submit.js:2)
Error transforming /test/testdata/failing_submit.js:2

> login_form.submit()
  ^

The command "submit" is not supported in WebdriverIO. We advise to use the click command to click on the submit button instead. For more information on this configuration, see https://webdriver.io/docs/api/element/click.
  at /path/to/project/test/testdata/failing_submit.js:132:0

For some Protractor commands there is just no replacement for it in WebdriverIO. In this case the codemod will give you some advice how to refactor it. If you stumble upon such error messages too often, feel free to raise an issue and request to add a certain transformation. While the codemod already transforms the majority of the Protractor API there is still a lot of room for improvements.

Conclusion

We hope this tutorial guides you a little bit through the migration process to WebdriverIO. The community continues to improve the codemod while testing it with various teams in various organisations. Don't hesitate to raise an issue if you have feedback or start a discussion if you struggle during the migration process.