Skip to content

Instantly share code, notes, and snippets.

View nadvolod's full-sized avatar
🏖️
Just living the good life

Nikolay Advolodkin nadvolod

🏖️
Just living the good life
View GitHub Profile
@nadvolod
nadvolod / loginPage.ts
Last active February 3, 2023 19:00
Is this a good page object using playwright and typescript?
export class LoginPage {
readonly page: Page;
readonly userNameTextbox: Locator
readonly passwordTextbox: Locator
readonly loginBtn: Locator
// Clarity over duplication removal
// Don't start with the abstraction
constructor(page: Page) {
this.page = page;
@nadvolod
nadvolod / playwright.spec.ts
Last active February 1, 2023 19:44
Flawed automated playwright tests
test('Dashboard page should not have any WCAG A violations', async ({ page }) => {
const authentication = new Authentication(page);
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
await loginPage.login(user)
// Wait until the logo is visible - default 30000
await dashboardPage.waitForLogo()
await page.getByRole('button', { name: 'Log In' }).click();
await authentication.loginWith2FA(user)
@nadvolod
nadvolod / UsingWebDriverManager.java
Last active January 17, 2023 19:47
How to use WebDriverManager with Junit 4
import io.github.bonigarcia.wdm.WebDriverManager;
//This method will run once before all of the tests in our class
@BeforeClass
public static void setupClass() {
WebDriverManager.chromedriver().setup();
}
//The setup() will run one time before every single @Test method
//In our case it will instantiate a new ChromeDriver that WebDriverManager setup for us
@Before
import { expect, Locator, Page } from '@playwright/test';
const userNameFieldLoc = '[id="user-name"]'
const passwordFieldLoc = '[id="password"]'
const loginButtonLoc = '[id="login-button"]'
const errorloc = '[data-test="error"]'
const headerLoc = '[class="title"]'
const burgerMenue = '[id="react-burger-menu-btn"]'
const aboutButtonLoc = '[id="about_sidebar_link"]'
export default class LoginPage{
const page = await context.newPage();
await page.goto('/');
const loginPage = new LoginPage(page)
//option 1
await loginPage.login(data)
//option 2
await loginPage.userNameFill(userData.standart)
await loginPage.userPasswordFill(userData.correctPassword)
await loginPage.loginButtonClick()
await loginPage.burgerMenuClick()
test('User can create GPW record', async ({page}) => {
await dashboardPage.createNewModule(dataModule)
// What if instead of comments, our code was self readable?
// Verify that module has name: [newModule] is created
const expectedMessage = `SuccessModule "${content}" was created.Close`
expect(dashboardPage.isModuleCreated(newModule).toEqual(expectedMessage)
await dashboardPage.isModuleCreated(newModule)
// Remove the new module to avoid spam
await dashboardPage.goToHomePage()
@nadvolod
nadvolod / happo.spec.ts
Created November 18, 2022 15:15
An example of a working Happo.io test using Playwright
// @ts-check
import { test } from '@playwright/test';
const happoPlaywright = require('happo-playwright');
test.describe('Sitefinity CMS', () => {
test.beforeEach(async ({ page }) => {
await happoPlaywright.init(page);
await page.goto('https://afro.who.int/countries');
await page.waitForLoadState('networkidle');
await page.isVisible('[alt=Countries]');
@nadvolod
nadvolod / happo.js
Created October 9, 2022 14:52
Working happo test
import { Page, test } from '@playwright/test';
const happoPlaywright = require('happo-playwright');
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
await happoPlaywright.init(page);
});
@nadvolod
nadvolod / cypress.config.ts
Last active September 15, 2022 18:51
Failing cy.open() command
const { defineConfig } = require("cypress");
export default defineConfig({
e2e: {
// this URL keeps automatically failing the test
baseUrl: "https://who--spmstage.sandbox.lightning.force.com/lightning/page/home",
failOnStatusCode: false,
setupNodeEvents(on, config) {
// implement node event listeners here
},
@RunWith(Parameterized.class)
public class DesktopTests extends SauceBaseTest {
/*
* Configure our data driven parameters
* */
@Parameterized.Parameter
public Browser browserName;
@Parameterized.Parameter(1)
public String browserVersion;
@Parameterized.Parameter(2)