How to use client.getObject method in qawolf

Best JavaScript code snippet using qawolf

GoogleAnalytics.ts

Source:GoogleAnalytics.ts Github

copy

Full Screen

1import { GoogleAnalyticsJobs } from '../../src/sources/GoogleAnalyticsJobs';2import { must } from 'must';3import * as nock from 'nock';4import * as utilConfig from 'config';5import { suite, test, slow, timeout, skip } from 'mocha-typescript';6import { GoogleAnalytics } from '../../src/util/GoogleAnalytics';7const gaConfig = {8 viewId: '273696',9 client_email: 'da@genuine-esence-222222.iam.gserviceaccount.com',10 private_key: '-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQCfG5ULYFU5EfJyoUKsU/3MGj1VuBqgohUP1A4xfilMR7+hQj0A\nSQq7x2+3M/0XSG/SgB3UBW6LpwXGmirTp8uQMft+RSbOIem/Y+CZdNX2iFXFuvR1\nwZL+O5DEBoAOjxIXh6FHqGKcZmBbXlDwVGXlj5Y3g6rcf+BBY5WKJ0rqoQIDAQAB\nAoGAHzdQJK0/yzSkNq1A4YKRFsxHIFxAjSd/rl1Sc49nFto01LSkNzwdaP4WAwGm\nND04Azqzn3d5WtjoHzD8Gg6ft1kLqqixz3dbgwpd4MNxBNzWEAqSmDXoQ6xPyp1d\njXAmDSrAFytu3BBQn3CmFSzV3cB+/BAjQuQ5FRokpDKUygECQQDhM1c7VeeZAXGC\nEsv0z7zFLNO0UnDpd6Ep/xQiebGNmLqo8M7XoWO/q0Rbwh2seUVJL+9nmBWGhOsb\nQ8kYZ49RAkEAtN436iZuBHznJmUOBXbKHHTxiRGyfMBYKMtoMUWASrZhRh2UQrfB\nFue+yMoJv3oNsSQhV8a9vwWKEDf77UzyUQJBAMgZTlEyq26QkcL54K/ORfUNN67p\n8doAqfse400exF0EcBbcoW2HwZH1I/BEMwmlV6MILLjnsXitchnvySceHYECQGgk\nrD1+80pSQSayeWhcBfRswccTEZsTha+3r77vLffXHBurXHsuI1h1CD3FV+eQ9+FP\n1IMeRJOBNQYxtjXlYIECQQC8ej7LjzfHMHADVeqKIApqboW614RKzdE69Yp/Ec3W\nU/2iEKs6dFKjNAKs4xxnQbL3mwck2n7/YaXb+X6s44b/\n-----END RSA PRIVATE KEY-----\n',11};12const testObject = {13 reports: [14 {15 columnHeader: {16 dimensions: [17 'ga:transactionId',18 'ga:browser',19 'ga:deviceCategory',20 'ga:browserVersion',21 'ga:browserSize',22 'ga:adMatchedQuery',23 ],24 metricHeader: {25 metricHeaderEntries: [26 {27 name: 'ga:transactions',28 type: 'INTEGER',29 },30 ],31 },32 },33 data: {34 rows: [35 {36 dimensions: [37 'JOB3649837',38 'Chrome',39 'tablet',40 '59.0.3071.125',41 '1100x1290',42 '(not set)',43 ],44 metrics: [45 {46 values: [47 '1',48 ],49 },50 ],51 },52 {53 dimensions: [54 'JOB3664260',55 'Chrome',56 'mobile',57 '49.0.2623.91',58 '360x560',59 '(not set)',60 ],61 metrics: [62 {63 values: [64 '1',65 ],66 },67 ],68 },69 {70 dimensions: [71 'JOB3670766',72 'Chrome',73 'mobile',74 '59.0.3071.125',75 '380x560',76 'hipages',77 ],78 metrics: [79 {80 values: [81 '1',82 ],83 },84 ],85 },86 ],87 totals: [88 {89 values: [90 '3882',91 ],92 },93 ],94 rowCount: 3849,95 minimums: [96 {97 values: [98 '1',99 ],100 },101 ],102 maximums: [103 {104 values: [105 '5',106 ],107 },108 ],109 isDataGolden: true,110 },111 nextPageToken: 1000,112 },113 ],114};115const testObject1 = {116 reports: [117 {118 columnHeader: {119 dimensions: [120 'ga:transactionId',121 'ga:campaign',122 'ga:adGroup',123 'ga:source',124 'ga:medium',125 'ga:keyword',126 ],127 metricHeader: {128 metricHeaderEntries: [129 {130 name: 'ga:transactions',131 type: 'INTEGER',132 },133 ],134 },135 },136 data: {137 rows: [138 {139 dimensions: [140 'JOB3649837',141 'Campaign1',142 'adGroup1',143 'Adclick',144 'website',145 'tradie',146 ],147 metrics: [148 {149 values: [150 '1',151 ],152 },153 ],154 },155 {156 dimensions: [157 'JOB3664260',158 'Campaign1',159 'adGroup1',160 'Adclick',161 'website',162 'tradie',163 ],164 metrics: [165 {166 values: [167 '1',168 ],169 },170 ],171 },172 {173 dimensions: [174 'JOB3670766',175 'Campaign1',176 'adGroup1',177 'Adclick',178 'website',179 'tradie',180 ],181 metrics: [182 {183 values: [184 '1',185 ],186 },187 ],188 },189 ],190 totals: [191 {192 values: [193 '3882',194 ],195 },196 ],197 rowCount: 3849,198 minimums: [199 {200 values: [201 '1',202 ],203 },204 ],205 maximums: [206 {207 values: [208 '5',209 ],210 },211 ],212 isDataGolden: true,213 },214 nextPageToken: 1000,215 },216 ],217};218const testObject2 = {219 reports: [220 {221 columnHeader: {222 dimensions: [223 'ga:transactionId',224 'ga:dimension15',225 ],226 metricHeader: {227 metricHeaderEntries: [228 {229 name: 'ga:transactions',230 type: 'INTEGER',231 },232 ],233 },234 },235 data: {236 rows: [237 {238 dimensions: [239 'JOB3649837',240 'cjkanva39814639251fnkdscwwikr1nkdc23ufn',241 ],242 metrics: [243 {244 values: [245 '1',246 ],247 },248 ],249 },250 {251 dimensions: [252 'JOB3664260',253 'Ch131jfajc1yur2y12qjccmnasc',254 ],255 metrics: [256 {257 values: [258 '1',259 ],260 },261 ],262 },263 ],264 totals: [265 {266 values: [267 '3882',268 ],269 },270 ],271 rowCount: 3849,272 minimums: [273 {274 values: [275 '1',276 ],277 },278 ],279 maximums: [280 {281 values: [282 '5',283 ],284 },285 ],286 isDataGolden: true,287 },288 nextPageToken: 1000,289 },290 ],291};292const dataMix = [293 {294 transactionId: 'JOB3649837',295 browser: 'Chrome',296 deviceCategory: 'tablet',297 browserVersion: '59.0.3071.125',298 browserSize: '1100x1290',299 adMatchedQuery: '(not set)',300 },301 {302 transactionId: 'JOB3664260',303 browser: 'Chrome',304 deviceCategory: 'mobile',305 browserVersion: '49.0.2623.91',306 browserSize: '360x560',307 adMatchedQuery: '(not set)',308 },309 {310 transactionId: 'JOB3670766',311 browser: 'Chrome',312 deviceCategory: 'mobile',313 browserVersion: '59.0.3071.125',314 browserSize: '380x560',315 adMatchedQuery: 'hipages',316 },317 ];318const metricHeaderEntries = {319 transactions: '1',320};321const injectedFields = [ {firstValue: 'value'}, {secondValue: 'second'} ];322suite('GoogleAnalytics', () => {323 suite('GoogleAnalytics API methods', () => {324 const googleAuth = nock('https://accounts.google.com')325 .post('/o/oauth2/token')326 .times(2)327 .reply(200, { access_token: 'ya29.ElmqBEzhpPi4uG9J89plhw7jw1eoqmqPRkCqgOuxjLcBKGKkWIHNxXAsjvqfNCg2HleabPXSbk5NSsaMB6zS2PkTYoGxJ4J6adc74Mhcln8w3axMOCZVvQwlSg',328 token_type: 'Bearer',329 expiry_date: 1503015873000,330 refresh_token: 'jwt-placeholder',331 });332 const GoogleAnalyticsBatchGet = nock('https://analyticsreporting.googleapis.com')333 .post('/v4/reports:batchGet')334 .socketDelay(2000)335 .reply(200, testObject);336 const gaClient = new GoogleAnalytics(gaConfig, 1000);337 test('Test request jwt token', async () => {338 const analytics = await gaClient.testAuth();339 analytics.must.have.property('reports');340 });341 test('Test request error when generating jwt token using wrong key', async () => {342 const wrongConfig = gaConfig;343 wrongConfig.client_email = 'da@test.gserviceaccount.com';344 wrongConfig.private_key = '--VATE KEY-----MIICXQIBAAKBgQCfG5ULYFU5EfJyoUKsU/3MGj1VuBqgohUP1A4xb/\n-----END RSA PRIVATE KEY-----\n';345 const wrongGaClient = new GoogleAnalytics(wrongConfig, 1000);346 try {347 await wrongGaClient.testAuth();348 } catch (e) {349 e.must.throw();350 }351 });352 });353 suite('GoogleAnalytics test public methods', () => {354 const googleAuth = nock('https://accounts.google.com')355 .post('/o/oauth2/token')356 .times(2)357 .reply(200, { access_token: 'ya29.ElmqBEzhpPi4uG9J89plhw7jw1eoqmqPRkCqgOuxjLcBKGKkWIHNxXAsjvqfNCg2HleabPXSbk5NSsaMB6zS2PkTYoGxJ4J6adc74Mhcln8w3axMOCZVvQwlSg',358 token_type: 'Bearer',359 expiry_date: 1503015873000,360 refresh_token: 'jwt-placeholder',361 });362 const GoogleAnalyticsBatchGet = nock('https://analyticsreporting.googleapis.com')363 .post('/v4/reports:batchGet')364 .socketDelay(2000)365 .reply(200, testObject);366 const gaClient = new GoogleAnalytics(gaConfig, 1000);367 test('Test request analytic data', async () => {368 const analyticData = await gaClient.fetch({369 dimensions: 'ga:transactionId,ga:campaign,ga:adGroup,ga:source,ga:medium,ga:keyword,ga:landingPagePath,ga:adMatchedQuery,ga:deviceCategory',370 metrics: 'ga:transactions',371 dateRanges: {372 startDate: '2017-08-12',373 endDate: '2017-08-11',374 },375 filters: 'ga:transactionId=~^JOB*',376 maxResults: 10,377 nextPageToken: 1,378 });379 analyticData.must.have.property('reports');380 });381 test('Test create params', async () => {382 gaClient.viewId.must.be.equal('273696');383 gaClient.getNextPageToken().must.be.equal(1000);384 });385 test('Test create params', async () => {386 gaClient.viewId.must.be.equal('273696');387 gaClient.getNextPageToken().must.be.equal(1000);388 });389 test('Test getObject: key does not exist', async () => {390 const found = gaClient.getObject(testObject, 'no_exist_key');391 found.must.be.false();392 });393 test('Test getObject: key exist', async () => {394 const found = gaClient.getObject(testObject, 'columnHeader');395 found.must.be.eql(testObject.reports[0].columnHeader);396 });397 test('Test getObject: nextPageToken', async () => {398 const found = gaClient.getObject(testObject, 'nextPageToken');399 found.must.be.equal(1000);400 });401 test('Test getObject: rows', async () => {402 const found = gaClient.getObject(testObject, 'rows');403 found.must.be.eql(testObject.reports[0].data.rows);404 });405 test('Test mergeHeadersRows', async () => {406 const data = gaClient.mergeHeadersRows(gaClient.getObject(testObject, 'columnHeader')['dimensions'], gaClient.getObject(testObject, 'rows'), false, 'dimensions');407 data.must.be.eql(dataMix);408 });409 test('Test mergeHeadersRows and injectedFields', async () => {410 const data = gaClient.mergeHeadersRows(gaClient.getObject(testObject, 'columnHeader')['dimensions'], gaClient.getObject(testObject, 'rows'), injectedFields, 'dimensions');411 const [a, b, c] = dataMix;412 const [x, y] = injectedFields;413 data.must.be.eql([{...x, ...y, ...a}, {...x, ...y, ...b}, {...x, ...y, ...c}]);414 });415 test('Test mergeHeadersRows and injectedFields with object as value', async () => {416 const t = {417 reports: [418 {419 columnHeader: {420 dimensions: [421 'ga:transactionId',422 'ga:browser',423 'ga:deviceCategory',424 'ga:browserVersion',425 'ga:browserSize',426 'ga:adMatchedQuery',427 ],428 metricHeader: {429 metricHeaderEntries: [430 {431 name: 'ga:transactions',432 type: 'INTEGER',433 },434 ],435 },436 },437 data: {438 rows: [439 {440 dimensions: [{441 dimensions: [442 'JOB3649837',443 'Chrome',444 'tablet',445 '59.0.3071.125',446 '1100x1290',447 '(not set)',448 ],449 }],450 metrics: [451 {452 values: [453 '1',454 ],455 },456 ],457 },458 ],459 totals: [460 {461 values: [462 '3882',463 ],464 },465 ],466 rowCount: 3849,467 minimums: [468 {469 values: [470 '1',471 ],472 },473 ],474 maximums: [475 {476 values: [477 '5',478 ],479 },480 ],481 isDataGolden: true,482 },483 nextPageToken: 1000,484 },485 ],486 };487 const data = gaClient.mergeHeadersRows(gaClient.getObject(t, 'columnHeader')['dimensions'], gaClient.getObject(t, 'rows'), injectedFields, 'dimensions');488 const [a, b, c] = dataMix;489 const [x, y] = injectedFields;490 data.must.be.eql([{...x, ...y, ...a}]);491 });492 test('Test mergeDimensionsRows', async () => {493 const results = [testObject, testObject1, testObject2];494 const data = gaClient.mergeDimensionsRows(results, injectedFields);495 data.must.be.an.array();496 data.must.have.length(3);497 });498 test('Test mergeHeadersDimensions', async () => {499 const data = gaClient.mergeHeadersDimensions(testObject);500 const [a, b, c] = dataMix;501 data.must.be.eql(dataMix);502 });503 test('Test getFindDimensionKey', async () => {504 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3649837', 3).must.be.equal(1);505 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3664260', 3).must.be.equal(2);506 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3670766', 3).must.be.equal(3);507 });508 test('Test getFindDimensionKey not existing transaction', async () => {509 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB700000', 3).must.be.equal(0);510 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3649836', 3).must.be.equal(0);511 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3649838', 3).must.be.equal(1);512 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3664261', 3).must.be.equal(2);513 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3665000', 3).must.be.equal(2);514 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB3670767', 3).must.be.equal(-1);515 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB4000000', 3).must.be.equal(-1);516 gaClient.findDimensionKeyRowIndex(testObject, 'ga:transactionId', 'JOB20000000', 3).must.be.equal(-1);517 });518 });...

Full Screen

Full Screen

index.spec.js

Source:index.spec.js Github

copy

Full Screen

1import S3 from './index.js'2const DEFAULT_OPTIONS = {3 accessKeyId: 2,4 secretAccessKey: 3,5 bucket: 'ok'6}7describe('Stores:S3', () => {8 const model = []9 model.name = 'project'10 beforeEach(() => {11 jest.resetAllMocks()12 S3.AWS.S3 = jest.fn()13 })14 it('initializes', () => {15 const subject = new S3()16 expect(subject.extension).toEqual('.json')17 })18 describe('buildConfiguration', () => {19 it('requires accessKeyId', () => {20 const subject = new S3()21 expect(() => subject._buildConfiguration(model, 1)).toThrow(new Error('`S3.accessKeyId` is required'))22 })23 it('requires secretAccessKey', () => {24 const subject = new S3({25 accessKeyId: 126 })27 expect(() => subject._buildConfiguration(model, 1)).toThrow(new Error('`S3.secretAccessKey` is required'))28 })29 it('requires bucket', () => {30 const subject = new S3({31 accessKeyId: 1,32 secretAccessKey: 133 })34 expect(() => subject._buildConfiguration(model, 1)).toThrow(new Error('`S3.bucket` is required'))35 })36 it('builds correct configuration', () => {37 const options = {38 endpoint: 1,39 accessKeyId: 2,40 secretAccessKey: 3,41 bucket: 'ok',42 apiVersion: 4,43 maxRetries: 5,44 key: 'projects.json'45 }46 const subject = new S3(options)47 expect(subject._buildConfiguration(model, 1).options).toEqual(options)48 })49 })50 describe('query', () => {51 it('returns data', async () => {52 const subject = new S3(DEFAULT_OPTIONS)53 const client = subject._buildConfiguration(model).client54 const projects = [{ id: 1 }]55 client.getObject = jest.fn((data, done) => {56 done(undefined, JSON.stringify({ projects }))57 })58 const response = await subject.query(model)59 expect(response).toEqual(projects)60 expect(client.getObject).toHaveBeenCalledWith({61 Bucket: subject.options.bucket,62 Key: 'projects.json'63 }, expect.anything())64 })65 it('returns error', () => {66 const subject = new S3(DEFAULT_OPTIONS)67 const client = subject._buildConfiguration(model).client68 const error = 'Something went wrong'69 client.getObject = jest.fn((data, done) => {70 done(error)71 })72 return subject.query(model, 1).catch((err) => {73 expect(err).toEqual(error)74 })75 })76 })77 describe('find', () => {78 it('returns data', async () => {79 const subject = new S3(DEFAULT_OPTIONS)80 const client = subject._buildConfiguration(model).client81 const project = { id: 1 }82 client.getObject = jest.fn((data, done) => {83 done(undefined, JSON.stringify({ project }))84 })85 const response = await subject.find(model, 1)86 expect(response).toEqual(project)87 expect(client.getObject).toHaveBeenCalledWith({88 Bucket: subject.options.bucket,89 Key: 'projects.json'90 }, expect.anything())91 })92 it('returns error', () => {93 const subject = new S3(DEFAULT_OPTIONS)94 const client = subject._buildConfiguration(model).client95 const error = 'Something went wrong'96 client.getObject = jest.fn((data, done) => {97 done(error)98 })99 return subject.find(model, 1).catch((err) => {100 expect(err).toEqual(error)101 })102 })103 })104 describe('save', () => {105 it('writes data', async () => {106 const subject = new S3(DEFAULT_OPTIONS)107 const client = subject._buildConfiguration(model).client108 const project = { name: 'Name', toJSON () { return { name: this.name } } }109 client.putObject = jest.fn((data, done) => {110 done(undefined, JSON.stringify({ project }))111 })112 const response = await subject.save(model, project)113 expect(response).toEqual(project.toJSON())114 expect(client.putObject).toHaveBeenCalledWith({115 Body: JSON.stringify(project.toJSON()),116 Bucket: subject.options.bucket,117 Key: 'projects.json'118 }, expect.anything())119 })120 it('returns error', () => {121 const subject = new S3(DEFAULT_OPTIONS)122 const client = subject._buildConfiguration(model).client123 const project = { name: 'Name', toJSON () { return { name: this.name } } }124 const error = 'Something went wrong'125 client.putObject = jest.fn((data, done) => {126 done(error)127 })128 return subject.save(model, project).catch((err) => {129 expect(err).toEqual(error)130 })131 })132 })133 describe('destroy', () => {134 it('writes data', async () => {135 const subject = new S3(DEFAULT_OPTIONS)136 const client = subject._buildConfiguration(model).client137 const id = 7777138 client.deleteObject = jest.fn((data, done) => done())139 await subject.destroy(model, id)140 expect(client.deleteObject).toHaveBeenCalledWith({141 Bucket: subject.options.bucket,142 Key: 'projects.json'143 }, expect.anything())144 })145 it('returns error', () => {146 const subject = new S3(DEFAULT_OPTIONS)147 const client = subject._buildConfiguration(model).client148 const error = 'Something went wrong'149 client.deleteObject = jest.fn((data, done) => {150 done(error)151 })152 return subject.destroy(model, 1).catch((err) => {153 expect(err).toEqual(error)154 })155 })156 })157 it('reset', async () => {158 const subject = new S3(DEFAULT_OPTIONS)159 console.warn = jest.fn()160 await subject.reset()161 expect(console.warn).toBeCalledWith('S3 `reset` not implemented.')162 })163 describe('formats data', () => {164 let subject165 beforeEach(() => {166 subject = new S3(DEFAULT_OPTIONS)167 })168 it('query', () => {169 const response = [1]170 expect(subject.formatData('query', model, { projects: response })).toEqual(response)171 expect(subject.formatData('query', model, { data: response })).toEqual(response)172 expect(subject.formatData('query', model, response)).toEqual(response)173 })174 it('find', () => {175 const response = { id: 1 }176 expect(subject.formatData('find', model, { project: response })).toEqual(response)177 expect(subject.formatData('find', model, { data: response })).toEqual(response)178 expect(subject.formatData('find', model, response)).toEqual(response)179 })180 it('save', () => {181 const response = { id: 1 }182 expect(subject.formatData('save', model, { project: response })).toEqual(response)183 expect(subject.formatData('save', model, { data: response })).toEqual(response)184 expect(subject.formatData('save', model, response)).toEqual(response)185 })186 })...

Full Screen

Full Screen

root.js

Source:root.js Github

copy

Full Screen

1remoteStorage.defineModule('public', function(client) {2 function getPublicItems()3 {4 return client.getObject("publishedItems");5 }67 return {8 exports: {9 getPublicItems: getPublicItems,10 getObject: client.getObject11 }12 }13});1415remoteStorage.defineModule('root', function(myPrivateBaseClient, myPublicBaseClient) {16 function setOnChange(cb)17 {18 myPrivateBaseClient.on('change', function(e)19 {20 console.log(e); cb(e);21 });22 myPublicBaseClient.on('change', function(e)23 {24 console.log(e); cb(e);25 });26 }2728 function addToPublicItems(path)29 {30 var data = myPublicBaseClient.getObject("publishedItems");31 if(path[0] == "/")32 path = path.substr(1);3334 if(data)35 {36 if(data.indexOf(path) == -1)37 {38 data.unshift(path);39 }40 }41 else42 {43 data = [];44 data.push(path);45 }46 myPublicBaseClient.storeObject('array', "publishedItems", data);47 }4849 function removeFromPublicItems(path)50 {51 var data = myPublicBaseClient.getObject("publishedItems");52 if(path[0] == "/")53 path = path.substr(1);54 if(data)55 {56 if(data.indexOf(path) != -1)57 {58 data.pop(path);59 }60 }61 else62 {63 data = [];64 }65 myPublicBaseClient.storeObject('array', "publishedItems", data);66 }6768 function publishObject(path)69 {70 if(pathIsPublic(path))71 return 'Object has already been made public';7273 var data = myPrivateBaseClient.getObject(path);74 var publicPath = "/public" + path;75 addToPublicItems(publicPath);76 myPrivateBaseClient.remove(path);77 myPrivateBaseClient.storeObject(data['@type'], publicPath, data);7879 return "Object " + path + " has been published to " + publicPath;80 }8182 function archiveObject(path)83 {84 if(!pathIsPublic(path))85 return 'Object has already been made private';8687 var data = myPrivateBaseClient.getObject(path);88 var privatePath = path.substring(7, path.length);89 removeFromPublicItems(path);90 myPrivateBaseClient.remove(path);91 myPrivateBaseClient.storeObject(data['@type'], privatePath, data);9293 return "Object " + path + " has been archived to " + privatePath;94 }9596 function pathIsPublic(path)97 {98 if(path.substring(0, 8) == "/public/")99 return true;100 return false;101 }102103 function getClient(path)104 {105 if(!pathIsPublic(path))106 return myPrivateBaseClient;107 return myPublicBaseClient;108 }109110 function getObject(path, cb, contex)111 {112 var client = getClient(path);113 return client.getObject(path, cb, contex);114 }115116 function setObject(type, path, obj)117 {118 var client = getClient(path);119 client.storeObject(type, path, obj);120 }121122 function removeObject(path)123 {124 var client = getClient(path);125 client.remove(path);126 }127 ...

Full Screen

Full Screen

remotestorage.js

Source:remotestorage.js Github

copy

Full Screen

...84})85module.exports.fetchProfiles = fetchProfiles86function fetchProfiles (host) {87 console.log('fetching profiles for', host)88 return rs.client.getObject(`hosts/${host}`)89 .then(hostData => {90 if (hostData) {91 return Promise.all(92 hostData.profiles.map(prf => rs.client.getObject(`profiles/${prf}`))93 )94 }95 return []96 })97 .then(profiles => profiles.filter(prf => prf))98}99module.exports.saveProfile = saveProfile100function saveProfile (host, profile) {101 let profileName = `${profile.domain}/${profile.login}`102 return Promise.all([103 rs.client.getObject(`hosts/${host}`)104 .then((hostData = {profiles: []}) => {105 var found = false106 hostData.profiles.forEach(prf => {107 if (prf === profileName) {108 found = true109 }110 })111 if (!found) {112 hostData.profiles.unshift(profileName)113 return rs.client.storeObject('host', `hosts/${host}`, hostData)114 }115 })116 .then(() => console.log('updated host', host)),117 rs.client.storeObject('profile', `profiles/${profileName}`, profile)118 .then(() => console.log('updated profile', profile))119 ])120}121module.exports.deleteProfile = deleteProfile122function deleteProfile (host, profileName) {123 rs.client.getObject(`hosts/${host}`)124 .then((hostData = {profiles: []}) => {125 var idx126 for (let i = 0; i < hostData.profiles.length; i++) {127 if (hostData.profiles[i] === profileName) {128 idx = i129 break130 }131 }132 if (idx !== undefined) {133 hostData.profiles.splice(idx, 1)134 return rs.client.storeObject('host', `hosts/${host}`, hostData)135 }136 })137 .then(() =>...

Full Screen

Full Screen

test-controller.js

Source:test-controller.js Github

copy

Full Screen

1/**2 Licensed to the Apache Software Foundation (ASF) under one3 or more contributor license agreements. See the NOTICE file4 distributed with this work for additional information5 regarding copyright ownership. The ASF licenses this file6 to you under the Apache License, Version 2.0 (the7 "License"); you may not use this file except in compliance8 with the License. You may obtain a copy of the License at9 http://www.apache.org/licenses/LICENSE-2.010 Unless required by applicable law or agreed to in writing,11 software distributed under the License is distributed on an12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13 KIND, either express or implied. See the License for the14 specific language governing permissions and limitations15 under the License.16 */17 'use strict'18 19AppServices.Controllers.controller('TestCtrl', ['ug', '$scope', '$rootScope', '$routeParams', '$location', function (ug, $scope, $rootScope, $routeParams, $location) {20 21 $scope.login = function() {22 $rootScope.currentPath = '/login';23 var username = $scope.login_username;24 var password = $scope.login_password;25 alert(username);26/*27 ug.client().orgLogin(username, password, function (err, data, user, organizations, applications) {28 if (err){29 //let the user know the login was not valid30 $scope.loginMessage = "Error: the username / password combination was not valid";31 if(!$scope.$$phase) {32 $scope.$apply();33 }34 } else {35 $rootScope.$broadcast('loginSuccesful', user, organizations, applications);36 }37 });38 */39 }40 $rootScope.$on('userNotAuthenticated', function(event) {41 $location.path('/login');42 if(!$rootScope.$$phase) {43 $rootScope.$apply();44 }45 });46 $scope.$on('loginSuccesful', function(event, user, organizations, applications) {47 //update org and app dropdowns48 $rootScope.userEmail = user.get('email');49 $rootScope.organizations = ug.client().getObject('organizations');50 $rootScope.applications = ug.client().getObject('applications');51 $rootScope.currentOrg = ug.client().get('orgName');52 $rootScope.currentApp = ug.client().get('appName');53 //if on login page, send to org overview page. if on a different page, let them stay there54 if ($rootScope.currentPath === '/login' || $rootScope.currentPath === '/login/loading') {55 $location.path('/org-overview');56 } else {57 $location.path($rootScope.currentPath);58 }59 if(!$scope.$$phase) {60 $scope.$apply();61 }62 });63 $scope.$on('reauthSuccesful', function(event) {64 $rootScope.organizations = ug.client().getObject('organizations');65 $rootScope.applications = ug.client().getObject('applications');66 $rootScope.currentOrg = ug.client().get('orgName');67 $rootScope.currentApp = ug.client().get('appName');68 //if on login page, send to org overview page. if on a different page, let them stay there69 if ($rootScope.currentPath === '/login') {70 $location.path('/org-overview');71 } else {72 $location.path($rootScope.currentPath);73 }74 if(!$scope.$$phase) {75 $scope.$apply();76 }77 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { client } = require("qawolf");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 await client.getObject(page, "input[name='name']");8 await client.getObject(page, "input[name='email']");9 await client.getObject(page, "input[name='password']");10 await client.getObject(page, "input[name='confirmPassword']");11 await client.getObject(page, "button[type='submit']");12 await browser.close();13})();14const { client } = require("qawolf");15const { chromium } = require("playwright");16(async () => {17 const browser = await chromium.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 await client.getObject(page, "input[name='name']");21 await client.getObject(page, "input[name='email']");22 await client.getObject(page, "input[name='password']");23 await client.getObject(page, "input[name='confirmPassword']");24 await client.getObject(page, "button[type='submit']");25 await browser.close();26})();27const { client } = require("qawolf");28const { chromium } = require("playwright");29(async () => {30 const browser = await chromium.launch();31 const context = await browser.newContext();32 const page = await context.newPage();33 await client.getObject(page, "input[name='name']");34 await client.getObject(page, "input[name='email']");35 await client.getObject(page, "input[name='password']");36 await client.getObject(page, "input[name='confirmPassword']");37 await client.getObject(page, "button[type='submit']");38 await browser.close();39})();40const { client } = require("qawolf");41const { chromium } = require("playwright");42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();46 await client.getObject(page, "input[name='name']");47 await client.getObject(page, "input[name='email']");48 await client.getObject(page, "input[name='password']");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { client } = require('qawolf');2(async () => {3 const browser = await client.launch();4 const page = await client.newPage(browser);5 await client.type(page, 'input[name="q"]', 'qawolf');6 await client.click(page, 'input[name="btnK"]');7 await client.waitForSelector(page, '#result-stats');8 await client.close(browser);9})();10const { client } = require('qawolf');11(async () => {12 const browser = await client.launch();13 const page = await client.newPage(browser);14 await client.type(page, 'input[name="q"]', 'qawolf');15 await client.click(page, 'input[name="btnK"]');16 await client.waitForSelector(page, '#result-stats');17 await client.close(browser);18})();19const { client } = require('qawolf');20(async () => {21 const browser = await client.launch();22 const page = await client.newPage(browser);23 await client.type(page, 'input[name="q"]', 'qawolf');24 await client.click(page, 'input[name="btnK"]');25 await client.waitForSelector(page, '#result-stats');26 await client.close(browser);27})();28const { client } = require('qawolf');29(async () => {30 const browser = await client.launch();31 const page = await client.newPage(browser);32 await client.type(page, 'input[name="q"]', 'qawolf');33 await client.click(page, 'input[name="btnK"]');34 await client.waitForSelector(page, '#result-stats');35 await client.close(browser);36})();37const { client } = require('qawolf');38(async () => {39 const browser = await client.launch();40 const page = await client.newPage(browser);41 await client.type(page, 'input[name="q"]', 'qawolf');42 await client.click(page, '

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Client } = require('qawolf');2const { test } = require('qawolf');3const { launch } = require('qawolf');4let browser;5let page;6beforeAll(async () => {7 browser = await launch();8});9afterAll(() => browser.close());10test('test', async () => {11 page = await browser.newPage();12 await page.click('input[name="q"]');13 await page.type('input[name="q"]', 'qawolf');14 await page.keyboard.press('Enter');15 await page.waitForSelector('div.g:nth-child(2) > div:nth-child(1) > a:nth-child(1) > h3:nth-child(1)');16 await page.click('div.g:nth-child(2) > div:nth-child(1) > a:nth-child(1) > h3:nth-child(1)');17 await page.waitForSelector('.hero-title');18 const heroTitle = await page.$('.hero-title');19 const heroTitleText = await page.evaluate(heroTitle => heroTitle.innerText, heroTitle);20 expect(heroTitleText).toBe('JavaScript browser automation');21});22const { test, expect } = require('qawolf');23test('test', async () => {24 await page.click('#btn');25 const input = await page.$('#input');26 const inputValue = await page.evaluate(input => input.value, input);27 expect(inputValue).toBe('clicked');28});29Error: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined30Error: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined31const { test, expect } = require('qawolf');32test('test', async () => {33 await page.click('#btn');34 const input = await page.$('#input');35 const inputValue = await page.evaluate(input => input.value, input);36 expect(input

Full Screen

Using AI Code Generation

copy

Full Screen

1const { client } = require('qawolf');2const { chromium } = require('playwright');3const assert = require('assert');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.click('input[name="q"]');9 await page.fill('input[name="q"]', 'qawolf');10 await page.press('input[name="q"]', 'Enter');11 await page.waitForSelector('text="qawolf"');12 await page.click('text="qawolf"');13 await page.waitForSelector('text="QA Wolf"');14 await page.click('text="QA Wolf"');15 await page.waitForSelector('text="Create end-to-end tests for your web app in minutes"');16 const element = await client.getObject(page, 'text="Create end-to-end tests for your web app in minutes"');17 const textContent = await element.textContent();18 assert.equal(textContent, 'Create end-to-end tests for your web app in minutes');19 await browser.close();20})();21const { client } = require('qawolf');22const { chromium } = require('playwright');23const assert = require('assert');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 await page.click('input[name="q"]');29 await page.fill('input[name="q"]', 'qawolf');30 await page.press('input[name="q"]', 'Enter');31 await page.waitForSelector('text="qawolf"');32 await page.click('text="qawolf"');33 await page.waitForSelector('text="QA Wolf"');34 await page.click('text="QA Wolf"');35 await page.waitForSelector('text="Create end-to-end tests for your web app in minutes"');36 const element = await client.getElement(page, 'text="Create end-to-end tests for your web app in minutes"');

Full Screen

Using AI Code Generation

copy

Full Screen

1const client = require('qawolf').create();2const { setDefaultOptions } = require('expect-puppeteer');3setDefaultOptions({ timeout: 5000 });4describe('test', () => {5 beforeAll(async () => {6 await client.startBrowser();7 });8 afterAll(async () => {9 await client.stopBrowser();10 });11 it('test', async () => {12 const page = await client.startPage();13 const element = await client.getObject('div');14 expect(element).toBeTruthy();15 await client.stopPage();16 });17});18const puppeteer = require('puppeteer');19const { setDefaultOptions } = require('expect-puppeteer');20setDefaultOptions({ timeout: 5000 });21describe('test', () => {22 let browser;23 let page;24 beforeAll(async () => {25 browser = await puppeteer.launch();26 });27 afterAll(async () => {28 await browser.close();29 });30 it('test', async () => {31 page = await browser.newPage();32 const element = await page.$('div');33 expect(element).toBeTruthy();34 });35});36const puppeteer = require('puppeteer');37const { setDefaultOptions } = require('expect-puppeteer');38setDefaultOptions({ timeout: 5000 });39describe('test', () => {40 let browser;41 let page;42 beforeAll(async () => {43 browser = await puppeteer.launch();44 });45 afterAll(async () => {46 await browser.close();47 });48 it('test', async () => {49 page = await browser.newPage();50 const element = await page.$('div');51 expect(element).toBeTruthy();52 });53});54const puppeteer = require('puppeteer');55const { setDefaultOptions } = require('expect-puppeteer');56setDefaultOptions({ timeout: 5000 });57describe('test', () => {58 let browser;59 let page;60 beforeAll(async () => {61 browser = await puppeteer.launch();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful