Skip to content

Commit

Permalink
Fixing Same Routes for Screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadHassan03 committed Aug 19, 2024
1 parent b3c55c2 commit 5b23894
Show file tree
Hide file tree
Showing 38 changed files with 49 additions and 26 deletions.
14 changes: 14 additions & 0 deletions packages/playwright/helper-login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const helperLogin = async (page) => {
console.log('Navigating to Login Page for Signing in');
await page.goto('https://packrat.world/', { waitUntil: 'networkidle' });
await page.getByRole('link', { name: 'Get Started' }).click();

await page.locator('input[type="email"]').click();
await page.locator('input[type="email"]').fill('[email protected]');
await page.locator('input[type="password"]').click();
await page.locator('input[type="password"]').fill('12345678');
await page.getByRole('button', { name: 'Sign In' }).click();
console.log('Waiting for dashboard to load...');

};
module.exports = { helperLogin };
57 changes: 33 additions & 24 deletions packages/playwright/sc-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,70 @@ const { chromium } = require('playwright');
const fs = require('fs');
const path = require('path');
const { url } = require('inspector');

const { helperLogin } = require('./helper-login');

(async () => {
const screenshotsDir = path.join(__dirname, 'screenshots');
const filename = path.basename(__filename, path.extname(__filename));
const screenshotsDir = path.join(__dirname, 'screenshots', filename);
if (!fs.existsSync(screenshotsDir)) {
fs.mkdirSync(screenshotsDir);
}


const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();


// Capture console logs
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
page.on('console', (msg) => console.log('PAGE LOG:', msg.text()));
// Capture page errors
page.on('pageerror', error => console.error('PAGE ERROR:', error));

page.on('pageerror', (error) => console.error('PAGE ERROR:', error));

const resolutions = [
{ width: 1920, height: 1080, name: 'desktop' },
{ width: 3440, height: 1440, name: 'big desktop screen' },
{ width: 1280, height: 800, name: 'tablet' },
{ width: 1366, height: 1024, name: 'iPad Pro'},
{ width: 375, height: 667, name: 'small mobile' },
{ width: 390, height: 844, name: 'Android mobile'},
{ width: 393, height: 852, name: 'iPhone'},
{ width: 430, height: 932, name: 'iPhone Pro Max'},
{ width: 1366, height: 768, name: 'laptop'},


{ width: 1366, height: 1024, name: 'iPad Pro' },
{ width: 375, height: 667, name: 'small mobile' },
{ width: 390, height: 844, name: 'Android mobile' },
{ width: 393, height: 852, name: 'iPhone' },
{ width: 430, height: 932, name: 'iPhone Pro Max' },
{ width: 1366, height: 768, name: 'laptop' },
];


const pages = [
{ url: 'https://packrat.world/',name: 'dashboard'},

{ url: 'https://packrat.world/', name: 'dashboard' },
{
url: 'https://packrat.world/',
name: 'landing-page',
identify: async (page) => helperLogin(page),
},
];


for (const resolution of resolutions) {
await page.setViewportSize({ width: resolution.width, height: resolution.height });
for (const { url, name } of pages) {
await page.setViewportSize({
width: resolution.width,
height: resolution.height,
});

for (const { url, name, identify } of pages) {
try {
console.log(`Navigating to ${url} at ${resolution.name} resolution...`);
await page.goto(url, { waitUntil: 'networkidle' });
console.log(`Taking full-page screenshot of ${url} at ${resolution.name} resolution...`);
await page.screenshot({ path: path.join(screenshotsDir, `${name}-${resolution.name}.png`), fullPage: false });
if (identify) {
await identify(page);
}
console.log(
`Taking full-page screenshot of ${url} at ${resolution.name} resolution...`,
);
await page.screenshot({
path: path.join(screenshotsDir, `${name}-${resolution.name}.png`),
fullPage: false,
});
} catch (error) {
console.error(`Failed to navigate to ${url}:`, error);
}
}
}


console.log('Closing browser...');
await browser.close();
})();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/playwright/screenshots/log in-laptop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/playwright/screenshots/log in-tablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const app = new Hono<{ Bindings: Bindings }>();
// ref: https://hono.dev/middleware/builtin/compress

// SETUP HTTPS Enforcement Middleware
app.use('*', enforceHttps()); // Apply to all routes
// app.use('*', enforceHttps()); // Apply to all routes

// SETUP SECURITY HEADERS
app.use('*', securityHeaders()); // Apply to all routes
// app.use('*', securityHeaders()); // Apply to all routes

// SETUP CORS
app.use('*', async (c, next) => {
Expand Down

0 comments on commit 5b23894

Please sign in to comment.