Skip to content

Commit

Permalink
Merge pull request #1 from go-bazzinga/playwright_testing
Browse files Browse the repository at this point in the history
automation testing using playwright
  • Loading branch information
shreybaz authored May 20, 2024
2 parents 9d233c6 + 4f8d4c3 commit 40af8b3
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 59 deletions.
49 changes: 34 additions & 15 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Generate lighthouse test report on PR
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
repository_dispatch:
Expand All @@ -21,27 +19,48 @@ jobs:
node-version: 20
- run: npm install

- name: Install Lighthouse
run: npm install -g @lhci/[email protected]

- name: Run Lighthouse
# run: lhci autorun --upload.githubToken="$LHCI_GITHUB_TOKEN" || echo "LHCI failed!"
run: lhci autorun
# env:
# LHCI_GITHUB_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}

- name: install playwright
run: npx playwright install

- name: run playwright
id: tests
# run: TESTPARAM=${{secrets.MAIL_PASSWORD}} npx playwright test --project=firefox
run: npx playwright test --project=firefox
run: TESTPARAM='${{ secrets.TESTING_MAIL_PASSWORD }}' npx playwright test --project=firefox
continue-on-error: true

# add playwright test report artifact to pipeline
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Notify on Google Chat
uses: Co-qn/google-chat-notification@v1
with:
name: test
url: ${{ secrets.TEST_GOOGLE_CHAT_WEBHOOK_URL }}
status: ${{ steps.tests.outcome }}

# - name: Check test result and comment
# uses: peter-evans/create-or-update-comment@v1
# with:
# token: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
# token: ${{ secrets.GITHUB_APP_TOKEN }}
# issue-number: ${{ github.event.pull_request.number }}
# body: |
# ${{ steps.tests.outcome == '2 passed' && 'Test passed :heavy_check_mark:' || 'Test failed, Please check logs for details.' }}
# ${{ steps.tests.outcome == 'failed' && 'Test failed, Please check logs for details.' || 'Test passed :heavy_check_mark:' }}


- uses: actions/checkout@master
- run: mkdir -p ${{ github.workspace }}/tmp/artifacts
- name: Lighthouse
uses: foo-software/lighthouse-check-action@master
with:
outputDirectory: ${{ github.workspace }}/tmp/artifacts
gitHubAccessToken: ${{ secrets.POST_DEPLOY_TARGET_GITHUB_APP_TOKEN }}
urls: 'https://yral.com/'
- name: Upload artifacts
uses: actions/upload-artifact@master
with:
name: Lighthouse reports
path: ${{ github.workspace }}/tmp/artifacts
Binary file added test1.mp4
Binary file not shown.
145 changes: 101 additions & 44 deletions tests/example.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { chromium } from 'playwright';
import { test, expect } from '@playwright/test';

test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -35,9 +36,11 @@ test.describe('New test', () => {

// click unmute button
await page.locator('.fixed').first().click();
await page.waitForTimeout(3000);
await page.waitForTimeout(1000);
// // css selector of unmute button
// const buttonLocator = page.locator('body > main > div.h-full.w-full.overflow-hidden.overflow-y-auto > div > button > svg > path').click();
// await expect(video).toHaveAttribute('muted');
// console.log("is muted");

let video_new = page.locator('video').nth(0);
// await expect(video_new).not.toHaveAttribute('muted');
Expand Down Expand Up @@ -72,7 +75,7 @@ test.describe('New test', () => {
const new_duration = await new_video.evaluate(new_video => new_video.duration);
console.log('2nd Video Duration:', new_duration);

await page.waitForTimeout(3000);
// await page.waitForTimeout(3000);

//scroll to new video based on its locator
let third_video = page.locator('video').nth(5);
Expand All @@ -88,66 +91,65 @@ test.describe('New test', () => {
const third_duration = await third_video.evaluate(new_video => new_video.duration);
console.log('3rd Video Duration:', third_duration);

// await page.waitForTimeout(3000);

});

// test('Test google login', async ({page}) => {
test('Test google login', async ({page}) => {

// // login from wallet: using headfull mode
// try {
// console.log('Log in test');
// login from wallet: using headfull mode
try {
console.log('Log in test');

// // const environment_pass = global.expect;
// const environment_pass = process.env.TESTPARAM;

// await page.waitForTimeout(3000);

// await page.getByRole('navigation').getByRole('link').nth(3).click();
// await page.getByRole('button', { name: 'Login to claim your COYNs' }).click();
// const page1Promise = page.waitForEvent('popup');
// await page.getByRole('button', { name: 'Google Sign-In' }).click();
// const page1 = await page1Promise;
// await page1.getByLabel('Email or phone').click();
// await page1.getByLabel('Email or phone').fill('[email protected]');
// const environment_pass = global.expect;
const environment_pass = process.env.TESTPARAM;

await page.waitForTimeout(3000);

await page.getByRole('navigation').getByRole('link').nth(3).click();
await page.getByRole('button', { name: 'Login to claim your COYNs' }).click();
const page1Promise = page.waitForEvent('popup');
await page.getByRole('button', { name: 'Google Sign-In' }).click();
const page1 = await page1Promise;
await page1.getByLabel('Email or phone').click();
await page1.getByLabel('Email or phone').fill('[email protected]');

// await page.waitForTimeout(2000);
// await page1.getByLabel('Email or phone').press('Enter');
await page.waitForTimeout(2000);
await page1.getByLabel('Email or phone').press('Enter');

// await page1.getByLabel('Enter your password').click();
// await page1.getByLabel('Enter your password').fill(environment_pass);
// await page.waitForTimeout(2000);
await page1.getByLabel('Enter your password').click();
await page1.getByLabel('Enter your password').fill(environment_pass);
await page.waitForTimeout(2000);

// await page1.getByLabel('Enter your password').press('Enter');
// // await page1.pause();
// await page.waitForTimeout(3000);
await page1.getByLabel('Enter your password').press('Enter');
// await page1.pause();
await page.waitForTimeout(3000);

// console.log('Logged in succesfully');
// // await page.getByRole('navigation').getByRole('link').first().click();
console.log('Logged in succesfully');
// await page.getByRole('navigation').getByRole('link').first().click();

// await page.waitForTimeout(3000);
// //request to the API endpoint to fetch the response
// const response = await fetch('https://yral-metadata.fly.dev/metadata/gzlng-jqzta-5kubz-4nyam-5so2e-tsoio-ijv2s-47dsw-7ksd7-pe3eb-zqe');
// await page.waitForTimeout(2000);
await page.waitForTimeout(3000);
//request to the API endpoint to fetch the response
const response = await fetch('https://yral-metadata.fly.dev/metadata/gzlng-jqzta-5kubz-4nyam-5so2e-tsoio-ijv2s-47dsw-7ksd7-pe3eb-zqe');
await page.waitForTimeout(2000);

// console.log(response.status);
// const responseData = await response.json();
// console.log(responseData);
console.log(response.status);
const responseData = await response.json();
console.log(responseData);

// } catch (error) {
// console.error("error in login");
// }
// });
} catch (error) {
console.error("error in login");
}
});

// test('TEST UPLOAD FLOW', async ({page}) => {

// // login from wallet: using headfull mode
// console.log('Uploading test');

// await page.waitForTimeout(2000);

// await page.getByRole('navigation').getByRole('link').nth(2).click();

// await page.setInputFiles('#dropzone-file', './test1.mp4');
// await page.setInputFiles('#dropzone-file', './test3.mp4');

// // TODO
// // //endpoint to fetch the response
Expand All @@ -160,15 +162,32 @@ test.describe('New test', () => {
// // expect(responseData.status).toBe(200);

// await page.getByPlaceholder('Write your description here..').click();
// await page.getByPlaceholder('Write your description here..').fill('test video upload');
// await page.getByPlaceholder('Write your description here..').fill('Monica Dance video');
// await page.getByPlaceholder('#hashtag1,#hashtag2,#hashtag3').click();
// await page.getByPlaceholder('#hashtag1,#hashtag2,#hashtag3').fill('#try');

// // const button =
// // await button.click('button[data-api-trigger="true"]');

// await page.getByRole('button', { name: 'Upload Video' }).click();
// await page.pause();

// console.log('Uploading .. .. ..');

// //wait for upload to complete, Continue Browsing button to appear
// // await page.waitForSelector('button[name="Continue Browsing"]', { state: 'visible' });

// // Wait for the button with the name 'Continue Browsing' to become clickable
// await page.waitForFunction(() => {
// const button = document.querySelector('button[name="Continue Browsing"]');
// return button && !button.disabled;
// });

// // await page.waitForTimeout(20000);

// // await getByRole('button', { name: 'Continue Browsing' }).click();
// // // await page.pause();

// console.log('Uploaded succesfully');

// // await button.click('button[data-api-trigger="true"]');

Expand All @@ -177,4 +196,42 @@ test.describe('New test', () => {

// });

// //test like functionality
// test('Test like', async ({page}) => {

// // login from wallet: using headfull mode
// // try {
// console.log('test like');

// await page.waitForTimeout(1000);

// let likes_locator = page.locator('.flex > div:nth-child(2) > .flex > .text-sm').first();
// let total_likes = await likes_locator.textContent();
// console.log("total likes: ", total_likes );

// await page.waitForTimeout(15000);

// await expect(page.locator('button').first()).toBeVisible();
// console.log('like button visible');

// //click like button
// await page.locator('button').first().click();
// // await page.locator('body > main > div.h-full.w-full.overflow-hidden.overflow-y-auto > div > div:nth-child(2) > div > div.flex.flex-row.flex-nowrap.justify-between.items-end.pb-16.px-2.md\:px-6.w-full.text-white.absolute.bottom-0.left-0.bg-transparent.z-\[4\] > div.flex.flex-col.gap-6.items-end.w-3\/12.text-4xl > div > button > svg > path').click();
// await page.waitForTimeout(2000);

// let new_likes_locator = page.locator('.flex > div:nth-child(2) > .flex > .text-sm').first();
// let updated_likes = await new_likes_locator.textContent();
// console.log("updated total likes: ", updated_likes );

// expect(parseInt(updated_likes)).toBe(parseInt(total_likes) + 1);
// // let new_like_count = expect(page.getByRole('main'));
// // console.log("new like count: ", new_like_count );

// // await expect(page.getByRole('main')).toContainText(like_count + 1);

// // } catch (error) {
// // console.error("error in login");
// // }
// });

});
46 changes: 46 additions & 0 deletions tests/like.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { test, expect } from '@playwright/test';

test.beforeEach(async ({ page }) => {
await page.goto('https://yral.com/');
});

test.describe('New test', () => {
//test like functionality
test('Test like', async ({page}) => {

// login from wallet: using headfull mode
// try {
console.log('test like');

await page.waitForTimeout(1000);

let likes_locator = page.locator('.flex > div:nth-child(2) > .flex > .text-sm').first();
let total_likes = await likes_locator.textContent();
console.log("total likes: ", total_likes );

await page.waitForTimeout(15000);

await expect(page.locator('button').first()).toBeVisible();
console.log('like button visible');

//click like button
await page.locator('button').first().click();
// await page.locator('body > main > div.h-full.w-full.overflow-hidden.overflow-y-auto > div > div:nth-child(2) > div > div.flex.flex-row.flex-nowrap.justify-between.items-end.pb-16.px-2.md\:px-6.w-full.text-white.absolute.bottom-0.left-0.bg-transparent.z-\[4\] > div.flex.flex-col.gap-6.items-end.w-3\/12.text-4xl > div > button > svg > path').click();
await page.waitForTimeout(2000);

let new_likes_locator = page.locator('.flex > div:nth-child(2) > .flex > .text-sm').first();
let updated_likes = await new_likes_locator.textContent();
console.log("updated total likes: ", updated_likes );

expect(parseInt(updated_likes)).toBe(parseInt(total_likes) + 1);
// let new_like_count = expect(page.getByRole('main'));
// console.log("new like count: ", new_like_count );

// await expect(page.getByRole('main')).toContainText(like_count + 1);

// } catch (error) {
// console.error("error in login");
// }
});

})
Loading

0 comments on commit 40af8b3

Please sign in to comment.