Best JavaScript code snippet using playwright-internal
ignorehttpserrors.spec.js
Source:ignorehttpserrors.spec.js
...40 const [serverRequest, response] = await Promise.all([41 httpsServer.waitForRequest('/empty.html'),42 page.goto(httpsServer.EMPTY_PAGE)43 ]);44 const securityDetails = response.securityDetails();45 expect(securityDetails.issuer()).toBe('puppeteer-tests');46 const protocol = serverRequest.socket.getProtocol().replace('v', ' ');47 expect(securityDetails.protocol()).toBe(protocol);48 expect(securityDetails.subjectName()).toBe('puppeteer-tests');49 expect(securityDetails.validFrom()).toBe(1550084863);50 expect(securityDetails.validTo()).toBe(33086084863);51 });52 it('should be |null| for non-secure requests', async({page, server}) => {53 const response = await page.goto(server.EMPTY_PAGE);54 expect(response.securityDetails()).toBe(null);55 });56 it('Network redirects should report SecurityDetails', async({page, httpsServer}) => {57 httpsServer.setRedirect('/plzredirect', '/empty.html');58 const responses = [];59 page.on('response', response => responses.push(response));60 const [serverRequest, ] = await Promise.all([61 httpsServer.waitForRequest('/plzredirect'),62 page.goto(httpsServer.PREFIX + '/plzredirect')63 ]);64 expect(responses.length).toBe(2);65 expect(responses[0].status()).toBe(302);66 const securityDetails = responses[0].securityDetails();67 const protocol = serverRequest.socket.getProtocol().replace('v', ' ');68 expect(securityDetails.protocol()).toBe(protocol);69 });70 });71 it('should work', async({page, httpsServer}) => {72 let error = null;73 const response = await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);74 expect(error).toBe(null);75 expect(response.ok()).toBe(true);76 });77 it('should work with request interception', async({page, server, httpsServer}) => {78 await page.setRequestInterception(true);79 page.on('request', request => request.continue());80 const response = await page.goto(httpsServer.EMPTY_PAGE);...
ignorehttpserrors.js
Source:ignorehttpserrors.js
...22 'ignoreHTTPSErrors - Response.securityDetails: should work',23 async t => {24 const { page, httpsServer } = t.context25 const response = await page.goto(httpsServer.EMPTY_PAGE)26 const securityDetails = response.securityDetails()27 t.is(securityDetails.issuer(), 'puppeteer-tests')28 t.regex(securityDetails.protocol(), /TLS\s[0-9]\.[0-9]/)29 t.is(securityDetails.subjectName(), 'puppeteer-tests')30 t.is(securityDetails.validFrom(), 1550084863)31 t.is(securityDetails.validTo(), 33086084863)32 }33)34test.serial(35 'ignoreHTTPSErrors - Response.securityDetails: should be |null| for non-secure requests',36 async t => {37 const { page, server } = t.context38 const response = await page.goto(server.EMPTY_PAGE)39 t.falsy(response.securityDetails())40 }41)42test.serial(43 'ignoreHTTPSErrors - Response.securityDetails: Network redirects should report SecurityDetails',44 async t => {45 const { page, httpsServer } = t.context46 const responses = []47 page.on('response', response => responses.push(response))48 await page.goto(httpsServer.PREFIX + '/plzredirect')49 t.is(responses.length, 2)50 t.is(responses[0].status(), 302)51 const securityDetails = responses[0].securityDetails()52 t.regex(securityDetails.protocol(), /TLS\s[0-9]\.[0-9]/)53 }54)55test.serial('ignoreHTTPSErrors should work', async t => {56 const { page, httpsServer } = t.context57 let error = null58 const response = await page59 .goto(httpsServer.EMPTY_PAGE)60 .catch(e => (error = e))61 t.falsy(error)62 t.true(response.ok())63})64test.serial(65 'ignoreHTTPSErrors should work with request interception',...
security-details-updated-with-security-state.js
Source:security-details-updated-with-security-state.js
1// Copyright 2017 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4(async function() {5 TestRunner.addResult(`Tests that the security details for an origin are updated if its security state changes.\n`);6 await TestRunner.loadModule('security_test_runner');7 await TestRunner.showPanel('security');8 // Add a request without security details.9 const request1 = new SDK.NetworkRequest(0, 'https://foo.test/foo.jpg', 'https://foo.test', 0, 0, null);10 request1.setSecurityState(Protocol.Security.SecurityState.Unknown);11 SecurityTestRunner.dispatchRequestFinished(request1);12 // Add an unrelated request.13 const request2 = new SDK.NetworkRequest(0, 'https://bar.test/bar.jpg', 'https://bar.test', 0, 0, null);14 request2.setSecurityState(Protocol.Security.SecurityState.Unknown);15 SecurityTestRunner.dispatchRequestFinished(request2);16 // Add a request to the first origin, this time including security details.17 const request3 = new SDK.NetworkRequest(0, 'https://foo.test/foo2.jpg', 'https://foo.test', 0, 0, null);18 request3.setSecurityState(Protocol.Security.SecurityState.Secure);19 let securityDetails = {};20 securityDetails.protocol = 'TLS 1.2';21 securityDetails.keyExchange = 'Key_Exchange';22 securityDetails.keyExchangeGroup = '';23 securityDetails.cipher = 'Cypher';24 securityDetails.mac = 'Mac';25 securityDetails.subjectName = 'foo.test';26 securityDetails.sanList = ['foo.test', '*.test'];27 securityDetails.issuer = 'Super CA';28 securityDetails.validFrom = 1490000000;29 securityDetails.validTo = 2000000000;30 securityDetails.CertificateId = 0;31 securityDetails.signedCertificateTimestampList = [];32 securityDetails.certificateTransparencyCompliance = Protocol.Network.CertificateTransparencyCompliance.Unknown;33 request3.setSecurityDetails(securityDetails);34 SecurityTestRunner.dispatchRequestFinished(request3);35 TestRunner.addResult('Sidebar Origins --------------------------------');36 SecurityTestRunner.dumpSecurityPanelSidebarOrigins();37 Security.SecurityPanel._instance()._sidebarTree._elementsByOrigin.get('https://foo.test').select();38 TestRunner.addResult('Origin view ------------------------------------');39 TestRunner.dumpDeepInnerHTML(Security.SecurityPanel._instance()._visibleView.contentElement);40 TestRunner.completeTest();...
origin-view-ct-compliance.js
Source:origin-view-ct-compliance.js
1// Copyright 2018 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4(async function() {5 TestRunner.addResult(6 `Tests that the panel includes Certificate Transparency compliance status\n`);7 await TestRunner.loadModule('security_test_runner');8 await TestRunner.showPanel('security');9 var request1 = new SDK.NetworkRequest(0, 'https://foo.test/', 'https://foo.test', 0, 0, null);10 request1.setSecurityState(Protocol.Security.SecurityState.Secure);11 let securityDetails = {};12 securityDetails.protocol = 'TLS 1.2';13 securityDetails.keyExchange = 'Key_Exchange';14 securityDetails.keyExchangeGroup = '';15 securityDetails.cipher = 'Cypher';16 securityDetails.mac = 'Mac';17 securityDetails.subjectName = 'foo.test';18 securityDetails.sanList = ['foo.test', '*.test'];19 securityDetails.issuer = 'Super CA';20 securityDetails.validFrom = 1490000000;21 securityDetails.validTo = 2000000000;22 securityDetails.CertificateId = 0;23 securityDetails.signedCertificateTimestampList = [];24 securityDetails.certificateTransparencyCompliance = Protocol.Network.CertificateTransparencyCompliance.Compliant;25 request1.setSecurityDetails(securityDetails);26 SecurityTestRunner.dispatchRequestFinished(request1);27 Security.SecurityPanel._instance()._sidebarTree._elementsByOrigin.get('https://foo.test').select();28 TestRunner.addResult('Panel on origin view:');29 TestRunner.dumpDeepInnerHTML(Security.SecurityPanel._instance()._visibleView.contentElement);30 TestRunner.completeTest();...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 const securityDetails = await page._client.send('Security.getSecurityDetails', {frameId: page.mainFrame()._id});7 console.log(securityDetails);8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch({headless: false});13 const context = await browser.newContext();14 const page = await context.newPage();15 const securityDetails = await page._client.send('Security.getSecurityDetails', {frameId: page.mainFrame()._id});16 console.log(securityDetails);17 console.log(securityDetails.protocol);18 console.log(securityDetails.certificate);19 console.log(securityDetails.subjectName);20 console.log(securityDetails.issuer);21 console.log(securityDetails.validFrom);22 console.log(securityDetails.validTo);23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch({headless: false});28 const context = await browser.newContext();29 const page = await context.newPage();30 const securityDetails = await page._client.send('Security.getSecurityDetails', {frameId: page.mainFrame()._id});31 console.log(securityDetails);32 const fingerprint = securityDetails.certificateFingerprint.sha1;33 console.log(fingerprint);34 await browser.close();35})();36const { chromium } = require('playwright');37(async () => {38 const browser = await chromium.launch({headless: false});
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const securityDetails = await page.evaluate(() => {7 return window.__playwright__internal__securityDetails;8 });9 console.log(securityDetails);10 await browser.close();11})();12const playwright = require('playwright');13(async () => {14 const browser = await playwright.chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const securityDetails = await page.evaluate(() => {18 return window.__playwright__internal__securityDetails;19 });20 console.log(securityDetails);21 await browser.close();22})();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!