Please, write me an automation framework using Typescript Cucumber Playwright, put page…
- User
Please, write me an automation framework using Typescript Cucumber Playwright, put page initialization into hooks file, use page object pattern: Prerequisite: Go to https://enotes.pointschool.ru/login The user is authorized in the system (username 'test', password 'test') Shopping cart is empty Steps: Click on the shopping cart icon - The shopping cart window pops up.
- Assistant
Sure! Here's an example of an automation framework using Typescript, Cucumber, and Playwright, with page initialization in hooks file and using the page object pattern:
First, let's set up the project by installing the required dependencies:
npm init -y npm install --save-dev typescript cucumber playwrightNext, configure the project by creating a
tsconfig.jsonfile:{ "compilerOptions": { "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, "sourceMap": true }, "include": [ "src/**/*.ts" ], "exclude": [ "node_modules" ] }Create a
featuresfolder in the project root directory. Inside thefeaturesfolder, create a file namedshopping_cart.feature:Feature: Shopping Cart As a user I want to view and interact with the shopping cart Scenario: View shopping cart Given the user is authorized in the system And the shopping cart is empty When the user clicks on the shopping cart icon Then the shopping cart window pops upNow, create a
stepsfolder inside thefeaturesdirectory. Inside thestepsfolder, create a file namedshopping_cart_steps.ts:import { Given, When, Then } from 'cucumber'; import { LoginPage } from '../pages/loginPage'; import { HomePage } from '../pages/homePage'; const loginPage = new LoginPage(); const homePage = new HomePage(); Given(/^the user is authorized in the system$/, async () => { await loginPage.login('test', 'test'); }); Given(/^the shopping cart is empty$/, async () => { await homePage.emptyShoppingCart(); }); When(/^the user clicks on the shopping cart icon$/, async () => { await homePage.clickShoppingCartIcon(); }); Then(/^the shopping cart window pops up$/, async () => { const isShoppingCartWindowVisible = await homePage.isShoppingCartWindowVisible(); expect(isShoppingCartWindowVisible).toBe(true); });Create a
pagesfolder in the project root directory. Inside thepagesfolder, create a file namedloginPage.ts:import { Page } from 'playwright'; export class LoginPage { page: Page; constructor(page: Page) { this.page = page; } async login(username: string, password: string) { await this.page.goto('https://enotes.pointschool.ru/login'); await this.page.fill('#username', username); await this.page.fill('#password', password); await this.page.click('button[name="login-button"]'); } }Create another file named
homePage.tsinside thepagesfolder:import { Page } from 'playwright'; export class HomePage { page: Page; constructor(page: Page) { this.page = page; } async emptyShoppingCart() { // Code to empty the shopping cart } async clickShoppingCartIcon() { // Code to click the shopping cart icon } async isShoppingCartWindowVisible(): Promise<boolean> { // Code to check if the shopping cart window is visible return false; } }Finally, create a
hooks.tsfile in the project root directory:import { Before, After } from 'cucumber'; import { Browser, Page } from 'playwright'; let browser: Browser; let page: Page; Before(async () => { browser = await playwright.chromium.launch(); page = await browser.newPage(); }); After(async () => { await page.close(); await browser.close(); });Now, you should have the automation framework set up using Typescript, Cucumber, and Playwright. You can run your tests by executing the following command:
npx cucumber-jsMake sure to adjust the implementation details inside the page objects according to your specific application.
- User
Please, edit this feedback for the course. Really good course, I enjoyed it. Cool, that all information divided into smaller parts, easy to watch and learn. I’d like to ask you to add video for Form automation lab, where you can add additional information about opportunities of this tool, for example, how to work with conditions or workflows, action steps. Just to understand how we can use it to make a flow a little bit more complicated. The similar thing for Process automation lab, just to add video with opportunities for automation, not to use them in lab, but to mention which business process we can automate and which steps are the most popular.
- Assistant
The course was excellent, and I thoroughly enjoyed it. I particularly appreciated how the information was divided into smaller, easily digestible parts, which made it much easier to follow along and learn.
I have a suggestion for improvement. It would be great if you could add a video specifically for the Form Automation Lab. In this video, you could provide additional information about the capabilities of the tool, such as how to work with conditions, workflows, and action steps. This would help us understand how we can use the tool to create more complex flows.
Similarly, for the Process Automation Lab, it would be beneficial to include a video that explains the various automation opportunities available and highlights the most popular steps involved. This would provide us with a better understanding of which business processes can be automated using the tool.
Overall, I believe these additional videos would enhance the learning experience and help us better utilize the tool's capabilities.
- User
Edit the text: Maybe, this is a platform error, but each time when I marked lab as completed I'd got an error on the screen.
- Assistant
It appears there might be a platform error, as I consistently encountered an error on the screen whenever I marked a lab as completed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.