Best JavaScript code snippet using playwright-internal
services.js
Source: services.js
1angular.module('starter.services', [])2.factory('Chats', function() {3 // Might use a resource here that returns a JSON array4 // Some fake testing data5 var chats = [{6 id: 0,7 name: 'Ben Sparrow',8 lastText: 'You on your way?',9 face: 'https://pbs.twimg.com/profile_images/514549811765211136/9SgAuHeY.png'10 }, {11 id: 1,12 name: 'Max Lynx',13 lastText: 'Hey, it\'s me',14 face: 'https://avatars3.githubusercontent.com/u/11214?v=3&s=460'15 }, {16 id: 2,17 name: 'Adam Bradleyson',18 lastText: 'I should buy a boat',19 face: 'https://pbs.twimg.com/profile_images/479090794058379264/84TKj_qa.jpeg'20 }, {21 id: 3,22 name: 'Perry Governor',23 lastText: 'Look at my mukluks!',24 face: 'https://pbs.twimg.com/profile_images/598205061232103424/3j5HUXMY.png'25 }, {26 id: 4,27 name: 'Mike Harrington',28 lastText: 'This is wicked good ice cream.',29 face: 'https://pbs.twimg.com/profile_images/578237281384841216/R3ae1n61.png'30 }];31 return {32 all: function() {33 return chats;34 },35 remove: function(chat) {36 chats.splice(chats.indexOf(chat), 1);37 },38 get: function(chatId) {39 for (var i = 0; i < chats.length; i++) {40 if (chats[i].id === parseInt(chatId)) {41 return chats[i];42 }43 }44 return null;45 }46 };47});48angular.module('AggiesLand.services',[]).factory('News',['$http','PARSE_CREDENTIALS',function($http,PARSE_CREDENTIALS){49 50 var object = {51 text: "",52 image: null53 };54 55 return {56 getAll:function(){57 return $http.get('https://parseapi.back4app.com/classes/News',{58 headers:{59 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,60 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,61 'Content-Type':'application/json'62 }63 });64 },65 get:function(id){66 return $http.get('https://parseapi.back4app.com/classes/News/'+id,{67 headers:{68 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,69 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,70 'Content-Type':'application/json'71 }72 });73 },74 create:function(data){ 75 return $http.post('https://parseapi.back4app.com/classes/News',data,{76 headers:{77 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,78 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,79 'Content-Type':'application/json'80 }81 });82 },83 edit:function(id,data){84 return $http.put('https://parseapi.back4app.com/classes/News/'+id,data,{85 headers:{86 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,87 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,88 'Content-Type':'application/json'89 }90 });91 },92 delete:function(id){93 return $http.delete('https://parseapi.back4app.com/classes/News/'+id,{94 headers:{95 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,96 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,97 'Content-Type':'application/json'98 }99 });100 }101 102 }103 104}]).value('PARSE_CREDENTIALS',{105 APP_ID: '5b91v6F6A0GaeC64FuIgeCctYaEM81LFybSR4g7K',106 REST_API_KEY:'4nWl2C1geJnmfhGoxykM7gAKxUvVah5wSN951Ksq'107})108.factory('CampusEvents',['$http','PARSE_CREDENTIALS',function($http,PARSE_CREDENTIALS){109 110 return {111 getAll:function(){112 return $http.get('https://parseapi.back4app.com/classes/CampusEvents',{113 headers:{114 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,115 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,116 'Content-Type':'application/json' }117 });118 },119 get:function(id){120 return $http.get('https://parseapi.back4app.com/classes/CampusEvents/'+id,{121 headers:{122 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,123 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,124 'Content-Type':'application/json' }125 });126 },127 create:function(data){128 return $http.post('https://parseapi.back4app.com/classes/CampusEvents',data,{129 headers:{130 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,131 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,132 'Content-Type':'application/json'133 }134 });135 },136 edit:function(id,data){137 return $http.put('https://parseapi.back4app.com/classes/CampusEvens/'+id,data,{138 headers:{139 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,140 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,141 'Content-Type':'application/json'142 }143 });144 },145 delete:function(id){146 return $http.delete('https://parseapi.back4app.com/classes/CampusEvents/'+id,{147 headers:{148 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,149 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,150 'Content-Type':'application/json'151 }152 });153 }154 }155 156}]).value('PARSE_CREDENTIALS',{157 APP_ID: '5b91v6F6A0GaeC64FuIgeCctYaEM81LFybSR4g7K',158 REST_API_KEY:'4nWl2C1geJnmfhGoxykM7gAKxUvVah5wSN951Ksq'159})160.factory('Clubs',['$http','PARSE_CREDENTIALS',function($http,PARSE_CREDENTIALS){161 162 return {163 getAll:function(){164 return $http.get('https://parseapi.back4app.com/classes/Clubs?include=CreatedBy',{165 headers:{166 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,167 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,168 'Content-Type':'application/json',169 params: { include: 'CreatedBy'}170 171 }172 });173 },174 get:function(id){175 return $http.get('https://parseapi.back4app.com/classes/Clubs/'+id,{176 headers:{177 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,178 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,179 'Content-Type':'application/json'180 }181 });182 },183 create:function(data){184 return $http.post('https://parseapi.back4app.com/classes/Clubs',data,{185 headers:{186 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,187 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,188 'Content-Type':'application/json'189 }190 });191 },192 edit:function(id,data){193 return $http.put('https://parseapi.back4app.com/classes/Clubs/'+id,data,{194 headers:{195 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,196 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,197 'Content-Type':'application/json'198 }199 });200 },201 delete:function(id){202 return $http.delete('https://parseapi.back4app.com/classes/Clubs/'+id,{203 headers:{204 'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,205 'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,206 'Content-Type':'application/json'207 }208 });209 }210 }211 212}]).value('PARSE_CREDENTIALS',{213 APP_ID: '5b91v6F6A0GaeC64FuIgeCctYaEM81LFybSR4g7K',214 REST_API_KEY:'4nWl2C1geJnmfhGoxykM7gAKxUvVah5wSN951Ksq'215})216.factory('Photo', function () {217 return {218 convertImageToBase64: function (url, callback, output) {219 var img = new Image();220 img.crossOrigin = 'Anonymous';221 img.onload = function(){222 var canvas = document.createElement('CANVAS'),223 c = canvas.getContext('2d'), urlData;224 canvas.height = this.height;225 canvas.width = this.width;226 c.drawImage(this, 0, 0);227 urlData = canvas.toDataURL(output);228 callback(urlData);229 canvas = null;230 };231 img.src = url;232 }233 };234})...
google-parse-auth-test.js
Source: google-parse-auth-test.js
1var assert = require("assert");2var sinon = require("sinon");3var nock = require("nock");4var GoogleParseAuth = require("google-parse-auth").GoogleParseAuth;5var GOOGLE_CONSUMER_KEY = "googleconsumerkey";6var GOOGLE_CONSUMER_SECRET = "googleconsumersecret";7describe('GoogleParseAuth', function() {8 describe('refreshAccessToken', function() {9 it("should return the new access token in a callback and save it in parse", function(done) {10 var parseAPI = {11 find: function(){},12 update: function(){}13 };14 var find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {15 console.log("(*) Called find on parse");16 callback(null, {google_refresh_token: 'refreshtoken'});17 });18 var update_stub = sinon.stub(parseAPI, "update", function(clazz, id, data, callback) {19 console.log("(*) called update on parse");20 callback(null, {});21 });22 var response = {access_token: "newtoken",23 expires_in:3920,24 token_type:"Bearer"25 };26 var google = nock('https://accounts.google.com')27 .log(console.log)28 .post('/o/oauth2/token', "refresh_token=refreshtoken" +29 "&client_id=" + GOOGLE_CONSUMER_KEY +30 "&client_secret=" + GOOGLE_CONSUMER_SECRET +31 "&grant_type=refresh_token")32 .reply(200, response, {'Content-Type': 'application/json'});33 var google_parse_auth = new GoogleParseAuth(parseAPI, 34 GOOGLE_CONSUMER_KEY, 35 GOOGLE_CONSUMER_SECRET);36 google_parse_auth.refreshAccessToken('myID', function(new_access_token) {37 assert.equal(new_access_token, 'newtoken');38 assert(find_stub.called);39 assert(update_stub.called);40 done();41 });42 });43 });44 describe("retrieveAccessToken", function() {45 it("should retrieve an access token from parse and then call the callback", function(done) {46 var parseAPI = {47 find: function(){},48 update: function(callback){callback()}49 };50 var find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {51 console.log("(*) Called find on parse");52 assert.equal(id, "userId");53 callback(null, {google_refresh_token: 'refreshtoken', google_access_token: 'authtoken'});54 });55 var google_parse_auth = new GoogleParseAuth(parseAPI, 56 GOOGLE_CONSUMER_KEY, 57 GOOGLE_CONSUMER_SECRET);58 google_parse_auth.retrieveAccessToken("userId", function(err, token) {59 assert.equal("authtoken", token);60 done();61 });62 });63 });64 describe("makeAuthenticatedCall", function() {65 var parseAPI;66 var find_stub;67 beforeEach(function() {68 parseAPI = {69 find: function(){},70 update: function(callback){callback()}71 }72 });73 it("should be able to make a call using the access token it gets from parse", function(done) {74 var test_module = {75 test_method: function(token, arg2, callback) {76 }77 }78 find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {79 console.log("(*) Called find on parse");80 callback(null, {google_refresh_token: 'refreshtoken', google_access_token: 'authtoken'});81 });82 var method_stub = sinon.stub(test_module, "test_method", function(token, arg2, callback) {83 console.log("Args length: ", arguments.length);84 assert.equal("authtoken", token);85 assert.equal(2, arg2);86 callback(false, "events");87 });88 var google_parse_auth = new GoogleParseAuth(parseAPI, 89 GOOGLE_CONSUMER_KEY, 90 GOOGLE_CONSUMER_SECRET);91 google_parse_auth.makeAuthenticatedCall("userId", test_module, test_module.test_method, 2, function(err, data) {92 assert.equal(data, "events");93 assert(method_stub.called);94 done();95 });96 }); 97 it("should work on a function with no extra arguments", function(done) {98 var test_module = {99 test_method: function(token, callback) {100 }101 }102 find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {103 console.log("(*) Called find on parse");104 callback(null, {google_refresh_token: 'refreshtoken', google_access_token: 'authtoken'});105 });106 var method_stub = sinon.stub(test_module, "test_method", function(token, callback) {107 console.log("Args length: ", arguments.length);108 assert.equal("authtoken", token);109 callback(false, "events");110 });111 var google_parse_auth = new GoogleParseAuth(parseAPI, 112 GOOGLE_CONSUMER_KEY, 113 GOOGLE_CONSUMER_SECRET);114 google_parse_auth.makeAuthenticatedCall("userId", test_module, test_module.test_method, function(err, data) {115 assert.equal(data, "events");116 assert(method_stub.called);117 done();118 });119 });120 it("should be able to successfully retrieve a refresh token if the access token is bad", function(done) {121 function api_method(token, arg2, callback) {122 if (token == "authtoken") {123 callback(false, "events");124 } else {125 console.log("Oops, old token");126 callback(new Error(), "error, old token");127 }128 }129 var test_module = {130 test_method: api_method131 }132 find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {133 console.log("(*) Called find on parse");134 callback(null, {google_refresh_token: 'refreshtoken', google_access_token: 'oldtoken'});135 });136 var update_stub = sinon.stub(parseAPI, "update", function(clazz, id, data, callback) {137 console.log("(*) called update on parse");138 callback(null, {});139 });140 var response = {access_token: "authtoken",141 expires_in:3920,142 token_type:"Bearer"143 };144 var google = nock('https://accounts.google.com')145 .log(console.log)146 .post('/o/oauth2/token', "refresh_token=refreshtoken" +147 "&client_id=" + GOOGLE_CONSUMER_KEY +148 "&client_secret=" + GOOGLE_CONSUMER_SECRET +149 "&grant_type=refresh_token")150 .reply(200, response, {'Content-Type': 'application/json'});151 var google_parse_auth = new GoogleParseAuth(parseAPI, 152 GOOGLE_CONSUMER_KEY, 153 GOOGLE_CONSUMER_SECRET);154 function finalCallback(err, data) {155 assert.equal(data, "events");156 done();157 }158 google_parse_auth.makeAuthenticatedCall("userId", test_module, test_module.test_method, 2, finalCallback);159 });160 it("should just return an error if it can't get a good token", function(done) {161 function api_method(token, arg2, callback) {162 if (token == "authtoken") {163 callback(null, "events");164 } else {165 callback(new Error(), "error, old token");166 }167 }168 var test_module = {169 test_method: api_method170 }171 find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {172 console.log("(*) Called find on parse");173 callback(null, {google_refresh_token: 'refreshtoken', google_access_token: 'oldtoken'});174 });175 var update_stub = sinon.stub(parseAPI, "update", function(clazz, id, data, callback) {176 console.log("(*) called update on parse");177 callback(null, {});178 });179 var response = {access_token: "nope, sorry",180 expires_in:3920,181 token_type:"Bearer"182 };183 var google = nock('https://accounts.google.com')184 .log(console.log)185 .post('/o/oauth2/token', "refresh_token=refreshtoken" +186 "&client_id=" + GOOGLE_CONSUMER_KEY +187 "&client_secret=" + GOOGLE_CONSUMER_SECRET +188 "&grant_type=refresh_token")189 .reply(200, response, {'Content-Type': 'application/json'});190 var google_parse_auth = new GoogleParseAuth(parseAPI, 191 GOOGLE_CONSUMER_KEY, 192 GOOGLE_CONSUMER_SECRET);193 function finalCallback(err, data) {194 assert(err);195 done();196 }197 google_parse_auth.makeAuthenticatedCall("userId", test_module, test_module.test_method, 2, finalCallback);198 });199 });...
google-calendar-parse-test.js
Source: google-calendar-parse-test.js
1var assert = require("assert");2var sinon = require("sinon");3var nock = require("nock");4var GoogleCalendarParse = require("google-calendar-parse").GoogleCalendarParse;5var GOOGLE_CONSUMER_KEY = "googleconsumerkey";6var GOOGLE_CONSUMER_SECRET = "googleconsumersecret";7describe("GoogleCalendarParse", function() {8 describe("listCalendarList", function() {9 var parseAPI;10 var find_stub;11 var update_stub;12 beforeEach(function() {13 parseAPI = {14 find: function(){},15 update: function(){}16 };17 find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {18 console.log("(*) Called find on parse");19 callback(null, {google_refresh_token: 'refreshtoken', google_access_token: "accesstoken"});20 });21 update_stub = sinon.stub(parseAPI, "update", function(clazz, id, data, callback) {22 console.log("(*) called update on parse");23 callback(null, {});24 });25 });26 it("Should just make the request like normal if it gets a token from parse", function(done) {27 var google = nock('https://www.googleapis.com')28 .log(console.log)29 .get('/calendar/v3/users/me/calendarList?access_token=accesstoken&key=googleconsumerkey')30 .reply(200, {calendar: 'success'}, {'Content-Type': 'application/json'});31 var google_calendar_parse = new GoogleCalendarParse(parseAPI, GOOGLE_CONSUMER_KEY, GOOGLE_CONSUMER_SECRET);32 google_calendar_parse.listCalendarList("user_id", function(err, data) {33 assert.equal(data.calendar, "success");34 done();35 });36 });37 it("Should just pass through the error if it receives a 401 in response", function(done) {38 var google = nock('https://www.googleapis.com')39 .log(console.log)40 .get('/calendar/v3/users/me/calendarList?access_token=accesstoken&key=googleconsumerkey')41 .reply(401, {calendar: 'faillll'}, {'Content-Type': 'application/json'});42 var google_calendar_parse = new GoogleCalendarParse(parseAPI, GOOGLE_CONSUMER_KEY, GOOGLE_CONSUMER_SECRET);43 google_calendar_parse.listCalendarList("user_id", function(err, data) {44 done();45 });46 });47 });48 describe("listEvent", function() {49 var parseAPI;50 var find_stub;51 var update_stub;52 beforeEach(function() {53 parseAPI = {54 find: function(){},55 update: function(){}56 };57 find_stub = sinon.stub(parseAPI, "find", function(clazz, id, callback) {58 console.log("(*) Called find on parse");59 callback(null, {google_refresh_token: 'refreshtoken', google_access_token: "accesstoken"});60 });61 update_stub = sinon.stub(parseAPI, "update", function(clazz, id, data, callback) {62 console.log("(*) called update on parse");63 callback(null, {});64 });65 });66 it("Should list the events for a calendar", function(done) {67 var google = nock('https://www.googleapis.com')68 .log(console.log)69 .get('/calendar/v3/calendars/1/events?access_token=accesstoken&key=googleconsumerkey')70 .reply(200, [{summary: 'success'}], {'Content-Type': 'application/json'});71 var google_calendar_parse = new GoogleCalendarParse(parseAPI, GOOGLE_CONSUMER_KEY, GOOGLE_CONSUMER_SECRET);72 google_calendar_parse.listEvent("user_id", 1, {}, function(err, data) {73 assert.equal(data[0].summary, "success");74 done();75 });76 });77 });...
index.js
Source: index.js
1import { fork } from 'redux-saga/effects'2import API from '../Services/Api'3import ParseAPI from '../Services/ParseAPI'4import FixtureAPI from '../Services/FixtureApi'5import { watchStartup } from './StartupSaga'6import loadContacts from './LoadContactsSaga'7import resetPassword from './ResetPasswordSaga'8import updatePassword from './UpdatePasswordSaga'9import updateProfile from './UpdateProfileSaga'10import createInstallation from './CreateInstallationSaga'11import login from './LoginSaga'12import pushPermissions from './PushPermissionsSaga'13import logout from './LogoutSaga'14import getCityWeather from './GetCityWeatherSaga'15import createPhoneNumber from './CreatePhoneNumberSaga'16import verifyAccessCode from './VerifyAccessCodeSaga'17import createUser from './CreateUserSaga'18import deleteUser from './DeleteUserSaga'19import sendPushToUser from './SendPushToUserSaga'20import provisionDevice from './ProvisionDeviceSaga'21import playNotificationSound from './PlayNotificationSoundSaga'22import playSuccessSound from './PlaySuccessSoundSaga'23import deleteDevice from './DeleteDeviceSaga'24import createAddress from './CreateAddressSaga'25import deleteAddress from './DeleteAddressSaga'26import deleteMonitor from './DeleteMonitorSaga'27import getAddresses from './GetAddressesSaga'28import getConfig from './GetConfigSaga'29import getDevices from './GetDevicesSaga'30import getDeviceActivity from './GetDeviceActivitySaga'31import getDeviceClimate from './GetDeviceClimateSaga'32import getMonitors from './GetMonitorsSaga'33import updateDevice from './UpdateDeviceSaga'34import { pollDevices } from './PollDevicesSaga'35import saveAddress from './SaveAddressSaga'36import snoozeDevice from './SnoozeDeviceSaga'37import getAlarmModels from './GetAlarmModelsSaga'38import createMonitor from './CreateMonitorSaga'39import createPromotion from './CreatePromotionSaga'40import updateInvitation from './UpdateInvitationSaga'41import DebugSettings from '../Config/DebugSettings'42// Create our API at this level and feed it into43// the sagas that are expected to make API calls44// so there's only 1 copy app-wide!45// const api = API.create()46const api = DebugSettings.useFixtures ? FixtureAPI : API.create()47const parseApi = ParseAPI.create()48// start the daemons49export default function * root () {50 yield fork(watchStartup)51 yield fork(loadContacts.watcher)52 yield fork(resetPassword(parseApi).watcher)53 yield fork(updatePassword(parseApi).watcher)54 yield fork(updateProfile(parseApi).watcher)55 yield fork(createInstallation(parseApi).watcher)56 yield fork(login(parseApi).watcher)57 yield fork(pushPermissions(parseApi).watcher)58 yield fork(logout(parseApi).watcher)59 yield fork(getCityWeather(api).watcher)60 yield fork(createPhoneNumber(parseApi).watcher)61 yield fork(verifyAccessCode(parseApi).watcher)62 yield fork(createUser(parseApi).watcher)63 yield fork(deleteUser(parseApi).watcher)64 yield fork(sendPushToUser(parseApi).watcher)65 yield fork(provisionDevice(parseApi).watcher)66 yield fork(playNotificationSound.watcher)67 yield fork(playSuccessSound().watcher)68 yield fork(deleteDevice(parseApi).watcher)69 yield fork(createAddress(parseApi).watcher)70 yield fork(deleteAddress(parseApi).watcher)71 yield fork(deleteMonitor(parseApi).watcher)72 yield fork(getAddresses(parseApi).watcher)73 yield fork(getConfig(parseApi).watcher)74 yield fork(getDevices(parseApi).watcher)75 yield fork(getDeviceActivity(parseApi).watcher)76 yield fork(getDeviceClimate(parseApi).watcher)77 yield fork(getMonitors(parseApi).watcher)78 yield fork(updateDevice(parseApi).watcher)79 yield fork(pollDevices)80 yield fork(saveAddress(parseApi).watcher)81 yield fork(snoozeDevice(parseApi).watcher)82 yield fork(getAlarmModels(parseApi).watcher)83 yield fork(createMonitor(parseApi).watcher)84 yield fork(createPromotion(parseApi).watcher)85 yield fork(updateInvitation(parseApi).watcher)...
formHandler.test.js
Source: formHandler.test.js
...41 "sentimented_concept_list": []42}43describe("Test Api Parser", () => {44 test("should recognize agreement", () => {45 expect(parseApi(mockUpResponse).isAgreeing).toBe(true);46 });47 test("should recognize isObjective", () => {48 expect(parseApi(mockUpResponse).isObjective).toBe(true);49 });50 test("should recognize isIronic", () => {51 expect(parseApi(mockUpResponse).isIronic).toBe(false);52 });53 test("should recognize score", () => {54 expect(parseApi(mockUpResponse).confidence).toBe(100);55 });56 test("should recognize len of sentences", () => {57 expect(parseApi(mockUpResponse).totalSentences).toBe(1);58 });59 test("should recognize sentiment none", () => {60 expect(parseApi(mockUpResponse).sentiment).toBe("no");61 });62 test("should recognize sentiment neutral", () => {63 mockUpResponse.score_tag = "NEU";64 expect(parseApi(mockUpResponse).sentiment).toBe("neutral");65 });66 test("should recognize sentiment positive", () => {67 mockUpResponse.score_tag = "P";68 expect(parseApi(mockUpResponse).sentiment).toBe("positive");69 });70 test("should recognize sentiment p+ as positive", () => {71 mockUpResponse.score_tag = "P+";72 expect(parseApi(mockUpResponse).sentiment).toBe("positive");73 });74 test("should recognize sentiment negative", () => {75 mockUpResponse.score_tag = "N";76 expect(parseApi(mockUpResponse).sentiment).toBe("negative");77 });78 test("should recognize sentiment n+", () => {79 mockUpResponse.score_tag = "N+";80 expect(parseApi(mockUpResponse).sentiment).toBe("negative");81 });82 test("should recognize sentiment unknown response", () => {83 mockUpResponse.score_tag = "random new response";84 expect(parseApi(mockUpResponse).sentiment).toBe("unknown");85 });...
User.js
Source: User.js
1/**2 * @author -> Dare McAdewole3 */4import Vue from 'vue'5const ParseAPI = Vue.prototype.$parseapi6export default class User {7 /**8 * 9 * @param {object} user10 * @returns {Promise}11 */12 static create(user) {13 return ParseAPI({14 method: 'POST',15 url: 'users/',16 data: user17 })18 }19 /**20 * 21 * @param {string} username22 * @param {string} password23 * @returns {Promise}24 */25 static authenticate(username, password) {26 return ParseAPI({27 method: 'GET',28 url: `login?username=${username}&password=${password}`29 })30 }31 /**32 * 33 * @param {string} objectId 34 * @returns {Promise}35 */36 static get(objectId) {37 return ParseAPI({38 method: 'GET',39 url: `users/${objectId}`40 })41 }42 /**43 * @param {null}44 * @returns {Promise}45 */46 static getAll() {47 return ParseAPI({48 method: 'GET',49 url: 'users'50 })51 }52 /**53 * 54 * @param {object} args55 * @param {string} args.token56 * @param {object} args.data57 * @param {string} args.objectId58 * @returns {Promise}59 */60 static update({ token, data, objectId }) {61 if (!token || !data || !objectId) {62 Promise.reject('You must provide a token, data and objectId')63 }64 return ParseAPI({65 method: 'PUT',66 url: `users/${objectId}`,67 data68 })69 }70 /**71 * 72 * @param {string} token73 * @returns {Promise}74 */75 static validateSession(token) {76 return ParseAPI({77 method: 'GET',78 url: 'users/me',79 headers: {80 'X-Parse-Session-Token': token81 }82 })83 }84 /**85 * 86 * @param {string} email87 * @returns {Promise}88 */89 static resetPassword(email) {90 return ParseAPI({91 method: 'POST',92 url: 'requestPasswordReset',93 data: { email }94 })95 }96}97#ð Dare MCAdewole...
apiMasking.test.js
Source: apiMasking.test.js
1const request = require('supertest')2const app = require('..') 3const server = request(app.server)4const ParseApi = require('../api/helper/parse')5describe ('Hit Movie Detail', () => {6 let movieIdExample = 'tt0080684';7 it('GET /v1/movie/detail?movieId='+movieIdExample+' - should 200', async () => {8 server9 .get(`/v1/movie/detail?movieId=${movieIdExample}`) 10 .expect(200)11 .end((err, res) => { 12 expect(res.status).toEqual(200); 13 }) 14 })15 it('GET /v1/movie/detail - should 400 need moviewId', async () => {16 server17 .get('/v1/movie/detail')18 .expect(400)19 .end((err, res) => { 20 expect(res.status).toEqual(400); 21 }) 22 })23})24describe('Hit Search Movie', () => {25 it('GET v1/movie/search?s=Star%20Wars - should 200', async () => {26 server27 .get('/v1/movie/search?s=Star%20Wars') 28 .expect(200)29 .end((err, res) => { 30 expect(res.status).toEqual(200); 31 }) 32 })33 it('GET /v1/movie/search - should 400 need params s for search', async () => {34 server35 .get('/v1/movie/search')36 .expect(400)37 .end((err, res) => { 38 expect(res.status).toEqual(400);39 expect(res.body.errors.message).toEqual('Bad Request'); 40 })41 })42})43describe ('Test Masking API', () => {44 it('should return body search', async () => {45 let url = `http://www.omdbapi.com/?apikey=${process.env.API_KEY}&s=Star%20Wars`46 const result = await ParseApi.get(url)47 expect(result.Response).toEqual('True')48 expect(result).toHaveProperty('Search')49 })50 it('should return error 401: No API key provided', async () => {51 let url = `http://www.omdbapi.com/?s=Star%20Wars`52 const result = await ParseApi.get(url)53 expect(result.statusCode).toEqual(401)54 expect(JSON.parse(result.body)).toHaveProperty('Error')55 })...
ObjectModel.js
Source: ObjectModel.js
1/**2 * @author -> Ukwuani Barnabas3 */4import Vue from 'vue'5const ParseAPI = Vue.prototype.$parseapi6export default class ObjectModel {7 /**8 * 9 * @param {string} className10 * @param {object} data11 * @returns {Promise}12 */13 static create (className, data) { 14 return ParseAPI({15 method: 'POST',16 url: `classes/${className}`,17 data: data18 })19 }20 /**21 * 22 * @param {string} className23 * @param {string} objectId24 * @returns {Promise}25 */26 static read (className, objectId) {27 return ParseAPI({28 method: 'GET',29 url: `classes/${className}/${objectId}` 30 })31 }32 /**33 * 34 * @param {string} className35 * @returns {Promise}36 */37 static readAll (className) {38 return ParseAPI({39 method: 'GET',40 url: `classes/${className}`41 })42 }43 /**44 * 45 * @param {object} args46 * @param {string} args.className47 * @param {string} args.objectId48 * @param {object} args.data49 * @returns {Promise}50 */51 static update ({className, objectId, data}) {52 if (!className || !objectId|| !data) {53 Promise.reject('You must provide a className, objectId and data')54 }55 return ParseAPI({56 method: 'PUT',57 url: `classes/${className}/${objectId}`,58 data59 })60 } 61 62 /**63 * 64 * @param {string} className65 * @param {string} objectId66 * @returns {Promise}67 */68 static delete (className, objectId) {69 return ParseAPI({70 method: 'DELETE',71 url: `classes/${className}/${objectId}`72 })73 }74 ...
Using AI Code Generation
1const { parseApi } = require('playwright/lib/utils/parseApi');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const parsed = parseApi(page, 'Page', 'goto');8 console.log(result);9 await browser.close();10})();11{ error: null, result: undefined }
Using AI Code Generation
1const { parseApi } = require('playwright/lib/server/api');2const { parseApi } = require('playwright/lib/server/api');3const { parseApi } = require('playwright/lib/server/api');4const { parseApi } = require('playwright/lib/server/api');5const { parseApi } = require('playwright/lib/server/api');6const { parseApi } = require('playwright/lib/server/api');7const { parseApi } = require('playwright/lib/server/api');8const { parseApi } = require('playwright/lib/server/api');9const { parseApi } = require('playwright/lib/server/api');10const { parseApi } = require('playwright/lib/server/api');
Using AI Code Generation
1const { parseApi } = require('@playwright/test/lib/test');2const { test } = parseApi(require('./test.spec.js'), 'test');3const { test } = require('@playwright/test');4test('test', async ({ page }) => {5});6Error: test: Error: Test "test" has no steps. Did you forget to call a test action like "page.goto()" or "page.click()"?7const { parseApi } = require('@playwright/test/lib/test');8const { test } = parseApi(require('./test.spec.js'), 'test');9const { test } = require('@playwright/test');10test.describe('test', () => {11 test('test', async ({ page }) => {12 });13});14Error: test: Error: Test "test" has no steps. Did you forget to call a test action like "page.goto()" or "page.click()"?
Using AI Code Generation
1const { parseApi } = require('playwright/lib/utils/parseApi');2const api = parseApi(require('playwright/lib/generated/api'));3console.log(api);4const { parseApi } = require('playwright/lib/utils/parseApi');5const api = parseApi(require('playwright/lib/generated/api'));6console.log(api);7const { parseApi } = require('playwright/lib/utils/parseApi');8const api = parseApi(require('playwright/lib/generated/api'));9console.log(api);10const { parseApi } = require('playwright/lib/utils/parseApi');11const api = parseApi(require('playwright/lib/generated/api'));12console.log(api);13const { parseApi } = require('playwright/lib/utils/parseApi');14const api = parseApi(require('playwright/lib/generated/api'));15console.log(api);16const { parseApi } = require('playwright/lib/utils/parseApi');17const api = parseApi(require('playwright/lib/generated/api'));18console.log(api);19const { parseApi } = require('playwright/lib/utils/parseApi');20const api = parseApi(require('playwright/lib/generated/api'));21console.log(api);22const { parseApi } = require('playwright/lib/utils/parseApi');23const api = parseApi(require('playwright/lib/generated/api'));24console.log(api);25const { parseApi } = require('playwright/lib/utils/parseApi');26const api = parseApi(require('playwright/lib/generated/api'));27console.log(api);28const { parseApi } = require('playwright/lib/utils/parseApi');29const api = parseApi(require('playwright/lib/generated/api'));30console.log(api);31const { parseApi } = require('playwright/lib/utils/parseApi');32const api = parseApi(require('playwright/lib/generated/api'));33console.log(api);34const { parse
Using AI Code Generation
1const { parseApi } = require('playwright/lib/server/apiParser');2const api = parseApi(require('playwright/lib/server/api'));3console.log(api);4const { parseApi } = require('playwright-webkit/lib/server/apiParser');5const api = parseApi(require('playwright-webkit/lib/server/api'));6console.log(api);7const { parseApi } = require('playwright-firefox/lib/server/apiParser');8const api = parseApi(require('playwright-firefox/lib/server/api'));9console.log(api);10const { parseApi } = require('playwright-chromium/lib/server/apiParser');11const api = parseApi(require('playwright-chromium/lib/server/api'));12console.log(api);13const { parseApi } = require('playwright-android/lib/server/apiParser');14const api = parseApi(require('playwright-android/lib/server/api'));15console.log(api);16const { parseApi } = require('playwright-ios/lib/server/apiParser');17const api = parseApi(require('playwright-ios/lib/server/api'));18console.log(api);19const { parseApi } = require('playwright-electron/lib/server/apiParser');20const api = parseApi(require('playwright-electron/lib/server/api'));21console.log(api);22const { parseApi } = require('playwright/lib/server/browserApiParser');23const api = parseApi(require('playwright/lib/server/browserApi'));24console.log(api);25const { parseApi } = require('playwright-webkit/lib/server/browserApiParser');26const api = parseApi(require('playwright-webkit/lib/server/browserApi'));27console.log(api);28const { parseApi } = require('playwright-firefox/lib/server/browserApiParser');29const api = parseApi(require('playwright-firefox/lib/server/browserApi'));30console.log(api);31const { parseApi } = require('playwright-chromium/lib/server/browserApiParser');
Using AI Code Generation
1const { parseApi } = require('playwright/lib/server/supplements/recorder/recorderApp');2const { parse, parseExpression } = require('playwright/lib/server/supplements/recorder/ast');3const { createPlaywright } = require('playwright');4(async () => {5 const playwright = await createPlaywright();6 const browser = await playwright.chromium.launch();7 const page = await browser.newPage();8 const { api } = await parseApi(page, 'test.js', parse, parseExpression);9 console.log(api);10 await browser.close();11})();12const { parseApi } = require('playwright/lib/server/supplements/recorder/recorderApp');13const { parse, parseExpression } = require('playwright/lib/server/supplements/recorder/ast');14const { createPlaywright } = require('playwright');15(async () => {16 const playwright = await createPlaywright();17 const browser = await playwright.chromium.launch();18 const page = await browser.newPage();19 const { api } = await parseApi(page, 'test.js', parse, parseExpression);20 console.log(api);21 await browser.close();22})();23const { parseApi } = require('playwright/lib/server/supplements/recorder/recorderApp');24const { parse, parseExpression } = require('playwright/lib/server/supplements/recorder/ast');25const { createPlaywright } = require('playwright');26(async () => {27 const playwright = await createPlaywright();28 const browser = await playwright.chromium.launch();29 const page = await browser.newPage();30 const { api } = await parseApi(page, 'test.js', parse, parseExpression);31 console.log(api);32 await browser.close();33})();34const { parseApi } = require('playwright/lib/server/supplements/recorder/recorderApp');35const { parse, parseExpression } = require('playwright/lib/server/supplements/recorder/ast');36const { createPlaywright } = require('playwright');37(async () => {38 const playwright = await createPlaywright();39 const browser = await playwright.chromium.launch();
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!!