How to use resFixture method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

s3o-middleware.test.js

Source:s3o-middleware.test.js Github

copy

Full Screen

1/**2 * Basic spec for s3o-middleware3 *4 */5const { cookies } = require('@financial-times/s3o-middleware-utils');6const chai = require('chai');7const sinon = require('sinon');8const sinonChai = require('sinon-chai');9const proxyquire = require('proxyquire');10chai.should();11chai.use(sinonChai);12describe('s3o-middleware', () => {13 let sandbox;14 let pollerStub;15 let authenticateTokenStub;16 let validatorStub;17 let nextStub;18 let reqFixture;19 let resFixture;20 let s3o;21 const runs = [22 {23 version: 'v3',24 options: {25 requestHeader: {},26 redirectLocation: 'https://s3o.ft.com/v2/authenticate?post=true&host=localhost&redirect=https%3A%2F%2Flocalhost%2F',27 redirectLocationWithPort: 'https://s3o.ft.com/v2/authenticate?post=true&host=localhost&redirect=https%3A%2F%2Flocalhost%3A1234%2F'28 }29 },30 {31 version: 'v4',32 options: {33 requestHeader: {34 'x-s3o-version': 'v4',35 'x-s3o-systemcode': 'system-code'36 },37 redirectLocation: 'https://s3ov4.in.ft.com/v2/authenticate?post=true&host=localhost&redirect=https%3A%2F%2Flocalhost%2F&systemcode=system-code',38 redirectLocationWithPort: 'https://s3ov4.in.ft.com/v2/authenticate?post=true&host=localhost&redirect=https%3A%2F%2Flocalhost%3A1234%2F&systemcode=system-code'39 }40 }41 ];42 beforeEach(() => {43 sandbox = sinon.createSandbox();44 pollerStub = sandbox.stub();45 pollerStub.returns(Promise.resolve())46 authenticateTokenStub = sandbox.stub();47 validatorStub = sandbox.stub();48 nextStub = sandbox.stub();49 nextStub.returns('next returned');50 // Reset overridden fixtures51 reqFixture = {52 cookies: {53 [cookies.USERNAME]: 'test',54 [cookies.TOKEN]: 'test-test-123',55 },56 get: sandbox.stub().withArgs('host').returns('localhost'),57 hostname: 'localhost',58 headers: {59 'transfer-encoding': 'utf8'60 }61 };62 resFixture = {63 clearCookie: sandbox.spy(),64 status: sandbox.spy(),65 send: sandbox.spy(),66 header: sandbox.spy(),67 locals: {},68 app: {69 get: () => 9999,70 },71 cookie: sandbox.spy(),72 redirect: sandbox.stub(),73 };74 s3o = proxyquire('../../', {75 '@financial-times/s3o-middleware-utils': {76 publickey: {77 poller: () => pollerStub,78 },79 authenticate: (publicKeyGetter) => {80 publicKeyGetter.should.equal(pollerStub);81 return {82 authenticateToken: authenticateTokenStub,83 validate: validatorStub,84 }85 }86 },87 });88 });89 afterEach(() => {90 sandbox.restore();91 });92 it('exposes validate', () => {93 s3o.validate.should.equal(validatorStub);94 });95 it('exposes a ready function which returns true when the poller resolves', () => {96 pollerStub.withArgs({ promise: true }).returns(Promise.resolve());97 return s3o.ready98 .then((result) => {99 return result.should.equal(true);100 })101 .catch(error => {102 throw error;103 })104 });105 runs.forEach((run) => {106 describe('normal authentication', () => {107 describe('when user POSTs a username', () => {108 it('redirects if user authenticates', () => {109 authenticateTokenStub.returns(true);110 reqFixture.method = 'POST';111 reqFixture.query = {112 username: 'test',113 };114 reqFixture.body = {115 token: 'abc123',116 };117 reqFixture.protocol = 'http';118 reqFixture.hostname = 'localhost';119 reqFixture.originalUrl = '/';120 s3o(reqFixture, resFixture, nextStub);121 authenticateTokenStub.withArgs('test', 'localhost', 'abc123').should.have.been.calledOnce;122 resFixture.header.withArgs('Cache-Control', 'private, no-cache, no-store, must-revalidate')123 .should.have.been.calledOnce;124 resFixture.header.withArgs('Pragma', 'no-cache').should.have.been.calledOnce;125 resFixture.header.withArgs('Expires', 0).should.have.been.calledOnce;126 resFixture.redirect.withArgs('/').should.have.been.calledOnce;127 });128 it('responds with error message if authentication fails', () => {129 authenticateTokenStub.returns(false);130 s3o(reqFixture, resFixture, nextStub);131 authenticateTokenStub.withArgs('test', 'localhost', 'test-test-123').should.have.been.calledOnce;132 resFixture.send133 .withArgs('<h1>Authentication error.</h1><p>For access, please log in with your FT account</p>')134 .should.have.been.calledOnce;135 });136 });137 describe('when user has cookies', () => {138 it('calls next() after authenticating cookies', () => {139 reqFixture.method = 'GET';140 authenticateTokenStub.returns(true);141 s3o(reqFixture, resFixture, nextStub);142 authenticateTokenStub.withArgs('test', 'localhost', 'test-test-123').should.have.been.calledOnce;143 nextStub.should.have.been.calledOnce;144 });145 it('responds with error message if authentication fails', () => {146 reqFixture.method = 'GET';147 authenticateTokenStub.returns(false);148 s3o(reqFixture, resFixture, nextStub);149 authenticateTokenStub.withArgs('test', 'localhost', 'test-test-123').should.have.been.calledOnce;150 nextStub.should.not.have.been.called;151 resFixture.send.withArgs('<h1>Authentication error.</h1><p>For access, please log in with your FT account</p>')152 .should.have.been.calledOnce;153 });154 });155 describe('when user is unauthenticated', () => {156 beforeEach(() => {157 delete reqFixture.cookies;158 delete reqFixture.query;159 delete reqFixture.method;160 });161 it('redirects to s3o login URL', () => {162 reqFixture.headers.host = 'localhost';163 reqFixture.headers = Object.assign(reqFixture.headers, run.options.requestHeader);164 reqFixture.protocol = 'https';165 reqFixture.hostname = 'localhost';166 reqFixture.originalUrl = '/';167 resFixture.redirect.returns('redirect returned');168 const result = s3o(reqFixture, resFixture, nextStub);169 resFixture.header.withArgs('Cache-Control', 'private, no-cache, no-store, must-revalidate')170 .should.have.been.calledOnce;171 resFixture.header.withArgs('Pragma', 'no-cache').should.have.been.calledOnce;172 resFixture.header.withArgs('Expires', 0).should.have.been.calledOnce;173 resFixture.redirect.withArgs(run.options.redirectLocation)174 .should.have.been.calledOnce;175 result.should.equal('redirect returned');176 });177 describe('when the request URL has a port', () => {178 it('includes the port in the s3o redirect', () => {179 reqFixture.headers.host = 'localhost';180 reqFixture.headers = Object.assign(reqFixture.headers, run.options.requestHeader);181 reqFixture.protocol = 'https';182 reqFixture.hostname = 'localhost';183 reqFixture.originalUrl = '/';184 reqFixture.get.withArgs('host').returns('localhost:1234');185 resFixture.redirect.returns('redirect returned');186 const result = s3o(reqFixture, resFixture, nextStub);187 resFixture.header.withArgs('Cache-Control', 'private, no-cache, no-store, must-revalidate')188 .should.have.been.calledOnce;189 resFixture.header.withArgs('Pragma', 'no-cache').should.have.been.calledOnce;190 resFixture.header.withArgs('Expires', 0).should.have.been.calledOnce;191 resFixture.redirect.withArgs(run.options.redirectLocationWithPort)192 .should.have.been.calledOnce;193 result.should.equal('redirect returned');194 });195 });196 describe('when the request URL has a proxy port', () => {197 it('includes the port in the s3o redirect', () => {198 reqFixture.headers.host = 'localhost';199 reqFixture.headers = Object.assign(reqFixture.headers, run.options.requestHeader);200 reqFixture.protocol = 'https';201 reqFixture.hostname = 'localhost';202 reqFixture.originalUrl = '/';203 reqFixture.headers['x-forwarded-port'] = '1234';204 resFixture.redirect.returns('redirect returned');205 const result = s3o(reqFixture, resFixture, nextStub);206 resFixture.header.withArgs('Cache-Control', 'private, no-cache, no-store, must-revalidate')207 .should.have.been.calledOnce;208 resFixture.header.withArgs('Pragma', 'no-cache').should.have.been.calledOnce;209 resFixture.header.withArgs('Expires', 0).should.have.been.calledOnce;210 resFixture.redirect.withArgs(run.options.redirectLocationWithPort)211 .should.have.been.calledOnce;212 result.should.equal('redirect returned');213 });214 });215 describe('when the request URL has a port that is 80 or 443', () => {216 it('does not include the port in the s3o redirect', () => {217 reqFixture.headers.host = 'localhost';218 reqFixture.headers = Object.assign(reqFixture.headers, run.options.requestHeader);219 reqFixture.protocol = 'https';220 reqFixture.hostname = 'localhost';221 reqFixture.originalUrl = '/';222 reqFixture.get.withArgs('host').returns('localhost:80');223 resFixture.redirect.returns('redirect returned');224 const result = s3o(reqFixture, resFixture, nextStub);225 resFixture.header.withArgs('Cache-Control', 'private, no-cache, no-store, must-revalidate')226 .should.have.been.calledOnce;227 resFixture.header.withArgs('Pragma', 'no-cache').should.have.been.calledOnce;228 resFixture.header.withArgs('Expires', 0).should.have.been.calledOnce;229 resFixture.redirect.withArgs(run.options.redirectLocation)230 .should.have.been.calledOnce;231 result.should.equal('redirect returned');232 });233 });234 });235 });236 describe('no redirect authentication',() => {237 it('calls next() on successful authentication',() => {238 authenticateTokenStub.returns(true);239 const result = s3o.authS3ONoRedirect(reqFixture,resFixture,nextStub);240 authenticateTokenStub.withArgs('test','localhost','test-test-123').should.have.been.calledOnce;241 nextStub.should.have.been.calledOnce;242 result.should.equal('next returned');243 });244 it('returns 403 on authentication failure',() => {245 authenticateTokenStub.returns(false);246 s3o.authS3ONoRedirect(reqFixture,resFixture,nextStub);247 authenticateTokenStub.withArgs('test','localhost','test-test-123').should.have.been.calledOnce;248 nextStub.should.not.have.been.called;249 resFixture.clearCookie.withArgs(cookies.USERNAME).should.have.been.calledOnce;250 resFixture.clearCookie.withArgs(cookies.TOKEN).should.have.been.calledOnce;251 resFixture.status.withArgs(403).should.have.been.calledOnce;252 resFixture.send.withArgs('Forbidden').should.have.been.calledOnce;253 });254 });255 });...

Full Screen

Full Screen

response.spec.js

Source:response.spec.js Github

copy

Full Screen

1const response = require('server/lib/response')2const log = require('server/lib/log')3const HTTPError = require('http-errors')4const obey = require('obey')5const reqFixture = {6 originalUrl: 'foo',7 method: 'get',8 clientIP: '1.1.1.1',9 sessionId: '1111-2222-3333'10}11describe('server > lib > response', () => {12 let logInfoStub13 let logErrorStub14 let resFixture15 let resSendStub16 beforeEach(() => {17 logInfoStub = sinon.stub(log, 'info')18 logErrorStub = sinon.stub(log, 'error')19 resSendStub = sinon.stub()20 resFixture = {21 data: { foo: 'bar' },22 status: function (code) {23 this.send = resSendStub24 return this25 }26 }27 })28 afterEach(() => {29 logInfoStub.restore()30 logErrorStub.restore()31 })32 describe('success', () => {33 it('logs response data and sends response back through express', () => {34 const resStatusSpy = sinon.spy(resFixture, 'status')35 response.success(reqFixture, resFixture, sinon.stub())36 expect(resStatusSpy).to.be.calledWith(200)37 expect(resSendStub).to.be.calledWith(resFixture.data)38 expect(logInfoStub).to.be.calledWith('Success Response', {39 route: reqFixture.originalUrl,40 method: reqFixture.method.toUpperCase(),41 sessionId: reqFixture.sessionId,42 ip: reqFixture.clientIP43 })44 })45 })46 describe('error', () => {47 it('logs http error and sends response back through express', () => {48 const resStatusSpy = sinon.spy(resFixture, 'status')49 response.error(new HTTPError(404), reqFixture, resFixture, sinon.stub())50 expect(resStatusSpy).to.be.calledWith(404)51 expect(resSendStub).to.be.calledWith('Not Found')52 expect(logErrorStub).to.be.calledWith('Error Response', {53 route: reqFixture.originalUrl,54 method: reqFixture.method.toUpperCase(),55 sessionId: reqFixture.sessionId,56 ip: reqFixture.clientIP,57 code: 404,58 error: 'Not Found'59 })60 })61 it('logs data validation error and sends response back through express', () => {62 const resStatusSpy = sinon.spy(resFixture, 'status')63 response.error(new obey.ValidationError([{ key: 'foo', value: 'bar', message: 'Must be foo' }]), reqFixture, resFixture, sinon.stub())64 expect(resStatusSpy).to.be.calledWith(400)65 expect(resSendStub).to.be.calledWith({66 message: 'foo (bar): Must be foo',67 collection: [{ key: 'foo', message: 'Must be foo', value: 'bar' }]68 })69 expect(logErrorStub).to.be.calledWith('Error Response', {70 route: reqFixture.originalUrl,71 method: reqFixture.method.toUpperCase(),72 sessionId: reqFixture.sessionId,73 ip: reqFixture.clientIP,74 code: 400,75 error: 'foo (bar): Must be foo'76 })77 })78 it('logs non-http error and sends response back through express', () => {79 const resStatusSpy = sinon.spy(resFixture, 'status')80 response.error(new Error(), reqFixture, resFixture, sinon.stub())81 expect(resStatusSpy).to.be.calledWith(500)82 expect(resSendStub).to.be.calledWith('Internal Server Error')83 expect(logErrorStub).to.be.calledWith('Error Response', {84 route: reqFixture.originalUrl,85 method: reqFixture.method.toUpperCase(),86 sessionId: reqFixture.sessionId,87 ip: reqFixture.clientIP,88 code: 500,89 error: 'Internal Server Error'90 })91 })92 })...

Full Screen

Full Screen

mock-request.js

Source:mock-request.js Github

copy

Full Screen

...23 const {url, method, json} = opts;24 if (/badurl$/.test(url)) {25 throw new Error('noworky');26 }27 const [status, data] = resFixture(url, method, json);28 return {29 status,30 headers: {'content-type': 'application/json; charset=utf-8'},31 data,32 };33}...

Full Screen

Full Screen

sheets.spec.js

Source:sheets.spec.js Github

copy

Full Screen

1const test = require('tape')2const proxyquire = require('proxyquire')3const resFixture = require('./fixtures/response.json')4const geojsonFixture = require('./fixtures/geojson.json')5const modulePath = '../sheets'6const Model = proxyquire(modulePath, {7 'googleapis': {8 google: {9 sheets: () => {10 return {11 spreadsheets: {12 values: {13 get: (params, options, callback) => {14 callback(null, resFixture)15 }16 }17 }18 }19 }20 }21 }22})23test('model translation to geojson', spec => {24 spec.plan(2)25 const model = new Model()26 const reqMock = {27 params: {28 id: 'fires!A1:I'29 }30 }31 model.getData(reqMock, (err, geojson) => {32 spec.notOk(err)33 spec.deepEquals(geojson, geojsonFixture, 'generates expected geojson')34 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var assert = require('assert');3var wd = require('wd');4var chai = require('chai');5var chaiAsPromised = require('chai-as-promised');6chai.use(chaiAsPromised);7var should = chai.should();8var serverConfigs = require('./appium-servers');9var desired = {10 app: path.resolve(__dirname, '../../apps/TestApp/build/Release-iphonesimulator/TestApp.app'),11};12var driver = wd.promiseChainRemote(serverConfigs.local);13driver.on('status', function (info) {14 console.log(info.cyan);15});16driver.on('command', function (eventType, command, response) {17 console.log(' > ' + eventType.cyan, command, (response || '').grey);18});19driver.on('http', function (meth, path, data) {20 console.log(' > ' + meth.magenta, path, (data || '').grey);21});22 .init(desired)23 .then(function () {24 var element = driver.elementByAccessibilityId('ComputeSumButton');25 .waitForElementByAccessibilityId('ComputeSumButton', 3000)26 .click()27 .text().should.eventually.equal('10');28 })29 .then(function () {30 .elementByAccessibilityId('Show alert')31 .click()32 .sleep(1000);33 })34 .then(function () {35 .alertText().should.eventually.include('Cool title')36 .acceptAlert()37 .sleep(1000);38 })39 .then(function () {40 .elementByAccessibilityId('Show date picker')41 .click()42 .sleep(1000);43 })44 .then(function () {45 .sendKeys('1')46 .sendKeys('1')

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumBaseDriver = require('appium-base-driver');2var resFixture = AppiumBaseDriver.resFixture;3var path = require('path');4var resPath = path.resolve(__dirname, 'test.json');5var res = resFixture(resPath);6var AppiumBaseDriver = require('appium-base-driver');7var resFixture = AppiumBaseDriver.resFixture;8var path = require('path');9var resPath = path.resolve(__dirname, 'test.json');10var res = resFixture(resPath);11var AppiumBaseDriver = require('appium-base-driver');12var resFixture = AppiumBaseDriver.resFixture;13var path = require('path');14var resPath = path.resolve(__dirname, 'test.json');15var res = resFixture(resPath);16var AppiumBaseDriver = require('appium-base-driver');17var resFixture = AppiumBaseDriver.resFixture;18var path = require('path');19var resPath = path.resolve(__dirname, 'test.json');20var res = resFixture(resPath);21var AppiumBaseDriver = require('appium-base-driver');22var resFixture = AppiumBaseDriver.resFixture;23var path = require('path');24var resPath = path.resolve(__dirname, 'test.json');25var res = resFixture(resPath);26var AppiumBaseDriver = require('appium-base-driver');27var resFixture = AppiumBaseDriver.resFixture;28var path = require('path');29var resPath = path.resolve(__dirname, 'test.json');30var res = resFixture(resPath);31var AppiumBaseDriver = require('appium-base-driver');32var resFixture = AppiumBaseDriver.resFixture;33var path = require('path');34var resPath = path.resolve(__dirname, 'test.json');35var res = resFixture(resPath);36var AppiumBaseDriver = require('appium-base-driver');37var resFixture = AppiumBaseDriver.resFixture;38var path = require('path');39var resPath = path.resolve(__dirname, 'test.json

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new AppiumDriver();2driver.resFixture('test', function(err, res) {3 console.log(res);4});5var driver = new AppiumDriver();6driver.resFixture('test', function(err, res) {7 console.log(res);8});9var driver = new AppiumDriver();10driver.resFixture('test', function(err, res) {11 console.log(res);12});13var driver = new AppiumDriver();14driver.resFixture('test', function(err, res) {15 console.log(res);16});17var driver = new AppiumDriver();18driver.resFixture('test', function(err, res) {19 console.log(res);20});21var driver = new AppiumDriver();22driver.resFixture('test', function(err, res) {23 console.log(res);24});25var driver = new AppiumDriver();26driver.resFixture('test', function(err, res) {27 console.log(res);28});29var driver = new AppiumDriver();30driver.resFixture('test', function(err, res) {31 console.log(res);32});33var driver = new AppiumDriver();34driver.resFixture('test', function(err, res) {35 console.log(res);36});37var driver = new AppiumDriver();38driver.resFixture('test', function(err, res) {39 console.log(res);40});41var driver = new AppiumDriver();42driver.resFixture('test', function(err, res) {43 console.log(res);44});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { resFixture } = require('../appium-base-driver/lib/test-utils');2const { describe, it } = require('mocha');3const { assert } = require('chai');4describe('sample test', function () {5 it('should pass', async function () {6 const res = await resFixture('sample-response.json');7 assert.equal(res.value, 1);8 });9});10const res = await resFixture('../fixtures/sample-response.json');11const path = require('path');12const res = await resFixture(path.resolve(__dirname, '../fixtures/sample-response.json'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var resFixture = require('appium-base-driver').resFixture;3var res = resFixture(path.resolve('test.js'), 'test.png');4console.log(res);5var path = require('path');6var resFixture = require('appium-base-driver').resFixture;7var res = resFixture(path.resolve('test.js'), 'test.txt');8console.log(res);9var path = require('path');10var resFixture = require('appium-base-driver').resFixture;11var res = resFixture(path.resolve('test.js'), 'test.jpg');12console.log(res);13var path = require('path');14var resFixture = require('appium-base-driver').resFixture;15var res = resFixture(path.resolve('test.js'), 'test.json');16console.log(res);17var path = require('path');18var resFixture = require('appium-base-driver').resFixture;19var res = resFixture(path.resolve('test.js'), 'test.xml');20console.log(res);21var path = require('path');22var resFixture = require('appium-base-driver').resFixture;23var res = resFixture(path.resolve('test.js'), 'test.html');24console.log(res);25var path = require('path');26var resFixture = require('appium-base-driver').resFixture;27var res = resFixture(path.resolve('test.js'), 'test.yaml');28console.log(res);29var path = require('path');30var resFixture = require('appium

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', function() {2 it('should test', function() {3 driver.resFixture('path/to/res', 'resName', 'resType');4 });5});6describe('Test', function() {7 it('should test', function() {8 driver.resFixture('path/to/res', 'resName', 'resType', 'resId');9 });10});11describe('Test', function() {12 it('should test', function() {13 driver.resFixture('path/to/res', 'resName', 'resType', 'resId', 1);14 });15});16describe('Test', function() {17 it('should test', function() {18 driver.resFixture('path/to/res', 'resName', 'resType', 'resId', 1, 1);19 });20});21describe('Test', function() {22 it('should test', function() {23 driver.resFixture('path/to/res', 'resName', 'resType', 'resId', 1, 1, 1);24 });25});26describe('Test', function() {27 it('should test', function() {28 driver.resFixture('path/to/res', 'resName', 'resType', 'resId', 1, 1, 1, 1);29 });30});31describe('Test', function() {32 it('should test', function() {33 driver.resFixture('path/to/res', 'resName', 'resType', 'resId', 1, 1, 1, 1, 1);34 });35});36describe('Test', function() {37 it('should test', function() {38 driver.resFixture('path/to/res', 'resName', 'resType', 'resId', 1, 1,

Full Screen

Using AI Code Generation

copy

Full Screen

1var responsePath = '/Users/xyz/Downloads/AppiumBaseDriver-master/test/fixtures';2var requestPath = '/Users/xyz/Downloads/AppiumBaseDriver-master/test/fixtures';3var driver = new BaseDriver({4});5driver.resFixture('getScreenshot', function(err, res) {6 console.log(res);7});8{9}10driver.reqFixture('getScreenshot', function(err, res) {11 console.log(res);12});13{14 headers: {15 'Content-Type': 'application/json; charset=utf-8',16 }17}

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 Appium Base Driver 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