admin管理员组文章数量:1336320
I am using playwright in a Docker container that runs in AWS Batch env. I am able to successfully test from VS Code but it errors out as ERR_CERT_AUTHORITY_INVALID when it runs from a container.
These are my relevant pieces of code.
test.ts
import { test as base } from '@playwright/test';
import path from 'path';
import fs from 'fs';
import type { User } from './types';
const defaultPassword = 'xxxx';
export const test = base.extend<{ user: User }>({
user: { username: '' },
storageState: async ({ browser, user, baseURL }, use, testInfo) => {
if (!user.username) {
return;
}
const fileName = path.join(
testInfo.project.outputDir,
`storage-${user.username}-${testInfo.workerIndex}.json`
);
if (!fs.existsSync(fileName)) {
const page = await browser.newPage({ storageState: undefined });
await page.goto(baseURL ?? '/select-client');
await page.click('role=button[name="AGREE & CONTINUE"]');
await page.fill('#userName', user.username);
await page.fill('#password', user.password ?? defaultPassword);
await page.click('role=button[name="LOGIN"]');
await page.waitForTimeout(10000);
await page.context().storageState({ path: fileName });
}
console.log("Base URL:", baseURL);
await use(fileName);
},
});
export { expect } from '@playwright/test';
playwright.config.js
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
export default defineConfig({
testDir: './tests',
//testDir: path.join(__dirname, 'playwright', 'tests'),
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
workers: process.env.CI ? 1 : 1,
reporter: [
['html', { open: 'never' }],
['line'],
// ["allure-playwright", { outputFolder: "reports/allure" }],
['junit', { outputFile: 'reports/results.xml' }],
['json', { outputFile: 'reports/results.json' }],
],
/* Shared settings for all the projects below. See /docs/api/class-testoptions. */
use: {
ignoreHTTPSErrors: true,
viewport: { width: 1920, height: 1080 },
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
trace: 'on-first-retry',
baseURL: '',
screenshot: 'only-on-failure',
headless: true,
storageState: 'storage.json',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
ignoreHTTPSErrors: true,
},
],
});
test case spec file:
import { Page, Locator, chromium } from '@playwright/test';
import { TransactionTypesPage } from '../../pages/transactionTypes.js';
import { CommonActions } from '../../pages/commonMethods';
import { LoginPage } from '../../pages/login';
import { test, expect } from '../../module/test';
import { imUser } from '../../module/users';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const today = new Date();
const todayDtTime = today.toISOString().replace(/[:T.]/g, '-').slice(0, -5);
let txnDetails = new TransactionTypeDetails();
test.describe('Transaction Types Test Set', () => {
console.log('Current working directory in test:', process.cwd());
test.use({ user: imUser, ignoreHTTPSErrors: true });
let page;
let transTypePage;
let commonActions;
let loginPage;
test.beforeAll(async ({ browser, baseURL }) => {
//const context = await browser.newContext({ ignoreHTTPSErrors: true });
page = await browser.newPage();
await page.route(() => true, (route) => {
route.fulfill( { status: 403, })
});
page = await browser.newPage();
transTypePage = new TransactionTypesPage(page);
commonActions = new CommonActions(page);
loginPage = new LoginPage(page);
await page.goto('/select-client', { timeout: 6000, waitUntil: 'networkidle' });
await page.waitForLoadState('networkidle');
console.log("Base URL----> ", page.url());
await loginPage.loginForStaticDataClient();
await page.waitForTimeout(3000);
await commonActions.clickAdminLink();
await page.waitForTimeout(3000);
await transTypePage.clickTransactionTypesLink();
await page.waitForTimeout(1000);
});
test('Click ADD NEW button', async () => {
await commonActions.clickAddNewButton();
await page.waitForTimeout(1000);
});
test('Enter Name', async() => {
await transTypePage.enterName("PW-Test-Name-" + todayDtTime);
txnDetails.name = "PW-Test-Name-" + todayDtTime
});
test('More tests...')
I also have the Dockerfile with this content:
FROM mcr.microsoft/playwright:latest
ENV CI=true
ENV NODE_TLS_REJECT_UNAUTHORIZED=0
RUN apt-get update && apt-get install -y ca-certificates \
&& update-ca-certificates
# Set the working directory in the container
WORKDIR /usr/src/app/csg-treasury-web-ui-app
# Install dependencies for AWS CLI installation
RUN apt-get update && apt-get install -y \
unzip \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install AWS CLI v2
RUN curl ".zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm awscliv2.zip \
&& rm -rf aws
RUN echo "AWS CLI installation successful"
# Install Playwright browsers
RUN npx playwright install chromium
RUN echo "Playwright and Chromium installation successful"
# Copy package.json and package-lock.json (if available)
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of your project files
COPY . .
RUN pwd
RUN ls -lt
# Install Playwright browsers
RUN npx playwright install
RUN echo playwright install successful
RUN pwd
RUN chmod +x ./run.sh
RUN echo "Playwright version is:"
RUN npx playwright --version
# Change the working directory to the playwright folder
RUN echo "Change dir to playwright in the container..."
WORKDIR /usr/src/app/csg-treasury-web-ui-app/playwright
RUN pwd
RUN ls -lt
CMD ["bash", "/usr/src/app/csg-treasury-web-ui-app/run.sh"]
The run.sh starts the playwright test like this.
npx playwright test ./tests/TransactionType/ --workers 1 --reporter=list,html
What I see is this error from AWS logs.
Error: page.goto: net::ERR_CERT_AUTHORITY_INVALID at
Its trying to lauch the URL but then fails with this error.
As you can see I have --ignoreHTTPSErrors in my playwright.config file and also in my test file, but still no luck. I am not sure if I am missing anything here.
I also have "scripts": {"test": "playwright test --ignore-https-errors"} in my package.json.
Any help to solve this much appreciated.
I am using playwright in a Docker container that runs in AWS Batch env. I am able to successfully test from VS Code but it errors out as ERR_CERT_AUTHORITY_INVALID when it runs from a container.
These are my relevant pieces of code.
test.ts
import { test as base } from '@playwright/test';
import path from 'path';
import fs from 'fs';
import type { User } from './types';
const defaultPassword = 'xxxx';
export const test = base.extend<{ user: User }>({
user: { username: '' },
storageState: async ({ browser, user, baseURL }, use, testInfo) => {
if (!user.username) {
return;
}
const fileName = path.join(
testInfo.project.outputDir,
`storage-${user.username}-${testInfo.workerIndex}.json`
);
if (!fs.existsSync(fileName)) {
const page = await browser.newPage({ storageState: undefined });
await page.goto(baseURL ?? '/select-client');
await page.click('role=button[name="AGREE & CONTINUE"]');
await page.fill('#userName', user.username);
await page.fill('#password', user.password ?? defaultPassword);
await page.click('role=button[name="LOGIN"]');
await page.waitForTimeout(10000);
await page.context().storageState({ path: fileName });
}
console.log("Base URL:", baseURL);
await use(fileName);
},
});
export { expect } from '@playwright/test';
playwright.config.js
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
export default defineConfig({
testDir: './tests',
//testDir: path.join(__dirname, 'playwright', 'tests'),
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
workers: process.env.CI ? 1 : 1,
reporter: [
['html', { open: 'never' }],
['line'],
// ["allure-playwright", { outputFolder: "reports/allure" }],
['junit', { outputFile: 'reports/results.xml' }],
['json', { outputFile: 'reports/results.json' }],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
ignoreHTTPSErrors: true,
viewport: { width: 1920, height: 1080 },
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
trace: 'on-first-retry',
baseURL: 'https://my-url',
screenshot: 'only-on-failure',
headless: true,
storageState: 'storage.json',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
ignoreHTTPSErrors: true,
},
],
});
test case spec file:
import { Page, Locator, chromium } from '@playwright/test';
import { TransactionTypesPage } from '../../pages/transactionTypes.js';
import { CommonActions } from '../../pages/commonMethods';
import { LoginPage } from '../../pages/login';
import { test, expect } from '../../module/test';
import { imUser } from '../../module/users';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const today = new Date();
const todayDtTime = today.toISOString().replace(/[:T.]/g, '-').slice(0, -5);
let txnDetails = new TransactionTypeDetails();
test.describe('Transaction Types Test Set', () => {
console.log('Current working directory in test:', process.cwd());
test.use({ user: imUser, ignoreHTTPSErrors: true });
let page;
let transTypePage;
let commonActions;
let loginPage;
test.beforeAll(async ({ browser, baseURL }) => {
//const context = await browser.newContext({ ignoreHTTPSErrors: true });
page = await browser.newPage();
await page.route(() => true, (route) => {
route.fulfill( { status: 403, })
});
page = await browser.newPage();
transTypePage = new TransactionTypesPage(page);
commonActions = new CommonActions(page);
loginPage = new LoginPage(page);
await page.goto('/select-client', { timeout: 6000, waitUntil: 'networkidle' });
await page.waitForLoadState('networkidle');
console.log("Base URL----> ", page.url());
await loginPage.loginForStaticDataClient();
await page.waitForTimeout(3000);
await commonActions.clickAdminLink();
await page.waitForTimeout(3000);
await transTypePage.clickTransactionTypesLink();
await page.waitForTimeout(1000);
});
test('Click ADD NEW button', async () => {
await commonActions.clickAddNewButton();
await page.waitForTimeout(1000);
});
test('Enter Name', async() => {
await transTypePage.enterName("PW-Test-Name-" + todayDtTime);
txnDetails.name = "PW-Test-Name-" + todayDtTime
});
test('More tests...')
I also have the Dockerfile with this content:
FROM mcr.microsoft/playwright:latest
ENV CI=true
ENV NODE_TLS_REJECT_UNAUTHORIZED=0
RUN apt-get update && apt-get install -y ca-certificates \
&& update-ca-certificates
# Set the working directory in the container
WORKDIR /usr/src/app/csg-treasury-web-ui-app
# Install dependencies for AWS CLI installation
RUN apt-get update && apt-get install -y \
unzip \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install AWS CLI v2
RUN curl "https://awscli.amazonaws/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm awscliv2.zip \
&& rm -rf aws
RUN echo "AWS CLI installation successful"
# Install Playwright browsers
RUN npx playwright install chromium
RUN echo "Playwright and Chromium installation successful"
# Copy package.json and package-lock.json (if available)
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of your project files
COPY . .
RUN pwd
RUN ls -lt
# Install Playwright browsers
RUN npx playwright install
RUN echo playwright install successful
RUN pwd
RUN chmod +x ./run.sh
RUN echo "Playwright version is:"
RUN npx playwright --version
# Change the working directory to the playwright folder
RUN echo "Change dir to playwright in the container..."
WORKDIR /usr/src/app/csg-treasury-web-ui-app/playwright
RUN pwd
RUN ls -lt
CMD ["bash", "/usr/src/app/csg-treasury-web-ui-app/run.sh"]
The run.sh starts the playwright test like this.
npx playwright test ./tests/TransactionType/ --workers 1 --reporter=list,html
What I see is this error from AWS logs.
Error: page.goto: net::ERR_CERT_AUTHORITY_INVALID at https://my-url
Its trying to lauch the URL but then fails with this error.
As you can see I have --ignoreHTTPSErrors in my playwright.config file and also in my test file, but still no luck. I am not sure if I am missing anything here.
I also have "scripts": {"test": "playwright test --ignore-https-errors"} in my package.json.
Any help to solve this much appreciated.
Share Improve this question asked Nov 19, 2024 at 23:43 RamRam 4152 gold badges8 silver badges17 bronze badges1 Answer
Reset to default 0I had a similar situation in which I kept getting the same error as you. I tried all of the same solutions. The only thing that worked was adding launchOptions: { args: ["--ignore-certificate-errors"] }
to the individual browser objects. The suggestions in the Playwright docs didn't seem to help.
Full example with Chromium:
// playwright.config.ts
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: {
...devices["Desktop Chrome"],
launchOptions: {
args: ["--ignore-certificate-errors"],
},
},
},
],
本文标签: ERRCERTAUTHORITYINVALID playwrightStack Overflow
版权声明:本文标题:ERR_CERT_AUTHORITY_INVALID playwright - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742390700a2465928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论