Best JavaScript code snippet using playwright-internal
normalize.js
Source: normalize.js
1import camelCase from 'lodash/camelCase';2import isArray from 'lodash/isArray';3import isNull from 'lodash/isNull';4import keys from 'lodash/keys';5import merge from 'lodash/merge';6function wrap(json) {7 if (isArray(json)) {8 return json;9 }10 return [json];11}12function isDate(attributeValue) {13 return Object.prototype.toString.call(attributeValue) === '[object Date]';14}15function camelizeNestedKeys(attributeValue) {16 if (attributeValue === null || typeof attributeValue !== 'object' || isDate(attributeValue)) {17 return attributeValue;18 }19 if (isArray(attributeValue)) {20 return attributeValue.map(camelizeNestedKeys);21 }22 const copy = {};23 keys(attributeValue).forEach((k) => {24 copy[camelCase(k)] = camelizeNestedKeys(attributeValue[k]);25 });26 return copy;27}28function extractRelationships(relationships, { camelizeKeys, camelizeTypeValues }) {29 const ret = {};30 keys(relationships).forEach((key) => {31 const relationship = relationships[key];32 const name = camelizeKeys ? camelCase(key) : key;33 ret[name] = {};34 if (typeof relationship.data !== 'undefined') {35 if (isArray(relationship.data)) {36 ret[name].data = relationship.data.map(e => ({37 id: e.id,38 type: camelizeTypeValues ? camelCase(e.type) : e.type,39 }));40 } else if (!isNull(relationship.data)) {41 ret[name].data = {42 id: relationship.data.id,43 type: camelizeTypeValues ? camelCase(relationship.data.type) : relationship.data.type,44 };45 } else {46 ret[name].data = relationship.data;47 }48 }49 if (relationship.links) {50 ret[name].links = camelizeKeys ? camelizeNestedKeys(relationship.links) : relationship.links;51 }52 if (relationship.meta) {53 ret[name].meta = camelizeKeys ? camelizeNestedKeys(relationship.meta) : relationship.meta;54 }55 });56 return ret;57}58function processMeta(metaObject, { camelizeKeys }) {59 if (camelizeKeys) {60 const meta = {};61 keys(metaObject).forEach((key) => {62 meta[camelCase(key)] = camelizeNestedKeys(metaObject[key]);63 });64 return meta;65 }66 return metaObject;67}68function extractEntities(json, { camelizeKeys, camelizeTypeValues }) {69 const ret = {};70 wrap(json).forEach((elem) => {71 const type = camelizeKeys ? camelCase(elem.type) : elem.type;72 ret[type] = ret[type] || {};73 ret[type][elem.id] = ret[type][elem.id] || {74 id: elem.id,75 };76 ret[type][elem.id].type = camelizeTypeValues ? camelCase(elem.type) : elem.type;77 if (camelizeKeys) {78 ret[type][elem.id].attributes = {};79 keys(elem.attributes).forEach((key) => {80 ret[type][elem.id].attributes[camelCase(key)] = camelizeNestedKeys(elem.attributes[key]);81 });82 } else {83 ret[type][elem.id].attributes = elem.attributes;84 }85 if (elem.links) {86 ret[type][elem.id].links = {};87 keys(elem.links).forEach((key) => {88 const newKey = camelizeKeys ? camelCase(key) : key;89 ret[type][elem.id].links[newKey] = elem.links[key];90 });91 }92 if (elem.relationships) {93 ret[type][elem.id].relationships = extractRelationships(elem.relationships, {94 camelizeKeys,95 camelizeTypeValues,96 });97 }98 if (elem.meta) {99 ret[type][elem.id].meta = processMeta(elem.meta, { camelizeKeys });100 }101 });102 return ret;103}104function doFilterEndpoint(endpoint) {105 return endpoint.replace(/\?.*$/, '');106}107function extractMetaData(json, endpoint, { camelizeKeys, camelizeTypeValues, filterEndpoint }) {108 const ret = {};109 ret.meta = {};110 let metaObject;111 if (!filterEndpoint) {112 const filteredEndpoint = doFilterEndpoint(endpoint);113 ret.meta[filteredEndpoint] = {};114 ret.meta[filteredEndpoint][endpoint.slice(filteredEndpoint.length)] = {};115 metaObject = ret.meta[filteredEndpoint][endpoint.slice(filteredEndpoint.length)];116 } else {117 ret.meta[endpoint] = {};118 metaObject = ret.meta[endpoint];119 }120 metaObject.data = {};121 if (json.data) {122 const meta = [];123 wrap(json.data).forEach((object) => {124 const pObject = {125 id: object.id,126 type: camelizeTypeValues ? camelCase(object.type) : object.type,127 };128 if (object.relationships) {129 pObject.relationships = extractRelationships(object.relationships, {130 camelizeKeys,131 camelizeTypeValues,132 });133 }134 meta.push(pObject);135 });136 metaObject.data = meta;137 }138 if (json.links) {139 metaObject.links = json.links;140 ret.meta[doFilterEndpoint(endpoint)].links = json.links;141 }142 if (json.meta) {143 metaObject.meta = processMeta(json.meta, { camelizeKeys });144 }145 return ret;146}147export default function normalize(json, {148 filterEndpoint = true,149 camelizeKeys = true,150 camelizeTypeValues = true,151 endpoint,152} = {}) {153 const ret = {};154 if (json.data) {155 merge(ret, extractEntities(json.data, { camelizeKeys, camelizeTypeValues }));156 }157 if (json.included) {158 merge(ret, extractEntities(json.included, { camelizeKeys, camelizeTypeValues }));159 }160 if (endpoint) {161 const endpointKey = filterEndpoint ? doFilterEndpoint(endpoint) : endpoint;162 merge(ret, extractMetaData(json, endpointKey, {163 camelizeKeys,164 camelizeTypeValues,165 filterEndpoint,166 }));167 }168 return ret;...
camelize.py
Source: camelize.py
...57 new[new_key] = _camelize_other_iterable(value, capitalized, strip_underscores)58 else:59 new[new_key] = value60 return new61def camelize(62 element: typing.Any,63 capitalized: bool = False,64 strip_underscores: bool = False,65 camelize_mapping_values: bool = False,66) -> typing.Any:67 if isinstance(element, typing.Mapping):68 return _camelize_mapping(element, capitalized, strip_underscores, camelize_mapping_values)69 elif isinstance(element, str):70 return _camelize_string(element, capitalized, strip_underscores)71 elif isinstance(element, typing.Iterable):72 return _camelize_other_iterable(element, capitalized, strip_underscores)...
test_camelize.py
Source: test_camelize.py
1from collections import defaultdict2from datetime import date3from snakecamel import camelize4def test_camelize_empty_string() -> None:5 assert camelize("") == ""6def test_camelize_simple_string() -> None:7 assert camelize("snake_string") == "snakeString"8def test_campelize_simple_string_capitalized() -> None:9 assert camelize("snake_string", capitalized=True) == "SnakeString"10def test_camelize_outside_underscores() -> None:11 assert camelize("_snake_string__") == "_snakeString__"12def test_camelize_trim_outside_underscores() -> None:13 assert camelize("_snake_string__", strip_underscores=True) == "snakeString"14def test_camelize_trim_outside_underscores_capitalized() -> None:15 assert camelize("_snake_string__", strip_underscores=True, capitalized=True) == "SnakeString"16def test_camelize_simple_mapping() -> None:17 assert camelize({"simple_key": "simple_value"}) == {"simpleKey": "simple_value"}18def test_camelize_simple_mapping_camelize_values() -> None:19 assert camelize({"simple_key": "simple_value"}, camelize_mapping_values=True) == {20 "simpleKey": "simpleValue"21 }22def test_camelize_nested_mapping() -> None:23 assert camelize(24 {"simple_key": "simple_value", "complex_key": {"nested_key": "nested_value"}}25 ) == {"simpleKey": "simple_value", "complexKey": {"nestedKey": "nested_value"}}26def test_camelize_mapping_nested_iterable() -> None:27 assert camelize(28 {"simple_key": ["first_value", "second_value"]}, camelize_mapping_values=True29 ) == {"simpleKey": ["firstValue", "secondValue"]}30def test_camelize_mapping_not_dict() -> None:31 d = defaultdict(list)32 d["simple_string"].append("simple_value")33 assert camelize(d, camelize_mapping_values=True) == {"simpleString": ["simpleValue"]}34def test_camelize_simple_list() -> None:35 assert camelize(["simple_string"]) == ["simpleString"]36def test_camelize_iterable_string_iterable() -> None:37 assert camelize(["simple_string", ["another_simple_string"]]) == [38 "simpleString",39 ["anotherSimpleString"],40 ]41def test_camelize_simple_set() -> None:42 assert camelize({"simple_string"}) == {"simpleString"}43def test_camelize_simple_tuple() -> None:44 assert camelize(("simple_string",)) == ("simpleString",)45def test_camelize_iterable_with_non_camelized_type() -> None:46 assert camelize(["simple_string", 5]) == ["simpleString", 5]47def test_camelize_iterable_with_mapping() -> None:48 assert camelize(["simple_string", {"simple_key": "simple_value"}]) == [49 "simpleString",50 {"simpleKey": "simple_value"},51 ]52def test_camelize_unknown_type() -> None:53 assert camelize(date.today()) == date.today()54def test_camelize_complex_dictionary() -> None:55 assert camelize(56 {57 "simple_key": "simple_value",58 "list_key": ["list_value"],59 "set_key": {"set_value"},60 5: "hello",61 "nested_key": {"nested_key_again": "nested_value"},62 },63 camelize_mapping_values=True,64 ) == {65 "simpleKey": "simpleValue",66 "listKey": ["listValue"],67 "setKey": {"setValue"},68 5: "hello",69 "nestedKey": {"nestedKeyAgain": "nestedValue"},...
camelize.spec.js
Source: camelize.spec.js
...7 it('has a filterCamelize filter', function () {8 expect(camelize).not.toBeNull();9 });10 it('should return camelized strings', function () {11 expect(camelize('test')).toBe('test');12 expect(camelize('test_string')).toBe('testString');13 expect(camelize('test-string')).toBe('testString'); 14 expect(camelize('test_long_string')).toBe('testLongString'); 15 expect(camelize('test-long-string')).toBe('testLongString'); 16 });17 18 it('should return totally camelized strings with a first=true parameter', function () {19 expect(camelize('test', true)).toBe('Test');20 expect(camelize('test_string', true)).toBe('TestString');21 expect(camelize('test-string', true)).toBe('TestString'); 22 expect(camelize('test_long_string', true)).toBe('TestLongString'); 23 expect(camelize('test-long-string', true)).toBe('TestLongString'); 24 });25 26 it('should not camelize trailing underscores', function () {27 expect(camelize('_test_string')).toBe('_testString');28 expect(camelize('_test_long_string')).toBe('_testLongString');29 expect(camelize('test_string_')).toBe('testString_');30 expect(camelize('test_long_string_')).toBe('testLongString_');31 });32 33 it('should deal with (multiple) spaces', function () {34 expect(camelize('the camelize string method')).toBe('theCamelizeStringMethod');35 expect(camelize(' the-camelize string method')).toBe('theCamelizeStringMethod');36 expect(camelize('the camelize string_method')).toBe('theCamelizeStringMethod');37 });38 39 it('should return empty strings for empty/weird inputs', function () {40 expect(camelize('')).toBe('');41 expect(camelize(null)).toBe('');42 expect(camelize(undefined)).toBe('');43 expect(camelize()).toBe('');44 expect(camelize(NaN)).toBe('');45 expect(camelize(beforeEach)).toBe('');46 });47 48 it('should stringify non-string values', function () {49 expect(camelize(0)).toBe('0');50 expect(camelize(1)).toBe('1');51 expect(camelize(-1)).toBe('-1');52 expect(camelize(Infinity)).toBe('Infinity'); 53 expect(camelize(-Infinity)).toBe('-Infinity'); 54 expect(camelize(true)).toBe('true'); 55 expect(camelize(false)).toBe('false'); 56 });...
camelize.js
Source: camelize.js
1var equal = require('assert').equal;2var camelize = require('../camelize');3test('#camelize', function(){4 equal(camelize('the_camelize_string_method'), 'theCamelizeStringMethod');5 equal(camelize('webkit-transform'), 'webkitTransform');6 equal(camelize('-the-camelize-string-method'), 'TheCamelizeStringMethod');7 equal(camelize('_the_camelize_string_method'), 'TheCamelizeStringMethod');8 equal(camelize('The-camelize-string-method'), 'TheCamelizeStringMethod');9 equal(camelize('the camelize string method'), 'theCamelizeStringMethod');10 equal(camelize(' the camelize string method'), 'theCamelizeStringMethod');11 equal(camelize('the camelize string method'), 'theCamelizeStringMethod');12 equal(camelize(' with spaces'), 'withSpaces');13 equal(camelize("_som eWeird---name-"), 'SomEWeirdName');14 equal(camelize(''), '', 'Camelize empty string returns empty string');15 equal(camelize(null), '', 'Camelize null returns empty string');16 equal(camelize(undefined), '', 'Camelize undefined returns empty string');17 equal(camelize(123), '123');18 equal(camelize('the_camelize_string_method', true), 'theCamelizeStringMethod');19 equal(camelize('webkit-transform', true), 'webkitTransform');20 equal(camelize('-the-camelize-string-method', true), 'theCamelizeStringMethod');21 equal(camelize('_the_camelize_string_method', true), 'theCamelizeStringMethod');22 equal(camelize('The-camelize-string-method', true), 'theCamelizeStringMethod');23 equal(camelize('the camelize string method', true), 'theCamelizeStringMethod');24 equal(camelize(' the camelize string method', true), 'theCamelizeStringMethod');25 equal(camelize('the camelize string method', true), 'theCamelizeStringMethod');26 equal(camelize(' with spaces', true), 'withSpaces');27 equal(camelize("_som eWeird---name-", true), 'somEWeirdName');28 equal(camelize('', true), '', 'Camelize empty string returns empty string');29 equal(camelize(null, true), '', 'Camelize null returns empty string');30 equal(camelize(undefined, true), '', 'Camelize undefined returns empty string');31 equal(camelize(123, true), '123');...
test_utils.py
Source: test_utils.py
...7 assert len(reporter_fields) == len(reporter_name_set)8 film_fields = get_model_fields(Film)9 film_name_set = set([field[0] for field in film_fields])10 assert len(film_fields) == len(film_name_set)11def test_camelize():12 assert camelize({}) == {}13 assert camelize("value_a") == "value_a"14 assert camelize({"value_a": "value_b"}) == {"valueA": "value_b"}15 assert camelize({"value_a": ["value_b"]}) == {"valueA": ["value_b"]}16 assert camelize({"value_a": ["value_b"]}) == {"valueA": ["value_b"]}17 assert camelize({"nested_field": {"value_a": ["error"], "value_b": ["error"]}}) == {18 "nestedField": {"valueA": ["error"], "valueB": ["error"]}19 }20 assert camelize({"value_a": gettext_lazy("value_b")}) == {"valueA": "value_b"}21 assert camelize({"value_a": [gettext_lazy("value_b")]}) == {"valueA": ["value_b"]}22 assert camelize(gettext_lazy("value_a")) == "value_a"23 assert camelize({gettext_lazy("value_a"): gettext_lazy("value_b")}) == {24 "valueA": "value_b"25 }...
camelize_vx.x.x.js
Source: camelize_vx.x.x.js
1// flow-typed signature: b22467475afd53c4ead3ab690219f05f2// flow-typed version: <<STUB>>/camelize_v^1.0.0/flow_v0.52.03/**4 * This is an autogenerated libdef stub for:5 *6 * 'camelize'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the11 * community by sending a pull request to:12 * https://github.com/flowtype/flow-typed13 */14declare module 'camelize' {15 declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22declare module 'camelize/example/camel' {23 declare module.exports: any;24}25declare module 'camelize/test/camel' {26 declare module.exports: any;27}28// Filename aliases29declare module 'camelize/example/camel.js' {30 declare module.exports: $Exports<'camelize/example/camel'>;31}32declare module 'camelize/index' {33 declare module.exports: $Exports<'camelize'>;34}35declare module 'camelize/index.js' {36 declare module.exports: $Exports<'camelize'>;37}38declare module 'camelize/test/camel.js' {39 declare module.exports: $Exports<'camelize/test/camel'>;...
Using AI Code Generation
1const { camelize } = require('@playwright/test/lib/utils/utils');2console.log(camelize('hello-world'));3const { camelize } = require('@playwright/test/lib/utils/utils');4console.log(camelize('hello-world'));5const { camelize } = require('@playwright/test/lib/utils/utils');6console.log(camelize('hello-world'));7const { camelize } = require('@playwright/test/lib/utils/utils');8console.log(camelize('hello-world'));9const { camelize } = require('@playwright/test/lib/utils/utils');10console.log(camelize('hello-world'));11const { camelize } = require('@playwright/test/lib/utils/utils');12console.log(camelize('hello-world'));13const { camelize } = require('@playwright/test/lib/utils/utils');14console.log(camelize('hello-world'));15const { camelize } = require('@playwright/test/lib/utils/utils');16console.log(camelize('hello-world'));17const { camelize } = require('@playwright/test/lib/utils/utils');18console.log(camelize('hello-world'));19const { camelize } = require('@playwright/test/lib/utils/utils');20console.log(camelize('hello-world'));21const { camelize } = require('@playwright/test/lib/utils/utils');22console.log(camelize('hello-world'));23const { camelize } = require('@playwright/test/lib/utils/utils');24console.log(camelize('hello-world'));25const { camelize } = require('@playwright/test/lib/utils/utils');26console.log(camelize('hello-world'));27const { camelize } = require('@playwright/test/lib/utils/utils');28console.log(camelize('hello-world'));29const { camelize } = require('@
Using AI Code Generation
1const { camelize } = require('playwright/lib/utils/utils');2const camelizedString = camelize('test-string');3console.log(camelizedString);4const { camelize } = require('playwright/lib/utils/utils');5const camelizedString = camelize('test-string');6console.log(camelizedString);7const { waitForEvent } = require('playwright/lib/utils/utils');8const page = await browser.newPage();9const event = await waitForEvent(page, 'domcontentloaded');10console.log(event);
Using AI Code Generation
1const { camelize } = require('playwright/lib/utils/utils');2const text = 'some text';3const camelizedText = camelize(text);4console.log(camelizedText);5const { utils } = require('playwright');6const text = 'some text';7const camelizedText = utils.camelize(text);8console.log(camelizedText);9const { utils } = require('playwright');10const text = 'some text';11const camelizedText = utils.camelize(text);12console.log(camelizedText);13const { utils } = require('playwright');14const text = 'some text';15const camelizedText = utils.camelize(text);16console.log(camelizedText);17const { utils } = require('playwright');18const text = 'some text';19const camelizedText = utils.camelize(text);20console.log(camelizedText);21const { utils } = require('playwright');22const text = 'some text';23const camelizedText = utils.camelize(text);24console.log(camelizedText);25const { utils } = require('
Jest + Playwright - Test callbacks of event-based DOM library
firefox browser does not start in playwright
Is it possible to get the selector from a locator object in playwright?
How to run a list of test suites in a single file concurrently in jest?
Running Playwright in Azure Function
firefox browser does not start in playwright
This question is quite close to a "need more focus" question. But let's try to give it some focus:
Does Playwright has access to the cPicker object on the page? Does it has access to the window object?
Yes, you can access both cPicker and the window object inside an evaluate call.
Should I trigger the events from the HTML file itself, and in the callbacks, print in the DOM the result, in some dummy-element, and then infer from that dummy element text that the callbacks fired?
Exactly, or you can assign values to a javascript variable:
const cPicker = new ColorPicker({
onClickOutside(e){
},
onInput(color){
window['color'] = color;
},
onChange(color){
window['result'] = color;
}
})
And then
it('Should call all callbacks with correct arguments', async() => {
await page.goto(`http://localhost:5000/tests/visual/basic.html`, {waitUntil:'load'})
// Wait until the next frame
await page.evaluate(() => new Promise(requestAnimationFrame))
// Act
// Assert
const result = await page.evaluate(() => window['color']);
// Check the value
})
Check out the latest blogs from LambdaTest on this topic:
Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
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!!