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 / TestOrderDependency.java
Created February 20, 2024 13:07
Test ordering problem
// Problem: Test order dependency
@FixMethodOrder(MethodSorters.NAME_ASCENDING) // This ensures the test methods are executed in lexicographical order by their names
public class TestOrderDependency {
private static WebDriver driver;
@BeforeClass
public static void setUpClass() throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "chrome");
package com.saucelabs.saucebindings.junit4.examples;
public class ConditionTester {
private boolean actionDone;
public boolean option1(boolean conditionA, boolean conditionB) {
if (!conditionA) {
actionDone = true; // Represents "Another action"
return actionDone;
}
@nadvolod
nadvolod / DataFactory.ts
Created September 3, 2023 19:07
Using a Data Factory with Playwright and TypeScript
interface UserData {
username: string;
password: string;
}
interface AddressData {
street: string;
city: string;
zipCode: string;
}
//usage
const actualQuantity =
await locationInventoryPage.getQuantityColumnValueUsing(adjustment.receiptData.lotNumber);
const actualQuantity =
await locationInventoryPage.getInventoryQuantityUsing(adjustment.receiptData.lotNumber);
async getQuantityColumnValue(item: string): Promise<string> {
return this.getInventoryQuantityCellFromRowUsingOtherLabelSelector(item).innerText();
}
@nadvolod
nadvolod / Solution1.java
Created March 19, 2023 15:54
JUnit 4 Exercise Solutions
// Solution to 1
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class AdditionTest {
@Test
public void testSum() {
int sum = 3 + 4;
int expectedSum = 7;
@nadvolod
nadvolod / .gitpod.Dockerfile
Created February 19, 2023 23:58
How to run Selenium tests in GitPod
FROM gitpod/workspace-full-vnc:latest
USER gitpod
RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \
sdk install java 17.0.3-ms && \
sdk default java 17.0.3-ms"
# Install dependencies.
RUN sudo apt-get update \
@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)
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()