Best JavaScript code snippet using playwright-internal
index.js
Source:index.js
...107}108function isUnderTest() {109 return _isUnderTest;110}111function experimentalFeaturesEnabled() {112 return isUnderTest() || !!process.env.PLAYWRIGHT_EXPERIMENTAL_FEATURES;113}114function getFromENV(name) {115 let value = process.env[name];116 value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value;117 value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;118 return value;119}120function getAsBooleanFromENV(name) {121 const value = getFromENV(name);122 return !!value && value !== 'false' && value !== '0';123}124function headersObjectToArray(headers, separator, setCookieSeparator) {125 if (!setCookieSeparator) setCookieSeparator = separator;...
Sidebar.jsx
Source:Sidebar.jsx
1/* global VERSION */2import Box from '@material-ui/core/Box';3import Typography from '@material-ui/core/Typography';4import Alarm from '@material-ui/icons/Alarm';5// import Apps from '@material-ui/icons/Apps';6import Flight from '@material-ui/icons/Flight';7import Gamepad from '@material-ui/icons/Gamepad';8import Grain from '@material-ui/icons/Grain';9import Layers from '@material-ui/icons/Layers';10import Map from '@material-ui/icons/Map';11import MyLocation from '@material-ui/icons/MyLocation';12import FormatListBulleted from '@material-ui/icons/FormatListBulleted';13import ShowChart from '@material-ui/icons/ShowChart';14// import Storage from '@material-ui/icons/Storage';15import ThreeDRotation from '@material-ui/icons/ThreeDRotation';16import WbSunny from '@material-ui/icons/WbSunny';17import PropTypes from 'prop-types';18import React from 'react';19import { Module, ModuleTray, Workbench } from 'react-flexible-workbench';20import { connect } from 'react-redux';21import LogStatusBadge from '~/components/badges/LogStatusBadge';22import { areExperimentalFeaturesEnabled } from '~/features/settings/selectors';23import Antenna from '~/icons/Antenna';24import { hasFeature } from '~/utils/configuration';25import { isSidebarOpen } from './selectors';26const SIDEBAR_OPEN_WIDTH = 180; /* 160px is enough for most platforms, but apparently Windows needs 180px because of the scrollbar */27const style = {28 backgroundColor: '#333',29 boxShadow: 'rgba(0, 0, 0, 0.3) -9px -3px 6px -6px inset',30 display: 'flex',31 flexFlow: 'column nowrap',32 height: 'calc(100vh - 48px)',33 overflow: 'hidden',34};35const innerStyle = {36 display: 'flex',37 flexFlow: 'column nowrap',38 flexGrow: 1,39 overflow: 'auto',40 width: SIDEBAR_OPEN_WIDTH,41};42/**43 * Presentation component for the sidebar at the left edge of the main44 * window.45 *46 * @returns {Object} the rendered sidebar component47 */48const Sidebar = ({ experimentalFeaturesEnabled, isOpen, workbench }) => (49 <div50 id='sidebar'51 style={{ ...style, width: isOpen ? SIDEBAR_OPEN_WIDTH : 48 }}52 >53 <div style={innerStyle}>54 <ModuleTray allowMultipleSelection vertical workbench={workbench}>55 <Module id='map' icon={<Map />} label='Map' component='map' />56 <Module57 id='threeDView'58 icon={<ThreeDRotation />}59 label='3D View'60 component='three-d-view'61 reorderEnabled={false}62 />63 <Module64 id='layers'65 icon={<Layers />}66 label='Layers'67 component='layer-list'68 />69 {hasFeature('features') && (70 <Module71 id='features'72 icon={<ShowChart />}73 label='Features'74 component='feature-list'75 />76 )}77 <hr />78 <Module id='uavs' icon={<Flight />} label='UAVs' component='uav-list' />79 {hasFeature('beacons') && (80 <Module81 id='beacons'82 icon={<Antenna />}83 label='Beacons'84 component='beacon-list'85 />86 )}87 {hasFeature('docks') && experimentalFeaturesEnabled && (88 <Module89 id='docks'90 icon={<Gamepad />}91 label='Docks'92 component='dock-list'93 />94 )}95 <hr />96 {/* Do not use a single React fragment here for the next section; it would confuse `react-flexible-workbench` */}97 {hasFeature('showControl') && (98 <Module99 id='show'100 icon={<Grain />}101 label='Show control'102 component='show-control'103 />104 )}105 {hasFeature('showControl') && (106 <Module107 id='lights'108 icon={<WbSunny />}109 label='Light control'110 component='light-control'111 />112 )}113 {hasFeature('showControl') && <hr />}114 <Module115 id='clocks'116 icon={<Alarm />}117 label='Clocks'118 component='lcd-clock-panel'119 />120 {/*121 <Module122 id="datasets"123 icon={<Storage />}124 label="Datasets"125 component="dataset-list"126 />127 */}128 <Module129 id='locations'130 icon={<MyLocation />}131 label='Locations'132 component='saved-location-list'133 />134 <hr />135 <Module136 id='log'137 badge={<LogStatusBadge />}138 icon={<FormatListBulleted />}139 label='Event log'140 component='log-panel'141 />142 </ModuleTray>143 </div>144 {isOpen && (145 <Box146 py={0.5}147 px={1}148 style={{ color: '#fff', opacity: 0.3, width: SIDEBAR_OPEN_WIDTH }}149 >150 <Typography align='center' variant='caption' component='footer'>151 {VERSION}152 </Typography>153 </Box>154 )}155 </div>156);157Sidebar.propTypes = {158 experimentalFeaturesEnabled: PropTypes.bool,159 isOpen: PropTypes.bool,160 workbench: PropTypes.instanceOf(Workbench).isRequired,161};162/**163 * Sidebar at the left edge of the main window.164 */165export default connect(166 // mapStateToProps167 (state, { workbench }) => ({168 experimentalFeaturesEnabled: areExperimentalFeaturesEnabled(state),169 isOpen: isSidebarOpen(state),170 workbench,171 })...
DisplayTab.jsx
Source:DisplayTab.jsx
1import PropTypes from 'prop-types';2import React from 'react';3import { connect } from 'react-redux';4import Box from '@material-ui/core/Box';5import Checkbox from '@material-ui/core/Checkbox';6import FormControl from '@material-ui/core/FormControl';7import FormControlLabel from '@material-ui/core/FormControlLabel';8import FormGroup from '@material-ui/core/FormGroup';9import InputLabel from '@material-ui/core/InputLabel';10import MenuItem from '@material-ui/core/MenuItem';11import Select from '@material-ui/core/Select';12import CoordinateSystemFields from '~/components/CoordinateSystemFields';13import { updateAppSettings } from '~/features/settings/slice';14import { CoordinateFormat, describeCoordinateFormat } from '~/model/settings';15import {16 setFlatEarthCoordinateSystemOrientation,17 setFlatEarthCoordinateSystemType,18 setFlatEarthCoordinateSystemOrigin,19} from '~/reducers/map/origin';20import { getMapOriginRotationAngle } from '~/selectors/map';21import Header from '@skybrush/mui-components/lib/FormHeader';22import ThemeSelector from '@skybrush/mui-components/lib/ThemeSelector';23const coordinateFormatOrder = [24 CoordinateFormat.DEGREES,25 CoordinateFormat.DEGREES_MINUTES,26 CoordinateFormat.DEGREES_MINUTES_SECONDS,27 CoordinateFormat.SIGNED_DEGREES,28 CoordinateFormat.SIGNED_DEGREES_MINUTES,29 CoordinateFormat.SIGNED_DEGREES_MINUTES_SECONDS,30];31const DisplayTabPresentation = (props) => (32 <>33 <Box my={2}>34 <ThemeSelector value={props.theme} onChange={props.onFieldChanged} />35 </Box>36 <Box my={2}>37 <FormControl fullWidth variant='filled'>38 <InputLabel id='coordinate-format-label'>Coordinate format</InputLabel>39 <Select40 labelId='coordinate-format-label'41 name='coordinateFormat'42 value={props.coordinateFormat}43 onChange={props.onFieldChanged}44 >45 {coordinateFormatOrder.map((coordinateFormat) => (46 <MenuItem key={coordinateFormat} value={coordinateFormat}>47 {describeCoordinateFormat(coordinateFormat)}48 </MenuItem>49 ))}50 </Select>51 </FormControl>52 <FormGroup>53 <Header>Map widgets</Header>54 <FormControlLabel55 label='Show mouse coordinates'56 control={57 <Checkbox58 checked={props.showMouseCoordinates}59 name='showMouseCoordinates'60 onChange={props.onCheckboxToggled}61 />62 }63 />64 <FormControlLabel65 label='Show scale line'66 control={67 <Checkbox68 checked={props.showScaleLine}69 name='showScaleLine'70 onChange={props.onCheckboxToggled}71 />72 }73 />74 </FormGroup>75 <FormGroup>76 <Header>Flat Earth coordinate system</Header>77 <CoordinateSystemFields78 origin={props.origin}79 originLabel='Map origin'80 orientation={props.orientation}81 type={props.coordinateSystemType}82 onOrientationChanged={props.onOrientationChanged}83 onOriginChanged={props.onOriginChanged}84 onTypeChanged={props.onCoordinateSystemTypeChanged}85 />86 </FormGroup>87 <FormGroup>88 <Header>Miscellaneous</Header>89 <FormControlLabel90 label='Enable experimental features (advanced)'91 control={92 <Checkbox93 checked={props.experimentalFeaturesEnabled}94 name='experimentalFeaturesEnabled'95 onChange={props.onCheckboxToggled}96 />97 }98 />99 </FormGroup>100 </Box>101 </>102);103DisplayTabPresentation.propTypes = {104 coordinateFormat: PropTypes.oneOf(coordinateFormatOrder),105 coordinateSystemType: PropTypes.oneOf(['neu', 'nwu']),106 experimentalFeaturesEnabled: PropTypes.bool,107 origin: PropTypes.arrayOf(PropTypes.number),108 onCheckboxToggled: PropTypes.func,109 onCoordinateSystemTypeChanged: PropTypes.func,110 onFieldChanged: PropTypes.func,111 onOriginChanged: PropTypes.func,112 onOrientationChanged: PropTypes.func,113 orientation: PropTypes.number,114 showMouseCoordinates: PropTypes.bool,115 showScaleLine: PropTypes.bool,116 theme: PropTypes.oneOf(['auto', 'dark', 'light']),117};118export default connect(119 // mapStateToProps120 (state) => ({121 coordinateSystemType: state.map.origin.type,122 origin: state.map.origin.position,123 orientation: getMapOriginRotationAngle(state),124 ...state.settings.display,125 }),126 // mapDispatchToProps127 (dispatch) => ({128 onCheckboxToggled(event) {129 dispatch(130 updateAppSettings('display', {131 [event.target.name]: event.target.checked,132 })133 );134 },135 onCoordinateSystemTypeChanged(event) {136 dispatch(setFlatEarthCoordinateSystemType(event.target.value));137 },138 onFieldChanged(event) {139 dispatch(140 updateAppSettings('display', {141 [event.target.name]: event.target.value,142 })143 );144 },145 onOriginChanged(value) {146 dispatch(setFlatEarthCoordinateSystemOrigin(value));147 },148 onOrientationChanged(value) {149 dispatch(setFlatEarthCoordinateSystemOrientation(value || 0));150 },151 })...
settingsReducers.js
Source:settingsReducers.js
1/* @flow */2// import type {3// SettingsState,4// SettingsAction,5// RealmInitAction,6// SettingsChangeAction,7// EventUpdateGlobalNotificationsSettingsAction,8// } from '../types';9// import {10// SETTINGS_CHANGE,11// REALM_INIT,12// EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,13// } from '../actionConstants';14// const initialState: SettingsState = {15// locale: 'en',16// theme: 'default',17// offlineNotification: true,18// onlineNotification: true,19// experimentalFeaturesEnabled: false,20// streamNotification: false,21// };22// const realmInit = (state, action) => ({23// ...state,24// offlineNotification: action.data.enable_offline_push_notifications,25// onlineNotification: action.data.enable_online_push_notifications26// });27// const settingsChange = (state, action) => ({28// ...state,29// [action.key]: action.value30// });31// const eventUpdateGlobalNotificationsSettings = (32// state = {33// locale: "zh",34// theme: "default",35// offlineNotification: true,36// onlineNotification: true,37// experimentalFeaturesEnabled: false,38// streamNotification: false39// },40// action = {}41// ) => {42// switch (action.notification_name) {43// // case "enable_offline_push_notifications":44// // return { ...state, offlineNotification: action.setting };45// // case "enable_online_push_notifications":46// // return { ...state, onlineNotification: action.setting };47// // case "enable_stream_push_notifications":48// // return { ...state, streamNotification: action.setting };49// default:50// return state;51// }52// };53export default (54 state = {55 locale: "zh",56 theme: "default",57 offlineNotification: true,58 onlineNotification: true,59 experimentalFeaturesEnabled: false,60 streamNotification: false61 },62 action = {}63) => {64 switch (action.type) {65 // case REALM_INIT:66 // return realmInit(state, action);67 // case SETTINGS_CHANGE:68 // return settingsChange(state, action);69 // case EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS:70 // return eventUpdateGlobalNotificationsSettings(state, action);71 default:72 return state;73 }...
settingsReducer.js
Source:settingsReducer.js
1/* @flow strict-local */2import type { SettingsState, Action } from '../types';3import {4 SETTINGS_CHANGE,5 REALM_INIT,6 EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,7} from '../actionConstants';8import { ensureUnreachable } from '../types';9const initialState: SettingsState = {10 locale: 'en',11 theme: 'default',12 offlineNotification: true,13 onlineNotification: true,14 experimentalFeaturesEnabled: false,15 streamNotification: false,16};17export default (state: SettingsState = initialState, action: Action): SettingsState => {18 switch (action.type) {19 case REALM_INIT:20 return {21 ...state,22 offlineNotification: action.data.enable_offline_push_notifications,23 onlineNotification: action.data.enable_online_push_notifications,24 streamNotification: action.data.enable_stream_push_notifications,25 };26 case SETTINGS_CHANGE:27 return {28 ...state,29 ...action.update,30 };31 case EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS:32 switch (action.notification_name) {33 case 'enable_offline_push_notifications':34 return { ...state, offlineNotification: action.setting };35 case 'enable_online_push_notifications':36 return { ...state, onlineNotification: action.setting };37 case 'enable_stream_push_notifications':38 return { ...state, streamNotification: action.setting };39 default:40 ensureUnreachable(action.notification_name);41 return state;42 }43 default:44 return state;45 }...
Service.class.js
Source:Service.class.js
1'use strict'2class Service {3 constructor (serviceData) {4 this.id = serviceData.id5 this.externalId = serviceData.external_id6 this.name = serviceData.name7 this.serviceName = serviceData.service_name8 this.gatewayAccountIds = serviceData.gateway_account_ids9 this.merchantDetails = serviceData.merchant_details10 this.collectBillingAddress = serviceData.collect_billing_address11 this.currentGoLiveStage = serviceData.current_go_live_stage12 this.experimentalFeaturesEnabled = serviceData.experimental_features_enabled13 this.createdDate = serviceData.created_date14 this.currentPspTestAccountStage = serviceData.current_psp_test_account_stage15 this.agentInitiatedMotoEnabled = serviceData.agent_initiated_moto_enabled16 }17 /**18 * @method toJson19 * @returns {Object} An 'adminusers' compatible representation of the service20 */21 toJson () {22 return {23 id: this.id,24 external_id: this.externalId,25 name: this.name,26 serviceName: this.serviceName,27 gateway_account_ids: this.gatewayAccountIds,28 merchant_details: this.merchantDetails,29 collect_billing_address: this.collectBillingAddress,30 current_go_live_stage: this.currentGoLiveStage,31 experimental_features_enabled: this.experimentalFeaturesEnabled,32 created_date: this.createdDate,33 current_psp_test_account_stage: this.currentPspTestAccountStage,34 agent_initiated_moto_enabled: this.agentInitiatedMotoEnabled35 }36 }37}...
experimental-features.test.js
Source:experimental-features.test.js
1const path = require('path')2const sinon = require('sinon')3const chai = require('chai')4const chaiAsPromised = require('chai-as-promised')5const experimentalFeatures = require(path.join(__dirname, '/../../../app/middleware/experimental-features.js'))6const { expect } = chai7let res, next8chai.use(chaiAsPromised)9describe('services experimental features middleware', () => {10 beforeEach(() => {11 res = {12 redirect: sinon.spy(),13 status: sinon.spy((code) => ({ render: sinon.spy() }))14 }15 next = sinon.spy()16 })17 it('restricts access if experimental features are disabled on the service configuration', () => {18 const req = {19 service: {20 experimentalFfeaturesEnabled: false21 }22 }23 experimentalFeatures(req, res, next)24 expect(res.status.calledWith(404))25 expect(next.called).to.be.false // eslint-disable-line26 })27 it('allows access if experimental features are enabled on the service configuration', () => {28 const req = {29 service: {30 experimentalFeaturesEnabled: true31 }32 }33 experimentalFeatures(req, res, next)34 expect(next.called).to.be.true // eslint-disable-line35 })...
experimental-features.js
Source:experimental-features.js
1'use strict'2const restrictServiceExperimentalFeatures = function restrictServiceExperimentalFeatures (req, res, next) {3 if (req.service && !req.service.experimentalFeaturesEnabled) {4 res.status(404).render('404')5 return6 }7 next()8}...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 console.log(await page.context().experimentalFeaturesEnabled());6 await browser.close();7})();
Using AI Code Generation
1const { experimentalFeaturesEnabled } = require('playwright');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9(async () => {10 console.log(await experimentalFeaturesEnabled());11})();12const { test, expect } = require('@playwright/test');13test('sample test', async ({ page }) => {14 await page.screenshot({ path: `example.png` });15 expect(await page.title()).toBe('Playwright');16});17test('sample test', async ({ page }) => {18 console.log(await page.experimentalFeaturesEnabled());19});20const { test, expect } = require('@playwright/test');21test.use({ storageState: 'state.json' });22test('sample test', async ({ page }) => {23 await page.screenshot({ path: `example.png` });24 expect(await page.title()).toBe('Playwright');25});26test('sample test', async ({ page }) => {27 console.log(await page.experimentalFeaturesEnabled());28});29const { test, expect } = require('@playwright/test');30test.use({ storageState: 'state.json' });31test('sample test', async ({ page }) => {32 await page.screenshot({ path: `example.png` });33 expect(await page.title()).toBe('Playwright');34});35test('sample test', async ({ page }) => {36 console.log(await page.experimentalFeaturesEnabled());37});38test('sample test', async ({ page }) => {39 console.log(await page.context().experimentalFeaturesEnabled());40});
Using AI Code Generation
1const { experimentalFeaturesEnabled } = require('@playwright/test');2console.log(experimentalFeaturesEnabled());3const { experimentalFeaturesEnabled } = require('@playwright/test');4console.log(experimentalFeaturesEnabled());5const { experimentalFeaturesEnabled } = require('@playwright/test');6console.log(experimentalFeaturesEnabled());7const { experimentalFeaturesEnabled } = require('@playwright/test');8console.log(experimentalFeaturesEnabled());9const { experimentalFeaturesEnabled } = require('@playwright/test');10console.log(experimentalFeaturesEnabled());11const { experimentalFeaturesEnabled } = require('@playwright/test');12console.log(experimentalFeaturesEnabled());13const { experimentalFeaturesEnabled } = require('@playwright/test');14console.log(experimentalFeaturesEnabled());15const { experimentalFeaturesEnabled } = require('@playwright/test');16console.log(experimentalFeaturesEnabled());17const { experimentalFeaturesEnabled } = require('@playwright/test');18console.log(experimentalFeaturesEnabled());19const { experimentalFeaturesEnabled } = require('@playwright/test');20console.log(experimentalFeaturesEnabled());21const { experimentalFeaturesEnabled } = require('@playwright/test');22console.log(experimentalFeaturesEnabled());23const { experimentalFeaturesEnabled } = require('@playwright/test');24console.log(experimentalFeaturesEnabled());25const { experimentalFeaturesEnabled } = require('@playwright/test');26console.log(experimentalFeaturesEnabled());
Using AI Code Generation
1const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');2console.log(experimentalFeaturesEnabled);3const { experimentalFeaturesEnabled } = require('playwright');4console.log(experimentalFeaturesEnabled);5const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');6console.log(experimentalFeaturesEnabled);7const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');8console.log(experimentalFeaturesEnabled);9const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');10console.log(experimentalFeaturesEnabled);11const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');12console.log(experimentalFeaturesEnabled);13const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');14console.log(experimentalFeaturesEnabled);15const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');16console.log(experimentalFeaturesEnabled);17const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');18console.log(experimentalFeaturesEnabled);19const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');20console.log(experimentalFeaturesEnabled);21const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');22console.log(experimentalFeaturesEnabled);23const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');24console.log(experimentalFeaturesEnabled);25const { experimentalFeaturesEnabled } = require('playwright/lib/server/playwright');26console.log(experimentalFeaturesEnabled
Using AI Code Generation
1import { experimentalFeaturesEnabled } from 'playwright-core/lib/server/browserContext';2const isExperimentalEnabled = await experimentalFeaturesEnabled(browserContext);3const isExperimentalEnabled = await browserContext.experimentalFeaturesEnabled();4const isExperimentalEnabled = await page.context().experimentalFeaturesEnabled();5const isExperimentalEnabled = await page.experimentalFeaturesEnabled();6const isExperimentalEnabled = await frame.experimentalFeaturesEnabled();7const isExperimentalEnabled = await frame.context().experimentalFeaturesEnabled();8const isExperimentalEnabled = await frame.page().experimentalFeaturesEnabled();9const isExperimentalEnabled = await frame.page().context().experimentalFeaturesEnabled();10const isExperimentalEnabled = await browserContext.pages()[0].experimentalFeaturesEnabled();11const isExperimentalEnabled = await browserContext.pages()[0].context().experimentalFeaturesEnabled();12const isExperimentalEnabled = await browserContext.pages()[0].context().browser().experimentalFeaturesEnabled();13const isExperimentalEnabled = await browserContext.pages()[0].context().browser().newContext().experimentalFeaturesEnabled();14const isExperimentalEnabled = await browserContext.pages()[0].context().browser().newPage().experimentalFeaturesEnabled();15const isExperimentalEnabled = await browserContext.pages()[0].context().browser().newPage().context().experimentalFeaturesEnabled();16const isExperimentalEnabled = await browserContext.pages()[0].context().browser().newPage().context().browser().experimentalFeaturesEnabled();
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!!