Best JavaScript code snippet using appium-xcuitest-driver
services.js
Source:services.js
1//@exclude2'use strict';3//@endexclude4(function () {5 /**6 * A base object to inherit from for make corbel-js requests with custom behavior.7 * @exports Services8 * @namespace9 * @extends corbel.Object10 * @memberof corbel11 */12 var Services = corbel.Services = corbel.Object.inherit({ //instance props13 /**14 * Creates a new Services15 * @memberof corbel.Services.prototype16 * @param {string} id String with the asset id or `all` key17 * @return {corbel.Services}18 */19 constructor: function (driver) {20 this.driver = driver;21 },22 /**23 * Execute the actual ajax request.24 * Retries request with refresh token when credentials are needed.25 * Refreshes the client when a force update is detected.26 * Returns a server error (corbel.Services._FORCE_UPDATE_STATUS_CODE - unsupported_version) when force update max retries are reached27 *28 * @memberof corbel.Services.prototype29 * @param {Promise} dfd The deferred object to resolve when the ajax request is completed.30 * @param {object} args The request arguments.31 */32 request: function (args) {33 this.driver.trigger('service:request:before', args);34 var that = this;35 return this._requestWithRetries(args).then(function (response) {36 that.driver.trigger('service:request:after', response);37 that.driver.config.set(corbel.Services._UNAUTHORIZED_NUM_RETRIES, 0);38 return response;39 }).catch(function (error) {40 that.driver.trigger('service:request:after', error);41 that.driver.config.set(corbel.Services._UNAUTHORIZED_NUM_RETRIES, 0);42 throw error;43 });44 },45 _requestWithRetries: function (args) {46 var that = this;47 var maxRetries = corbel.Services._UNAUTHORIZED_MAX_RETRIES;48 var requestParameters = that._buildParams(args);49 return that._doRequest(requestParameters)50 .catch(function (response) {51 var retries = that.driver.config.get(corbel.Services._UNAUTHORIZED_NUM_RETRIES, 0);52 if (retries < maxRetries && response.status === corbel.Services._UNAUTHORIZED_STATUS_CODE) {53 //A 401 request within, refresh the token and retry the request.54 return that._refreshToken()55 .then(function () {56 that.driver.config.set(corbel.Services._UNAUTHORIZED_NUM_RETRIES, retries + 1);57 //@TODO: see if we need to upgrade the token to access assets.58 return that._requestWithRetries(args).catch(function (retryResponse) {59 // rejects whole promise with the retry response60 response = retryResponse;61 throw response;62 });63 }).catch(function () {64 //Has failed refreshing, reject request65 console.log('corbeljs:services:token:refresh:fail');66 throw response;67 });68 } else {69 console.log('corbeljs:services:token:no_refresh', response.status);70 throw response;71 }72 });73 },74 /**75 * Internal request method.76 * Has force update behavior77 * @param {object} params78 * @return {Promise}79 */80 _doRequest: function (params) {81 var that = this;82 return corbel.request.send(params, that.driver).then(function (response) {83 that.driver.config.set(corbel.Services._FORCE_UPDATE_STATUS, 0);84 that.driver.config.set(corbel.Services._UNAUTHORIZED_NUM_RETRIES, 0);85 return response;86 }).catch(function (response) {87 // Force update88 if (response.status === corbel.Services._FORCE_UPDATE_STATUS_CODE &&89 response.textStatus === corbel.Services._FORCE_UPDATE_TEXT) {90 var retries = that.driver.config.get(corbel.Services._FORCE_UPDATE_STATUS, 0);91 if (retries < corbel.Services._FORCE_UPDATE_MAX_RETRIES) {92 retries++;93 that.driver.config.set(corbel.Services._FORCE_UPDATE_STATUS, retries);94 that.driver.trigger('force:update', response);95 throw response;96 } else {97 throw response;98 }99 } else {100 throw response;101 }102 });103 },104 _refreshToken: function () {105 var tokenObject = this.driver.config.get(corbel.Iam.IAM_TOKEN, {});106 return this._refreshHandler(tokenObject);107 },108 /**109 * Default token refresh handler110 * Only requested once at the same time111 * @return {Promise}112 */113 _refreshHandler: function (tokenObject) {114 var that = this;115 if (this.driver._refreshHandlerPromise) {116 return this.driver._refreshHandlerPromise;117 }118 if (tokenObject.refreshToken) {119 console.log('corbeljs:services:token:refresh');120 this.driver._refreshHandlerPromise = this.driver.iam.token().refresh(121 tokenObject.refreshToken,122 this.driver.config.get(corbel.Iam.IAM_TOKEN_SCOPES, '')123 );124 } else {125 console.log('corbeljs:services:token:create');126 this.driver._refreshHandlerPromise = this.driver.iam.token().create();127 }128 return this.driver._refreshHandlerPromise129 .then(function (response) {130 that.driver.trigger('token:refresh', response.data);131 that.driver._refreshHandlerPromise = null;132 return response;133 }).catch(function (err) {134 that.driver._refreshHandlerPromise = null;135 throw err;136 });137 },138 /**139 * Add Authorization header with default tokenObject140 * @param {object} params request builded params141 */142 _addAuthorization: function (params) {143 var accessToken = params.accessToken ? params.accessToken : this.driver.config144 .get(corbel.Iam.IAM_TOKEN, {}).accessToken;145 if (accessToken && !params.headers.Authorization) {146 params.headers.Authorization = 'Bearer ' + accessToken;147 params.withCredentials = true;148 } else if (params.headers.Authorization) {149 params.withCredentials = true;150 }151 return params;152 },153 /**154 * Returns a valid corbel.request parameters with default values155 * and authorization params if needed.156 * By default, all request are json (dataType/contentType)157 * with object serialization support158 *159 * @memberof corbel.Services.prototype160 * @param {object} args161 * @return {object}162 */163 _buildParams: function (args) {164 // Default values165 var defaults = {166 dataType: 'json',167 contentType: 'application/json; charset=utf-8',168 dataFilter: corbel.Services.addEmptyJson,169 headers: {170 Accept: 'application/json'171 },172 method: corbel.request.method.GET173 };174 // do not modify args object175 var params = corbel.utils.defaults({}, args);176 params = corbel.utils.defaults(params, defaults);177 if (!params.url) {178 throw new Error('You must define an url');179 }180 if (params.query) {181 params.url += '?' + params.query;182 }183 if (params.noRedirect) {184 params.headers['No-Redirect'] = true;185 }186 if (params.Accept) {187 params.headers.Accept = params.Accept;188 params.dataType = undefined; // Accept & dataType are incompatibles189 }190 // set correct accept & contentType in case of blob191 // @todo: remove contentType+accept same-type constraint192 if (params.dataType === 'blob') {193 if (corbel.Config.isBrowser) {194 params.headers.Accept = params.data.type;195 params.contentType = params.data.type;196 params.dataType = undefined; // Accept & dataType are incompatibles197 }198 }199 params = this._addAuthorization(params);200 return corbel.utils.pick(params, ['url', 'dataType', 'contentType', 'method', 'headers', 'data', 'dataFilter', 'responseType', 'withCredentials', 'success', 'error']);201 },202 /**203 * @memberof corbel.Services.prototype204 * @return {string}205 */206 _buildUri: function () {207 var uri = '';208 if (this.urlBase.slice(-1) !== '/') {209 uri += '/';210 }211 Array.prototype.slice.call(arguments).forEach(function (argument) {212 if (argument) {213 uri += argument + '/';214 }215 });216 // remove last '/'217 uri = uri.slice(0, -1);218 return this.urlBase + uri;219 }220 }, {221 /**222 * _FORCE_UPDATE_TEXT constant223 * @constant224 * @memberof corbel.Services225 * @type {string}226 * @default227 */228 _FORCE_UPDATE_TEXT: 'unsupported_version',229 /**230 * _FORCE_UPDATE_MAX_RETRIES constant231 * @constant232 * @memberof corbel.Services233 * @type {number}234 * @default235 */236 _FORCE_UPDATE_MAX_RETRIES: 3,237 /**238 * _FORCE_UPDATE_STATUS constant239 * @constant240 * @memberof corbel.Services241 * @type {string}242 * @default243 */244 _FORCE_UPDATE_STATUS: 'fu_r',245 /**246 * _FORCE_UPDATE_STATUS_CODE constant247 * @constant248 * @memberof corbel.Services249 * @type {number}250 * @default251 */252 _FORCE_UPDATE_STATUS_CODE: 403,253 /**254 * _UNAUTHORIZED_MAX_RETRIES constant255 * @constant256 * @memberof corbel.Services257 * @type {number}258 * @default259 */260 _UNAUTHORIZED_MAX_RETRIES: 1,261 /**262 * _UNAUTHORIZED_NUM_RETRIES constant263 * @constant264 * @memberof corbel.Services265 * @type {string}266 * @default267 */268 _UNAUTHORIZED_NUM_RETRIES: 'un_r',269 /**270 * _UNAUTHORIZED_STATUS_CODE constant271 * @constant272 * @memberof corbel.Services273 * @type {number}274 * @default275 */276 _UNAUTHORIZED_STATUS_CODE: 401,277 /**278 * Extract a id from the location header of a requestXHR279 * @memberof corbel.Services280 * @param {Promise} responseObject response from a requestXHR281 * @return {String} id from the Location282 */283 getLocationId: function (responseObject) {284 var location = this._getLocationHeader(responseObject);285 return location ? location.substr(location.lastIndexOf('/') + 1) : undefined;286 },287 /**288 * Extracts the entire location header289 * @param {Promise} responseObject response from a requestXHR290 * @returns {String} location header content291 */292 getLocation: function (responseObject) {293 return this._getLocationHeader(responseObject);294 },295 /**296 * Extracts the location header297 * @param {Promise} responseObject response from a requestXHR298 * @returns {String} location header content299 * @private300 */301 _getLocationHeader: function (responseObject) {302 responseObject = responseObject || {};303 if (responseObject.xhr) {304 return responseObject.xhr.getResponseHeader('Location');305 } else if (responseObject.response && responseObject.response.headers.location) {306 return responseObject.response.headers.location;307 }308 },309 /**310 * @memberof corbel.Services311 * @param {mixed} response312 * @param {string} type313 * @return {midex}314 */315 addEmptyJson: function (response, type) {316 if (!response && type === 'json') {317 response = '{}';318 }319 return response;320 }321 });322 return Services;...
rides.js
Source:rides.js
1import {2 RIDES_FETCH_REQUEST,3 RIDES_FETCH_SUCCESS,4 RIDES_FETCH_FAILURE,5 RIDES_REFRESH_REQUEST,6 RIDES_REFRESH_SUCCESS,7 RIDES_REFRESH_FAILURE,8 RIDES_AS_PASSENGER_FETCH_REQUEST,9 RIDES_AS_PASSENGER_FETCH_SUCCESS,10 RIDES_AS_PASSENGER_FETCH_FAILURE,11 RIDES_AS_PASSENGER_REFRESH_REQUEST,12 RIDES_AS_PASSENGER_REFRESH_SUCCESS,13 RIDES_AS_PASSENGER_REFRESH_FAILURE,14 RIDES_AS_DRIVER_FETCH_REQUEST,15 RIDES_AS_DRIVER_FETCH_SUCCESS,16 RIDES_AS_DRIVER_FETCH_FAILURE,17 RIDES_AS_DRIVER_REFRESH_REQUEST,18 RIDES_AS_DRIVER_REFRESH_SUCCESS,19 RIDES_AS_DRIVER_REFRESH_FAILURE,20 RIDE_FILTER_UPDATE,21 RIDE_SEARCH_UPDATE,22 RIDE_AS_DRIVER_FILTER_UPDATE,23 RIDE_AS_PASSENGER_FILTER_UPDATE,24 RIDE_INITIALIZE,25 RIDE_FETCH_REQUEST,26 RIDE_FETCH_SUCCESS,27 RIDE_FETCH_FAILURE,28 RIDE_OPTIONS_FETCH_REQUEST,29 RIDE_OPTIONS_FETCH_SUCCESS,30 RIDE_OPTIONS_FETCH_FAILURE,31 RIDE_CREATE_REQUEST,32 RIDE_CREATE_SUCCESS,33 RIDE_CREATE_FAILURE,34 RIDE_UPDATE_REQUEST,35 RIDE_UPDATE_SUCCESS,36 RIDE_UPDATE_FAILURE,37 RIDE_SEARCH_CLEAR,38 RIDE_FILTER_CLEAR,39 RIDE_AS_DRIVER_FILTER_CLEAR,40 RIDE_AS_PASSENGER_FILTER_CLEAR,41 RIDES_SET_DEFAULT_PER,42 RIDES_AS_PASSENGER_SET_DEFAULT_PER,43 RIDES_AS_DRIVER_SET_DEFAULT_PER,44} from '../constants/action-types';45import { APIEndpoints } from '../constants/constants';46export function refreshRides(per = 20) {47 return (dispatch, getState) => {48 const { ridesFilters } = getState()49 const filters = ridesFilters.filters50 const search = ridesFilters.search51 return dispatch({52 types: [53 RIDES_REFRESH_REQUEST,54 RIDES_REFRESH_SUCCESS,55 RIDES_REFRESH_FAILURE56 ],57 payload: {58 request: {59 url: APIEndpoints.RIDES,60 params: {61 page: 1,62 per,63 filters,64 search,65 }66 }67 },68 })69 }70}71export function fetchRides(page = 1, per = 20) {72 return (dispatch, getState) => {73 const { ridesFilters } = getState()74 const filters = ridesFilters.filters75 const search = ridesFilters.search76 return dispatch({77 types: [78 RIDES_FETCH_REQUEST,79 RIDES_FETCH_SUCCESS,80 RIDES_FETCH_FAILURE81 ],82 payload: {83 request: {84 url: APIEndpoints.RIDES,85 params: {86 page,87 per,88 filters,89 search,90 }91 }92 }93 })94 }95}96export function refreshRidesAsPassenger(user_id, per = 20) {97 return (dispatch, getState) => {98 const { ridesAsPassengerFilters } = getState()99 const filters = ridesAsPassengerFilters.filters100 return dispatch({101 types: [102 RIDES_AS_PASSENGER_REFRESH_REQUEST,103 RIDES_AS_PASSENGER_REFRESH_SUCCESS,104 RIDES_AS_PASSENGER_REFRESH_FAILURE105 ],106 payload: {107 request: {108 url: `${APIEndpoints.RIDES}/as_passenger`,109 params: {110 page: 1,111 per,112 user_id,113 filters,114 }115 }116 }117 })118 }119}120export function fetchRidesAsPassenger(user_id, page = 1, per = 20) {121 return (dispatch, getState) => {122 const { ridesAsPassengerFilters } = getState()123 const filters = ridesAsPassengerFilters.filters124 return dispatch({125 types: [126 RIDES_AS_PASSENGER_FETCH_REQUEST,127 RIDES_AS_PASSENGER_FETCH_SUCCESS,128 RIDES_AS_PASSENGER_FETCH_FAILURE129 ],130 payload: {131 request: {132 url: `${APIEndpoints.RIDES}/as_passenger`,133 params: {134 page,135 per,136 user_id,137 filters,138 }139 }140 }141 })142 }143}144export function refreshRidesAsDriver(user_id, per = 20) {145 return (dispatch, getState) => {146 const { ridesAsDriverFilters } = getState()147 const filters = ridesAsDriverFilters.filters148 return dispatch({149 types: [150 RIDES_AS_DRIVER_REFRESH_REQUEST,151 RIDES_AS_DRIVER_REFRESH_SUCCESS,152 RIDES_AS_DRIVER_REFRESH_FAILURE153 ],154 payload: {155 request: {156 url: `${APIEndpoints.RIDES}/as_driver`,157 params: {158 page: 1,159 per,160 user_id,161 filters,162 }163 }164 }165 })166 }167}168export function fetchRidesAsDriver(user_id, page = 1, per = 20) {169 return (dispatch, getState) => {170 const { ridesAsDriverFilters } = getState()171 const filters = ridesAsDriverFilters.filters172 return dispatch({173 types: [174 RIDES_AS_DRIVER_FETCH_REQUEST,175 RIDES_AS_DRIVER_FETCH_SUCCESS,176 RIDES_AS_DRIVER_FETCH_FAILURE177 ],178 payload: {179 request: {180 url: `${APIEndpoints.RIDES}/as_driver`,181 params: {182 page,183 per,184 user_id,185 filters,186 }187 }188 }189 })190 }191}192export function fetchRide(rideId) {193 return {194 types: [195 RIDE_FETCH_REQUEST,196 RIDE_FETCH_SUCCESS,197 RIDE_FETCH_FAILURE198 ],199 payload: {200 request: {201 url: `${APIEndpoints.RIDES}/${rideId}`,202 }203 }204 }205}206export function createRide(body) {207 return {208 types: [209 RIDE_CREATE_REQUEST,210 RIDE_CREATE_SUCCESS,211 RIDE_CREATE_FAILURE212 ],213 payload: {214 request: {215 method: 'post',216 url: APIEndpoints.RIDES,217 data: body218 }219 }220 }221}222export function fetchRideOptions() {223 return {224 types: [225 RIDE_OPTIONS_FETCH_REQUEST,226 RIDE_OPTIONS_FETCH_SUCCESS,227 RIDE_OPTIONS_FETCH_FAILURE228 ],229 payload: {230 request: {231 url: `${APIEndpoints.RIDES}/options`,232 }233 }234 }235}236export function updateRide(body, rideId) {237 return {238 types: [239 RIDE_UPDATE_REQUEST,240 RIDE_UPDATE_SUCCESS,241 RIDE_UPDATE_FAILURE242 ],243 payload: {244 request: {245 method: 'put',246 url: `${APIEndpoints.RIDES}/${rideId}`,247 data: body248 }249 }250 }251}252export function updateRidesSearch(search = {}) {253 return {254 type: RIDE_SEARCH_UPDATE,255 search: search256 }257}258export function updateRidesFilters(filters = {}) {259 return {260 type: RIDE_FILTER_UPDATE,261 filters: filters262 }263}264export function clearRidesSearch() {265 return {266 type: RIDE_SEARCH_CLEAR,267 }268}269export function clearRidesFilters() {270 return {271 type: RIDE_FILTER_CLEAR,272 }273}274export function updateRidesAsDriverFilters(filters = {}) {275 return {276 type: RIDE_AS_DRIVER_FILTER_UPDATE,277 filters: filters278 }279}280export function clearRidesAsDriverFilters() {281 return {282 type: RIDE_AS_DRIVER_FILTER_CLEAR,283 }284}285export function updateRidesAsPassengerFilters(filters = {}) {286 return {287 type: RIDE_AS_PASSENGER_FILTER_UPDATE,288 filters: filters289 }290}291export function clearRidesAsPassengerFilters() {292 return {293 type: RIDE_AS_PASSENGER_FILTER_CLEAR,294 }295}296export function setDefaultRidesPer(per) {297 return {298 type: RIDES_SET_DEFAULT_PER,299 per: per,300 }301}302export function setDefaultRidesAsPassengerPer(per) {303 return {304 type: RIDES_AS_PASSENGER_SET_DEFAULT_PER,305 per: per,306 }307}308export function setDefaultRidesAsDriverPer(per) {309 return {310 type: RIDES_AS_DRIVER_SET_DEFAULT_PER,311 per: per,312 }313}314export function initializeRide(ride) {315 return {316 type: RIDE_INITIALIZE,317 item: ride,318 }...
watcher.js
Source:watcher.js
...7 };8 it('can get basic page activity', function() {9 this.timeout(20000);10 var driver = this.extensionDriver;11 return driver.get('https://google.com/').then(function() {return driver.refresh();12 }).then(function() {13 return new Promise(function(resolve, reject) {14 setTimeout(function() {15 driver.navigate('html/index.html#log')16 .then(function() {17 return driver.refresh();18 })19 .then(function() {20 return driver.click('.show.author');21 })22 .then(function() {23 return driver.execute(function() {24 return document.querySelectorAll('table tr.no-author').length;25 });26 }).then(function(length) {27 assert.equal(length, 1);28 }).then(resolve, reject);29 }, 3000);30 });31 })32 });33 it('can detect author information', function() {34 this.timeout(20000);35 var driver = this.extensionDriver;36 return driver.get('http://tbranyen.com/').then(function() {37 return new Promise(function(resolve, reject) {38 setTimeout(function() {39 driver.navigate('html/index.html#log')40 .then(function() {41 return driver.refresh();42 })43 .then(function() {44 return driver.wait(function() {45 return document.querySelectorAll('.show.author').length;46 })47 })48 .then(function() {49 return driver.click('.show.author');50 })51 .then(function() {52 return driver.execute(function() {53 return document.querySelectorAll('table tr.has-author').length;54 });55 }).then(function(length) {56 assert.equal(length, 1);57 }).then(resolve, reject);58 }, 1000);59 });60 });61 });62 it('will report correct time when page is visited for five seconds', function() {63 this.timeout(40000);64 var driver = this.extensionDriver;65 var delay = Date.now() + 5000;66 return driver.get('http://reddit.com/').then(function() {return driver.refresh();67 }).then(function() {68 return new Promise(function(resolve) {69 setTimeout(resolve, 5000);70 });71 })72 .then(function() {73 return driver.navigate('html/index.html#log')74 })75 .then(function() {76 return driver.refresh();77 })78 .then(function() {79 return driver.click('.show.author');80 })81 .then(function() {82 return driver.wait(function() {83 var tr = document.querySelector('[data-host="reddit.com"]');84 if (!tr) { return; }85 return tr.querySelector('.timeSpent').innerHTML;86 });87 })88 .then(function() {89 return driver.execute(function() {90 var tr = document.querySelector('[data-host="reddit.com"]');...
rides-as-driver.js
Source:rides-as-driver.js
1import {2 RIDES_AS_DRIVER_FETCH_REQUEST,3 RIDES_AS_DRIVER_FETCH_SUCCESS,4 RIDES_AS_DRIVER_REFRESH_REQUEST,5 RIDES_AS_DRIVER_REFRESH_SUCCESS,6 RIDES_AS_DRIVER_SET_DEFAULT_PER,7 LOGOUT_SUCCESS,8} from '../constants/action-types';9import { unionWith, sortWith, ascend, prop } from 'ramda';10const comparator = function(a1, a2) { return a1.id === a2.id; };11const startDateSort = sortWith([12 ascend(prop('start_date')),13]);14export const initialState = {15 isStarted: false,16 isFetching: false,17 items: [],18 pagination: {},19};20export function ridesAsDriver(state = initialState, action) {21 let items, pagination22 switch (action.type) {23 case LOGOUT_SUCCESS:24 return {25 ...initialState26 };27 case RIDES_AS_DRIVER_FETCH_REQUEST:28 console.log('RIDES_AS_DRIVER_FETCH_REQUEST');29 return {30 ...state,31 isStarted: true,32 isFetching: true,33 };34 case RIDES_AS_DRIVER_FETCH_SUCCESS:35 console.log('RIDES_AS_DRIVER_FETCH_SUCCESS');36 items = action.payload.data.items37 pagination = action.payload.data.meta38 return {39 ...state,40 isFetching: false,41 items: unionWith(42 comparator,43 items,44 state.items,45 ),46 pagination: pagination,47 };48 case RIDES_AS_DRIVER_REFRESH_REQUEST:49 console.log('RIDES_AS_DRIVER_REFRESH_REQUEST');50 return {51 ...state,52 isStarted: true,53 isFetching: true,54 items: [],55 };56 case RIDES_AS_DRIVER_REFRESH_SUCCESS:57 console.log('RIDES_AS_DRIVER_REFRESH_SUCCESS');58 items = action.payload.data.items59 pagination = action.payload.data.meta60 const currentPage = pagination.per / state.defaultPer61 const totalPages = Math.ceil(pagination.total_count / state.defaultPer)62 return {63 ...state,64 isFetching: false,65 items: items,66 pagination: {67 ...pagination,68 current_page: currentPage,69 next_page: currentPage + 1,70 prev_page: currentPage - 1,71 total_pages: totalPages,72 }73 };74 case RIDES_AS_DRIVER_SET_DEFAULT_PER:75 console.log('RIDES_AS_DRIVER_SET_DEFAULT_PER');76 return {77 ...state,78 defaultPer: action.per,79 };80 default:81 return state;82 }...
CabDriverController.js
Source:CabDriverController.js
1angular.module('myApp').controller('CabDriverController', function($scope, $http) {2 //driver part starts3 var DriverRefresh = function () {4 $http.get('/driv/getDriv').success(function (response) {5 console.log('READ IS SUCCESSFUL');6 $scope.DriverData = response;7 $scope.driv = "";8 });9 };10 DriverRefresh();11 $scope.addDriv = function () {12 13 $http.post('/driv/addDriv', $scope.driv).success(function (response) {14 console.log(response);15 console.log("CREATE IS SUCCESSFUL");16 17 });18 DriverRefresh(); 19 20 21 22 };23 $scope.removeDriv = function (driv) {24 //console.log(id);25 $http.delete('/driv/deleteDriv/' + driv._id).success(function (response) {26 console.log(response);27 console.log('DELETED SUCCESSFULLY');28 29 });30 DriverRefresh();31 };32 $scope.editDriv = function (driv) {33 $http.get('/driv/getDriv/' + driv._id).success(function (response) {34 $scope.driv = response[0];35 });36 }; 37 ...
secret.js
Source:secret.js
1const {2 ADMIN_ACCESS_SECRET,3 MANAGER_ACCESS_SECRET,4 SUPERVISOR_ACCESS_SECRET,5 DRIVER_ACCESS_SECRET,6 ADMIN_REFRESH_SECRET,7 MANAGER_REFRESH_SECRET,8 SUPERVISOR_REFRESH_SECRET,9 DRIVER_REFRESH_SECRET,10} = process.env;11// Set access token secret key depending on role provided12const setAccessSecret = (role) => {13 let secret;14 switch (role) {15 case 'Admin':16 secret = ADMIN_ACCESS_SECRET;17 break;18 case 'Manager':19 secret = MANAGER_ACCESS_SECRET;20 break;21 case 'Supervisor':22 secret = SUPERVISOR_ACCESS_SECRET;23 break;24 case 'Driver':25 secret = DRIVER_ACCESS_SECRET;26 break;27 default:28 secret = DRIVER_ACCESS_SECRET;29 break;30 }31 return secret;32};33// Set refresh token secret key depending on role provided34const setRefreshSecret = (role) => {35 let secret;36 switch (role) {37 case 'Admin':38 secret = ADMIN_REFRESH_SECRET;39 break;40 case 'Manager':41 secret = MANAGER_REFRESH_SECRET;42 break;43 case 'Supervisor':44 secret = SUPERVISOR_REFRESH_SECRET;45 break;46 case 'Driver':47 secret = DRIVER_REFRESH_SECRET;48 break;49 default:50 secret = DRIVER_REFRESH_SECRET;51 break;52 }53 return secret;54};55module.exports = {56 setAccessSecret,57 setRefreshSecret,...
driver.socket.js
Source:driver.socket.js
1'use strict';2const events = require('events');3const eventEmitter = new events.EventEmitter();4const sockets = [];5eventEmitter.on('drivers:refresh', function (drivers) {6 sockets.every(function (socket) {7 socket.emit('drivers:refresh', drivers);8 });9});10eventEmitter.on('driver:refresh', function (driver) {11 sockets.every(function (socket) {12 socket.emit('driver:refresh', driver);13 });14});15function unRegister(socket) {16 let idx = sockets.indexOf(socket);17 if (idx > -1) {18 sockets.splice(idx, 1);19 }20}21exports.register = function (socket) {22 sockets.push(socket);23 socket.on('disconnect', function () {24 unRegister(socket);25 });26};27exports.driversRefresh = function (drivers) {28 eventEmitter.emit('drivers:refresh', drivers);29};30exports.driverRefresh = function (driver) {31 eventEmitter.emit('driver:refresh', driver);...
driver.controller.js
Source:driver.controller.js
1'use strict';2const socket = require('./driver.socket');3exports.driversRefresh = function (req, res) {4 socket.driversRefresh(req.body);5 return res.json(200, {message: 'Socket has been synced'});6};7exports.driverRefresh = function (req, res) {8 socket.driverRefresh(req.body);9 return res.json(200, {message: 'Socket has been synced'});...
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('safari')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.refresh();10driver.quit();11from appium import webdriver12from selenium.webdriver.common.by import By13from selenium.webdriver.support.ui import WebDriverWait14from selenium.webdriver.support import expected_conditions as EC15caps = {}16element = driver.find_element_by_name("q")17element.send_keys("Appium")18element.submit()19WebDriverWait(driver, 10).until(EC.title_contains("Appium"))20driver.refresh()21driver.quit()22element = driver.find_element(:name, 'q')23element.send_keys("Appium")24element.submit()25wait = Selenium::WebDriver::Wait.new(:timeout => 10)26wait.until { driver.title.downcase.start_with? "appium" }27using System;28using System.Collections.Generic;29using System.Linq;30using System.Text;31using System.Threading.Tasks;32using OpenQA.Selenium;
Using AI Code Generation
1const wdio = require('webdriverio');2const assert = require('assert');3const opts = {4 capabilities: {5 }6};7(async function main() {8 try {9 const client = await wdio.remote(opts);10 await client.pause(5000);11 await client.refresh();12 } catch (err) {13 console.log(err);14 }15})();16[HTTP] {}17[debug] [MJSONWP] Responding to client with driver.refresh() result: null18I am using XCUITest driver to automate my iOS app. I want to use driver.refresh() method to refresh the page. But when I use it, it does nothing. Can anyone help me with this?19const wdio = require('webdriverio');
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6const PORT = 4723;
Using AI Code Generation
1const wdio = require('webdriverio');2const assert = require('assert');3const opts = {4 capabilities: {5 }6};7(async function () {8 const client = await wdio.remote(opts);9 await client.pause(2000);10 await client.refresh();11 await client.pause(2000);12 await client.deleteSession();13})();
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6const assert = chai.assert;7const PORT = 4723;8const HOST = 'localhost';9const defaultCaps = {10};11const driver = wd.promiseChainRemote(HOST, PORT);12describe('test', function() {13 this.timeout(600000);14 before(async () => {15 await driver.init(defaultCaps);16 });17 after(async () => {18 await driver.quit();19 });20 it('should refresh the page', async () => {21 await driver.refresh();22 });23});24{25 "scripts": {26 },27 "dependencies": {28 }29}
Using AI Code Generation
1const wd = require('wd');2const path = require('path');3const assert = require('assert');4const { exec } = require('child_process');5const chai = require('chai');6const chaiAsPromised = require('chai-as-promised');7chai.use(chaiAsPromised);8const { serverConfig, desiredCaps } = require('./config');9const driver = wd.promiseChainRemote(serverConfig);10describe('Test Refreshing', function () {11 this.timeout(300000);12 before(async () => {13 await driver.init(desiredCaps);14 });15 after(async () => {16 await driver.quit();17 });18 it('should refresh the page', async () => {19 await driver.refresh();20 });21});22const serverConfig = {23};24const desiredCaps = {25};26module.exports = {27};
Using AI Code Generation
1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 }5};6async function main() {7 let client = await wdio.remote(opts);8 await client.pause(1000);9 await client.refresh();10 await client.pause(1000);11 await client.deleteSession();12}13main();14from appium import webdriver15caps = {}16driver.implicitly_wait(1)17driver.refresh()18driver.implicitly_wait(1)19driver.quit()20import io.appium.java_client.AppiumDriver;21import io.appium.java_client.ios.IOSDriver;22import org.openqa.selenium.remote.DesiredCapabilities;23import java.net.MalformedURLException;24import java.net.URL;25public class Test {26 public static void main(String[] args) throws MalformedURLException {27 DesiredCapabilities capabilities = new DesiredCapabilities();28 capabilities.setCapability("platformName", "iOS");29 capabilities.setCapability("platformVersion", "12.1");30 capabilities.setCapability("deviceName", "iPhone X");31 capabilities.setCapability("app", "com.apple.mobilesafari");32 capabilities.setCapability("automationName", "XCUITest");33 capabilities.setCapability("bundleId", "com.apple.mobilesafari");34 capabilities.setCapability("noReset", true);
Using AI Code Generation
1const { remote } = require('webdriverio');2async function main () {3 const browser = await remote({4 capabilities: {5 }6 });7 await browser.pause(5000);8 await browser.refresh();9 await browser.pause(5000);10 await browser.deleteSession();11}12main();
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var username = process.env.SAUCE_USERNAME;4var accessKey = process.env.SAUCE_ACCESS_KEY;5var desiredCaps = {6};7var driver = wd.promiseChainRemote('ondemand.saucelabs.com', 80, username, accessKey);8driver.init(desiredCaps)9 .then(function () {10 })11 .then(function () {12 return driver.refresh();13 })14 .then(function () {15 return driver.title();16 })17 .then(function (title) {18 assert.equal(title, 'Google');19 })20 .fin(function () { return driver.quit(); })21 .done();22JavascriptExecutor js = (JavascriptExecutor) driver;23HashMap<String, String> scrollObject = new HashMap<String, String>();24scrollObject.put("direction", "down");25js.executeScript("mobile: scroll", scrollObject);26driver.context(driver.getContextHandles().toArray()[1].toString());
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!!