From 876a4b97a8897d514f5a17e9db8d450a0af7f8ed Mon Sep 17 00:00:00 2001 From: zivyangll Date: Thu, 16 Jul 2020 16:03:12 +0800 Subject: [PATCH 1/4] feat: support post with screenshot --- lib/helper.js | 4 ++-- package.json | 2 +- wd/lib/commands.js | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/helper.js b/lib/helper.js index 603959f4..4a9227a2 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -181,13 +181,13 @@ const extendsMixIn = wd => { * @type utility * @returns {Promise.} */ - wd.addPromiseChainMethod('saveScreenshots', function(context) { + wd.addPromiseChainMethod('saveScreenshots', function(context, params) { const reporterDir = process.env.MACACA_REPORTER_DIR || cwd; const reportspath = path.join(reporterDir, 'reports'); const filepath = path.join(reportspath, 'screenshots', `${uuid()}.png`); mkdir(path.dirname(filepath)); - return this.saveScreenshot(filepath).then(() => { + return this.saveScreenshot(filepath, params).then(() => { appendToContext(context, `${path.relative(reportspath, filepath)}`); }); }); diff --git a/package.json b/package.json index cbac7ff0..1d17daf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "macaca-wd", - "version": "3.3.1", + "version": "3.3.2", "description": "Macaca wd client", "keywords": [ "macaca", diff --git a/wd/lib/commands.js b/wd/lib/commands.js index 21113750..f31c8109 100644 --- a/wd/lib/commands.js +++ b/wd/lib/commands.js @@ -1102,10 +1102,12 @@ commands.waitForVisible = function(using, value, timeout, pollFreq) { */ commands.takeScreenshot = function() { var cb = findCallback(arguments); + var params = arguments[0]; this._jsonWireCall({ - method: 'GET' + method: 'POST' , relPath: '/screenshot' , cb: callbackWithData(cb, this) + , data: params }); }; @@ -1120,6 +1122,7 @@ commands.saveScreenshot = function() { var cb = findCallback(arguments); var fargs = utils.varargs(arguments); var _path = fargs.all[0]; + var _params = fargs.all[1]; var dir = process.env.CUSTOM_DIR || ''; function buildFilePath(_path, cb) { @@ -1141,7 +1144,7 @@ commands.saveScreenshot = function() { } buildFilePath(_path, function(err, filePath) { - commands.takeScreenshot.apply(_this, [function(err, base64Data) { + commands.takeScreenshot.apply(_this, [_params, function(err, base64Data) { if(err) { return cb(err); } require("fs").writeFile(filePath, base64Data, 'base64', function(err) { if(err) { return cb(err); } From 9d6aa33d029233962386d072e63c1c9890e0aeff Mon Sep 17 00:00:00 2001 From: zivyangll Date: Thu, 16 Jul 2020 16:03:30 +0800 Subject: [PATCH 2/4] fix: lint --- lib/web/react-router-helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/react-router-helper.js b/lib/web/react-router-helper.js index 955f0c18..bd1d9934 100644 --- a/lib/web/react-router-helper.js +++ b/lib/web/react-router-helper.js @@ -74,7 +74,7 @@ exports.getRouter = (data, options = {}) => { isMatched = matchPath(pathname, currentRoute) || isMatched; } }, { - extname: '.js', + extname: '.js' }); }); currentRoute.path = currentRoute._path || currentRoute.path; From bb64a0b8aec2d775ff5056ab070cb25b91073d75 Mon Sep 17 00:00:00 2001 From: zivyangll Date: Thu, 16 Jul 2020 16:20:11 +0800 Subject: [PATCH 3/4] fix: test --- test/screenshot.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/screenshot.test.js b/test/screenshot.test.js index 045c41ed..762eb2c7 100644 --- a/test/screenshot.test.js +++ b/test/screenshot.test.js @@ -34,7 +34,7 @@ describe('test/screenshot.test.js', function() { describe('saveScreenshot', async () => { it('should work', async () => { await driver.saveScreenshot(); - assert.equal(server.ctx.method, 'GET'); + assert.equal(server.ctx.method, 'POST'); assert.equal(server.ctx.url, '/wd/hub/session/screenshot'); assert.deepEqual(server.ctx.request.body, {}); assert.deepEqual(server.ctx.response.body, { @@ -50,8 +50,10 @@ describe('test/screenshot.test.js', function() { */ describe('takeScreenshot', async () => { it('should work', async () => { - await driver.takeScreenshot(); - assert.equal(server.ctx.method, 'GET'); + await driver.takeScreenshot('', { + fullPage: true, + }); + assert.equal(server.ctx.method, 'POST'); assert.equal(server.ctx.url, '/wd/hub/session/screenshot'); assert.deepEqual(server.ctx.request.body, {}); assert.deepEqual(server.ctx.response.body, { From 434720f65554f21463e0a67103885fb724e1ea9d Mon Sep 17 00:00:00 2001 From: zivyangll Date: Thu, 16 Jul 2020 17:49:53 +0800 Subject: [PATCH 4/4] feat: use get with screenshot --- test/screenshot.test.js | 8 +++----- wd/lib/commands.js | 5 ++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/screenshot.test.js b/test/screenshot.test.js index 762eb2c7..045c41ed 100644 --- a/test/screenshot.test.js +++ b/test/screenshot.test.js @@ -34,7 +34,7 @@ describe('test/screenshot.test.js', function() { describe('saveScreenshot', async () => { it('should work', async () => { await driver.saveScreenshot(); - assert.equal(server.ctx.method, 'POST'); + assert.equal(server.ctx.method, 'GET'); assert.equal(server.ctx.url, '/wd/hub/session/screenshot'); assert.deepEqual(server.ctx.request.body, {}); assert.deepEqual(server.ctx.response.body, { @@ -50,10 +50,8 @@ describe('test/screenshot.test.js', function() { */ describe('takeScreenshot', async () => { it('should work', async () => { - await driver.takeScreenshot('', { - fullPage: true, - }); - assert.equal(server.ctx.method, 'POST'); + await driver.takeScreenshot(); + assert.equal(server.ctx.method, 'GET'); assert.equal(server.ctx.url, '/wd/hub/session/screenshot'); assert.deepEqual(server.ctx.request.body, {}); assert.deepEqual(server.ctx.response.body, { diff --git a/wd/lib/commands.js b/wd/lib/commands.js index f31c8109..065ff017 100644 --- a/wd/lib/commands.js +++ b/wd/lib/commands.js @@ -1104,10 +1104,9 @@ commands.takeScreenshot = function() { var cb = findCallback(arguments); var params = arguments[0]; this._jsonWireCall({ - method: 'POST' - , relPath: '/screenshot' + method: 'GET' + , relPath: `/screenshot${url.format({query: params})}` , cb: callbackWithData(cb, this) - , data: params }); };