diff --git a/Scripts/fetch-prebuilt-wda.js b/Scripts/fetch-prebuilt-wda.js index f616c8a85..82673188f 100644 --- a/Scripts/fetch-prebuilt-wda.js +++ b/Scripts/fetch-prebuilt-wda.js @@ -1,10 +1,8 @@ const path = require('path'); -const request = require('request-promise'); -const requestCallback = require('request'); +const axios = require('axios'); const { asyncify } = require('asyncbox'); -const { logger, fs, mkdirp } = require('appium-support'); +const { logger, fs, mkdirp, net } = require('appium-support'); const _ = require('lodash'); -const _fs = require('fs'); const B = require('bluebird'); const log = logger.getLogger('WDA'); @@ -16,14 +14,15 @@ async function fetchPrebuiltWebDriverAgentAssets () { log.info(`Getting WDA release ${downloadUrl}`); let releases; try { - releases = await request.get(downloadUrl, { + releases = (await axios({ + url: downloadUrl, headers: { 'user-agent': 'appium', + 'accept': 'application/json, */*', }, - json: true, - }); + })).data; } catch (e) { - throw new Error(`Could not fetch endpoint '${downloadUrl}. Reason: ${e.message}'`); + throw new Error(`Could not fetch endpoint ${downloadUrl}. Reason: ${e.message}`); } const webdriveragentsDir = path.resolve(__dirname, '..', 'prebuilt-agents'); @@ -34,19 +33,7 @@ async function fetchPrebuiltWebDriverAgentAssets () { // Define a method that does a streaming download of an asset async function downloadAgent (url, targetPath) { try { - // don't use request-promise here, we need streams - return await new B((resolve, reject) => { - requestCallback(url) - .on('error', reject) // handle real errors, like connection errors - .on('response', (res) => { - // handle responses that fail, like 404s - if (res.statusCode >= 400) { - return reject(new Error(`${res.statusCode} - ${res.statusMessage}`)); - } - }) - .pipe(_fs.createWriteStream(targetPath)) - .on('close', resolve); - }); + await net.downloadFile(url, targetPath); } catch (err) { throw new Error(`Problem downloading webdriveragent from url ${url}: ${err.message}`); } diff --git a/package.json b/package.json index deab37049..59b7c2600 100644 --- a/package.json +++ b/package.json @@ -61,14 +61,13 @@ "@babel/runtime": "^7.0.0", "appium-base-driver": "^5.0.2", "appium-ios-simulator": "^3.14.0", - "appium-support": "^2.37.0", + "appium-support": "^2.46.0", "async-lock": "^1.0.0", "asyncbox": "^2.5.3", + "axios": "^0.19.2", "bluebird": "^3.5.5", "lodash": "^4.17.11", "node-simctl": "^6.0.2", - "request": "^2.79.0", - "request-promise": "^4.1.1", "source-map-support": "^0.5.12", "stream-equal": "^1.1.1", "teen_process": "^1.14.1" diff --git a/test/functional/helpers/session.js b/test/functional/helpers/session.js index 612656ce3..49cd1131c 100644 --- a/test/functional/helpers/session.js +++ b/test/functional/helpers/session.js @@ -1,8 +1,8 @@ import wd from 'wd'; -import request from 'request-promise'; import { startServer } from '../../..'; import { util } from 'appium-support'; import _ from 'lodash'; +import axios from 'axios'; const {SAUCE_RDC, SAUCE_EMUSIM, CLOUD} = process.env; @@ -96,7 +96,7 @@ function getServer () { async function initWDA (caps) { // first, see if this is necessary try { - await request.get({url: `http://${HOST}:${WDA_PORT}/status`}); + await axios({url: `http://${HOST}:${WDA_PORT}/status`, timeout: 5000}); } catch (err) { // easiest way to initialize WDA is to go through a test startup // otherwise every change to the system would require a change here diff --git a/test/functional/webdriveragent-e2e-specs.js b/test/functional/webdriveragent-e2e-specs.js index a8f020078..99ae18e4c 100644 --- a/test/functional/webdriveragent-e2e-specs.js +++ b/test/functional/webdriveragent-e2e-specs.js @@ -4,11 +4,11 @@ import Simctl from 'node-simctl'; import { getVersion } from 'appium-xcode'; import { getSimulator } from 'appium-ios-simulator'; import { killAllSimulators, shutdownSimulator } from './helpers/simulator'; -import request from 'request-promise'; import { SubProcess } from 'teen_process'; import { PLATFORM_VERSION, DEVICE_NAME } from './desired'; import { retryInterval } from 'asyncbox'; import { WebDriverAgent } from '../..'; +import axios from 'axios'; const SIM_DEVICE_NAME = 'webDriverAgentTest'; @@ -85,7 +85,7 @@ describe('WebDriverAgent', function () { const agent = new WebDriverAgent(xcodeVersion, getStartOpts(device)); await agent.launch('sessionId'); - await request(testUrl).should.be.eventually.rejectedWith(/unknown command/); + await axios({url: testUrl}).should.be.eventually.rejected; await agent.quit(); });