Best JavaScript code snippet using appium-base-driver
config-http-specs.js
Source:config-http-specs.js
...29 currentHttpConfig = wd.getHttpConfig();30 });31 afterEach(function() {32 var _this = this;33 wd.configureHttp(currentHttpConfig);34 wd.getHttpConfig().should.deep.equal(currentHttpConfig);35 if(browser && browser.sessionID){36 return browser37 .quit().then(function() {38 if(env.SAUCE) { return(browser.sauceJobStatus(_this.currentTest.state === 'passed')); }39 });40 }41 });42 after(function(done) {43 express.stop(done);44 });45 it("wd.configureHttp", function() {46 var newConfig = {47 timeout: env.HTTP_TIMEOUT || 60000,48 retries: env.HTTP_RETRIES || 10,49 retryDelay: env.HTTP_RETRY_DELAY || 50,50 baseUrl: 'http://example.com',51 proxy: undefined52 };53 var newConfig2 = _(newConfig).clone();54 newConfig2.baseUrl = 'http://example2.com';55 wd.configureHttp(newConfig);56 wd.getHttpConfig().should.deep.equal(newConfig);57 wd.configureHttp( {baseUrl: 'http://example2.com' } );58 wd.getHttpConfig().should.deep.equal(newConfig2);59 promiseChainRemote();60 browser._httpConfig.should.deep.equal(newConfig2);61 });62 it("browser.configureHttp", function() {63 var wdCurrent = wd.getHttpConfig();64 promiseChainRemote();65 browser._httpConfig.should.deep.equal(wdCurrent);66 var newConfig = {67 timeout: env.HTTP_TIMEOUT || 60000,68 retries: env.HTTP_RETRIES || 10,69 retryDelay: env.HTTP_RETRY_DELAY || 50,70 baseUrl: 'http://example3.com',71 proxy: undefined72 };73 var newConfig2 = _(newConfig).clone();74 newConfig2.baseUrl = 'http://example4.com';75 browser.configureHttp(newConfig);76 browser._httpConfig.should.deep.equal(newConfig);77 wd.getHttpConfig().should.deep.equal(wdCurrent);78 browser.configureHttp( {baseUrl: 'http://example4.com' } );79 browser._httpConfig.should.deep.equal(newConfig2);80 wd.getHttpConfig().should.deep.equal(wdCurrent);81 });82 it('browser.configureHttp (using promise)', function() {83 promiseChainRemote();84 var current = _(browser._httpConfig).clone();85 current.should.exist;86 var wdCurrent = wd.getHttpConfig();87 var newConfig = {88 timeout: env.HTTP_TIMEOUT || 60000,89 retries: env.HTTP_RETRIES || 10,90 retryDelay: env.HTTP_RETRY_DELAY || 50,91 baseUrl: 'http://example.com/',92 proxy: undefined93 };94 if(newConfig.retryDelay = wdCurrent.retryDelay) { newConfig.retryDelay++; }95 return browser96 .configureHttp( newConfig).then(function() {97 browser._httpConfig.should.deep.equal(newConfig);98 wd.getHttpConfig().should.deep.equal(wdCurrent);99 })100 .configureHttp(current).should.be.fulfilled;101 });102 it("setting global baseUrl", function() {103 var url = midwayUrl( this.runnable().parent.title, this.runnable().title);104 var matcher = url.match(/(.*\/)(test-page.*)/);105 var baseUrl = matcher[1];106 should.exist(baseUrl);107 var relUrl = matcher[2];108 should.exist(relUrl);109 wd.configureHttp({baseUrl: baseUrl});110 promiseChainRemote();111 return browser112 .init(buildDesired( this.runnable().parent.title + " #1"))113 .get(url)114 .title().should.eventually.include('WD Tests - config-http')115 .get(relUrl).title().should.eventually.include('WD Tests - config-http')116 ;117 });118 it("setting browser baseUrl", function() {119 var url = midwayUrl( this.runnable().parent.title, this.runnable().title);120 var matcher = url.match(/(.*\/)(test-page.*)/);121 var baseUrl = matcher[1];122 should.exist(baseUrl);123 var relUrl = matcher[2];124 should.exist(relUrl);125 promiseChainRemote();126 should.not.exist(browser._httpConfig.baseUrl);127 return browser128 .init(buildDesired( this.runnable().parent.title + " #2"))129 .then(function() {130 return browser131 .get(relUrl).should.eventually.include('WD Tests - config-http')132 .should.be.rejected;133 })134 .configureHttp({baseUrl: baseUrl})135 .get(relUrl).title().should.eventually.include('WD Tests - config-http')136 .get(url).title().should.eventually.include('WD Tests - config-http');137 });138 it("wd baseUrl override", function() {139 var url = midwayUrl( this.runnable().parent.title, this.runnable().title);140 var matcher = url.match(/(.*\/)(test-page.*)/);141 var baseUrl = matcher[1];142 should.exist(baseUrl);143 var relUrl = matcher[2];144 should.exist(relUrl);145 wd.configureHttp({baseUrl: 'http://__nowhere__:1234/'});146 promiseChainRemote();147 browser._httpConfig.baseUrl.should.include('__nowhere');148 return browser149 .init(buildDesired( this.runnable().parent.title + " #3"))150 .then(function() {151 return browser152 .get(relUrl).should.eventually.include('WD Tests - config-http')153 .should.be.rejected;154 })155 .configureHttp({baseUrl: baseUrl}) 156 .get(relUrl).title().should.eventually.include('WD Tests - config-http')157 .get(url).title().should.eventually.include('WD Tests - config-http');158 });...
http-specs.js
Source:http-specs.js
...3 describe("global http settings", function() {4 it("should be able to configure http", function(done) {5 wd.getHttpConfig().should.exists;6 var current = wd.getHttpConfig();7 wd.configureHttp({timeout: 60000, retries: 3, retryDelay: 15, baseUrl: 'http://example.com/' });8 wd.getHttpConfig().should.deep.equal(9 {timeout: 60000, retries: 3, retryDelay: 15, rejectUnauthorized: true,10 baseUrl: 'http://example.com/', proxy: undefined});11 wd.configureHttp({timeout: 'default'});12 wd.getHttpConfig().should.deep.equal(13 {timeout: undefined, retries: 3, retryDelay: 15, rejectUnauthorized: true,14 baseUrl: 'http://example.com/', proxy: undefined});15 wd.configureHttp({retries: 'always'});16 wd.getHttpConfig().should.deep.equal(17 {timeout: undefined, retries: 0, retryDelay: 15, rejectUnauthorized: true,18 baseUrl: 'http://example.com/', proxy: undefined});19 wd.configureHttp({retries: 'never'});20 wd.getHttpConfig().should.deep.equal(21 {timeout: undefined, retries: -1, retryDelay: 15, rejectUnauthorized: true,22 baseUrl: 'http://example.com/', proxy: undefined});23 wd.configureHttp({proxy: 'http://proxy.com'});24 wd.getHttpConfig().should.deep.equal(25 {timeout: undefined, retries: -1, retryDelay: 15, rejectUnauthorized: true,26 baseUrl: 'http://example.com/', proxy: 'http://proxy.com'});27 wd.configureHttp({rejectUnauthorized: false});28 wd.getHttpConfig().should.deep.equal(29 {timeout: undefined, retries: -1, retryDelay: 15, rejectUnauthorized: false,30 baseUrl: 'http://example.com/', proxy: 'http://proxy.com'});31 wd.configureHttp(current);32 wd.getHttpConfig().should.deep.equal(current);33 done();34 });35 });...
main.js
Source:main.js
...7// Store Instantiation8// ========================================================9const initialState = window.___INITIAL_STATE__10const store = createStore(initialState)11configureHttp(store);12// ========================================================13// Render Setup14// ========================================================15const MOUNT_NODE = document.getElementById('root')16let render = () => {17 const routes = require('./routes/index').default(store)18 ReactDOM.render(19 <AppContainer store={store} routes={routes} />,20 MOUNT_NODE21 )22}23// This code is excluded from production bundle24if (__DEV__) {25 if (module.hot) {...
configure-http.test.js
Source:configure-http.test.js
2import { successUrl } from 'isomorphic-fetch'3// These tests rely on the mock Fetch() 4// returning options as the response5test('configureHttp adds defaults to request options', () => {6 const myHttp = configureHttp({ credentials: 'foo' })7 return myHttp(successUrl, { mode: 'bar' }).then((res) => {8 expect(res.credentials).toEqual('foo')9 expect(res.mode).toEqual('bar')10 })11})12test('configureHttp works with request object', () => {13 const myHttp = configureHttp({ credentials: 'foo' })14 return myHttp({ url: successUrl, mode: 'bar' }).then((res) => {15 expect(res.credentials).toEqual('foo')16 expect(res.mode).toEqual('bar')17 })18})19test('configureHttp can accept a custom base http', () => {20 const myFirstHttp = configureHttp({ credentials: 'foo' })21 const mySecondHttp = configureHttp({ mode: 'bar' }, myFirstHttp)22 return mySecondHttp(successUrl, { cache: 'baz' }).then((res) => {23 expect(res.credentials).toEqual('foo')24 expect(res.mode).toEqual('bar')25 expect(res.cache).toEqual('baz')26 })...
configUpdateServer.js
Source:configUpdateServer.js
...16 fs.writeFileSync(cfgFile, JSON.stringify(temp));17 console.log('update-server Configuration completed');18};19var configure = exp.configure = function(){20 configureHttp(path.join(cfgDir, 'config.json'), path.join(cfgDir, 'config.json.bak'));21};22exp.getNeedOpenPorts = function(cfgDir){23 var conf = JSON.parse(fs.readFileSync(path.join(cfgDir, 'config.json'), {encoding: 'utf8'}));24 return [parseInt(conf.port)];25};...
config.js
Source:config.js
...5 retryDelay: 15,6 baseUrl: undefined,7 proxy: undefined8};9function _configureHttp(httpConfig, opts) {10 _(_.keys(httpConfig)).intersection(_.keys(opts)).each(function(key) {11 switch(key) {12 case 'timeout':13 if(opts[key] === 'default') { opts[key] = undefined; }14 break;15 case 'retries':16 if(opts[key] === 'always') { opts[key] = 0; }17 if(opts[key] === 'never') { opts[key] = -1; }18 break;19 }20 httpConfig[key] = opts[key];21 }, this);22}23function configureHttp(opts) {24 _configureHttp(httpConfig, opts);25}26module.exports = {27 httpConfig: httpConfig,28 _configureHttp: _configureHttp,29 configureHttp: configureHttp...
services.js
Source:services.js
1define(["angular", "app/utilsService", "app/backendService", "app/rentalService"],2 function (angular, utilsServiceFactory, backendServiceFactory, rentalServiceFactory) {3 function configureHttp($httpProvider) {4 $httpProvider.defaults.headers.post = {'Content-Type':'application/json'};5 }6 configureHttp.$inject = ["$httpProvider"];7 var module = angular.module("rylc-services", []);8 module.config(configureHttp);9 module.factory("utilsService", utilsServiceFactory);10 module.factory("backendService", backendServiceFactory);11 module.factory("rentalService", rentalServiceFactory);...
Using AI Code Generation
1var AppiumBaseDriver = require('appium-base-driver').AppiumBaseDriver;2var appiumBaseDriver = new AppiumBaseDriver();3appiumBaseDriver.configureHttp({timeout: 60000});4var AppiumDriver = require('appium').AppiumDriver;5var appiumDriver = new AppiumDriver();6appiumDriver.configureHttp({timeout: 60000});7var AppiumDriver = require('appium').AppiumDriver;8var appiumDriver = new AppiumDriver();9appiumDriver.configureHttp({timeout: 60000});10var BaseDriver = require('appium-base-driver').BaseDriver;11var baseDriver = new BaseDriver();12baseDriver.configureHttp({timeout: 60000});13var Driver = require('appium').Driver;14var driver = new Driver();15driver.configureHttp({timeout: 60000});16var AppiumBaseDriver = require('appium-base-driver').AppiumBaseDriver;17var appiumBaseDriver = new AppiumBaseDriver();18appiumBaseDriver.configureHttp({timeout: 60000});19var AppiumDriver = require('appium').AppiumDriver;20var appiumDriver = new AppiumDriver();21appiumDriver.configureHttp({timeout: 60000});22var AppiumDriver = require('appium').AppiumDriver;23var appiumDriver = new AppiumDriver();24appiumDriver.configureHttp({timeout: 60000});25var BaseDriver = require('appium-base-driver').BaseDriver;26var baseDriver = new BaseDriver();27baseDriver.configureHttp({timeout: 60000});28var Driver = require('appium').Driver;29var driver = new Driver();30driver.configureHttp({timeout: 60000});
Using AI Code Generation
1var Appium = require('appium');2var appium = new Appium();3var appiumBaseDriver = appium.getBaseDriverClass('appium-base-driver');4var appiumBaseDriverObj = new appiumBaseDriver();5appiumBaseDriverObj.configureHttp({timeout: 60000});6var Appium = require('appium');7var appium = new Appium();8var appiumBaseDriver = appium.getBaseDriverClass('appium-base-driver');9var appiumBaseDriverObj = new appiumBaseDriver();10appiumBaseDriverObj.configureHttp({timeout: 60000});
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2const appiumBaseDriver = new AppiumBaseDriver();3appiumBaseDriver.configureHttp({4});5const AppiumDriver = require('appium');6const appiumDriver = new AppiumDriver();7appiumDriver.configureHttp({8});9const appiumExpress = require('appium/lib/appium');10appiumExpress.configureHttp({11});12I have read the Appium Code of Conduct (
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2AppiumBaseDriver.prototype.configureHttp = function (opts) {3};4const AppiumBaseDriver = require('appium-base-driver');5AppiumBaseDriver.prototype.configureHttp = function (opts) {6};7const AppiumBaseDriver = require('appium-base-driver');8AppiumBaseDriver.prototype.configureHttp = function (opts) {9};
Using AI Code Generation
1const { AppiumDriver } = require('appium-base-driver');2const { appiumServer } = require('appium');3const appium = new appiumServer();4const appiumDriver = new AppiumDriver(appium);5appiumDriver.configureHttp({6 headers: {7 },8});9const { AppiumExpressDriver } = require('appium-express-driver');10const { appiumServer } = require('appium');11const appium = new appiumServer();12const appiumDriver = new AppiumExpressDriver(appium);13appiumDriver.configureHttp({14 headers: {15 },16});17const { AppiumFakeDriver } = require('appium-fake-driver');18const { appiumServer } = require('appium');19const appium = new appiumServer();20const appiumDriver = new AppiumFakeDriver(appium);21appiumDriver.configureHttp({22 headers: {23 },24});25const { AppiumFlutterDriver } = require('appium-flutter-driver');26const { appiumServer } = require('appium');27const appium = new appiumServer();28const appiumDriver = new AppiumFlutterDriver(appium);29appiumDriver.configureHttp({
Using AI Code Generation
1const { AppiumDriver, util } = require('appium-base-driver');2const { configureHttp } = require('appium-base-driver/lib/protocol/http');3const { startServer } = require('appium-base-driver/lib/protocol/protocol');4const { routeConfiguringFunction } = require('appium-base-driver/lib/protocol/routes');5const { createSession } = require('appium-base-driver/lib/protocol/create-session');6const { deleteSession } = require('appium-base-driver/lib/protocol/delete-session');7const { validateConfig } = require('appium-base-driver/lib/protocol/validation');8const { errors } = require('appium-base-driver');9const driver = new AppiumDriver();10const http = configureHttp({11 notFound: (req, res) => {12 res.status(404).json(errors.errorToJson(errors.NoSuchDriverError(req.originalUrl)));13 },14 notAllowedMethod: (req, res) => {15 res.status(405).json(errors.errorToJson(errors.MethodNotAllowedError(req.method)));16 },17 errorHandler: (err, req, res, next) => {18 if (err instanceof errors.ErrorResponse) {19 res.status(err.status).json(errors.errorToJson(err));20 } else {21 next(err);22 }23 },24});25startServer(http, driver, {26});27const { AppiumDriver, util } = require('appium-base-driver');28const { configureHttp } = require('appium-base-driver/lib/protocol/http');29const { startServer } = require('appium-base-driver/lib/protocol/protocol');30const { routeConfiguringFunction } = require('appium-base-driver/lib/protocol/routes');31const { create
Using AI Code Generation
1describe('Appium Base Driver', function() {2 describe('configureHttp', function() {3 it('should configure http', function() {4 let driver = new AppiumDriver();5 driver.configureHttp({timeout: 1234});6 driver.httpConfig.timeout.should.equal(1234);7 });8 });9});10class AppiumDriver extends BaseDriver {11 constructor (opts = {}) {12 super(opts);13 this.opts = opts;14 this.httpConfig = {};15 this.configureHttp(opts);16 }17 configureHttp (opts) {18 this.httpConfig = {19 };20 }21}22class BaseDriver {23 constructor (opts = {}) {24 this.opts = opts;25 this.httpConfig = {};26 this.configureHttp(opts);27 }28 configureHttp (opts) {29 this.httpConfig = {30 };31 }32}33describe('Appium Driver', function() {34 describe('configureHttp', function() {35 it('should configure http', function() {36 let driver = new AppiumDriver();37 driver.configureHttp({timeout: 1234});38 driver.httpConfig.timeout.should.equal(1234);39 });40 });41});42describe('BaseDriver', function() {43 describe('configureHttp', function() {44 it('should configure http', function() {45 let driver = new BaseDriver();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!