Skip to content

Commit

Permalink
fix: viewport (#119)
Browse files Browse the repository at this point in the history
* fix: viewport
  • Loading branch information
yihuineng authored Oct 12, 2023
1 parent d260eb2 commit 8a10dc2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
14 changes: 9 additions & 5 deletions lib/helper/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const domEventLibSource = fs.readFileSync(domEventLib, 'utf8');

const cwd = process.cwd();
const reporterDir = process.env.MACACA_REPORTER_DIR || cwd;
const reportspath = path.join(reporterDir, 'reports');
const reportsPath = path.join(reporterDir, 'reports');

const safeQuote = string => JSON.stringify(String(string));

Expand All @@ -29,8 +29,12 @@ module.exports = wd => {
platformName: 'playwright',
browserName: 'chromium',
deviceScaleFactor: 2,
viewport: {
width: options.width,
height: options.height,
},
...options,
}).setWindowSize(options.width, options.height);
});
});

/**
Expand Down Expand Up @@ -77,11 +81,11 @@ module.exports = wd => {
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('saveScreenshots', function(context, params) {
const filepath = path.join(reportspath, 'screenshots', `${uuid()}.png`);
const filepath = path.join(reportsPath, 'screenshots', `${uuid()}.png`);
mkdir(path.dirname(filepath));

return this.saveScreenshot(filepath, params).then(() => {
appendToContext(context, `${path.relative(reportspath, filepath)}`);
appendToContext(context, `${path.relative(reportsPath, filepath)}`);
});
});

Expand All @@ -95,7 +99,7 @@ module.exports = wd => {
wd.addPromiseChainMethod('saveVideos', function(context, params = {}) {
params.video = true;
return this.saveScreenshot(null, params).then(filepath => {
appendToContext(context, `${path.relative(reportspath, filepath)}`);
appendToContext(context, `${path.relative(reportsPath, filepath)}`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaca-wd",
"version": "4.3.1",
"version": "4.3.2",
"description": "Macaca webdirver API for Node.js",
"keywords": [
"macaca",
Expand Down
26 changes: 0 additions & 26 deletions test/utility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,6 @@ describe('test/utility.test.js', function() {
});
});

/**
* https://macacajs.github.io/macaca-wd/#initWindow
*/
describe('initWindow', async () => {
it('should work', async () => {
await driver.initWindow({
width: 800,
height: 600,
});
assert.equal(
server.ctx.url,
'/wd/hub/session/sessionId/window/current/size'
);
assert.equal(server.ctx.method, 'POST');
assert.deepEqual(server.ctx.request.body, {
width: 800,
height: 600,
});
assert.deepEqual(server.ctx.response.body, {
sessionId: 'sessionId',
status: 0,
value: '',
});
});
});

/**
* https://macacajs.github.io/macaca-wd/#openReporter
*/
Expand Down
48 changes: 36 additions & 12 deletions test/window.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ describe('test/window.test.js', function() {
server.stop();
});


/**
* https://macacajs.github.io/macaca-wd/#close
*/
* https://macacajs.github.io/macaca-wd/#close
*/
describe('close', async () => {
it('should work', async () => {
await driver.close();
Expand All @@ -47,8 +48,8 @@ describe('test/window.test.js', function() {
});

/**
* https://macacajs.github.io/macaca-wd/#close
*/
* https://macacajs.github.io/macaca-wd/#getWindowSize
*/
describe('getWindowSize', async () => {
it('should work', async () => {
await driver.getWindowSize();
Expand All @@ -64,8 +65,8 @@ describe('test/window.test.js', function() {
});

/**
* https://macacajs.github.io/macaca-wd/#setWindowSize
*/
* https://macacajs.github.io/macaca-wd/#setWindowSize
*/
describe('setWindowSize', async () => {
it('should work', async () => {
await driver.setWindowSize(800, 600);
Expand All @@ -84,8 +85,8 @@ describe('test/window.test.js', function() {
});

/**
* https://macacajs.github.io/macaca-wd/#window
*/
* https://macacajs.github.io/macaca-wd/#window
*/
describe('window', async () => {
it('should work', async () => {
await driver.window();
Expand All @@ -101,8 +102,8 @@ describe('test/window.test.js', function() {
});

/**
* https://macacajs.github.io/macaca-wd/#windowHandle
*/
* https://macacajs.github.io/macaca-wd/#windowHandle
*/
describe('windowHandle', async () => {
it('should work', async () => {
await driver.windowHandle();
Expand All @@ -118,8 +119,8 @@ describe('test/window.test.js', function() {
});

/**
* https://macacajs.github.io/macaca-wd/#windowHandles
*/
* https://macacajs.github.io/macaca-wd/#windowHandles
*/
describe('windowHandles', async () => {
it('should work', async () => {
await driver.windowHandles();
Expand All @@ -133,5 +134,28 @@ describe('test/window.test.js', function() {
});
});
});


/**
* https://macacajs.github.io/macaca-wd/#initWindow
*/
describe('initWindow', async () => {
it('should work', async () => {
await driver.initWindow({
width: 800,
height: 600,
});
assert.equal(
server.ctx.url,
'/wd/hub/session'
);
assert.equal(server.ctx.method, 'POST');
assert.deepEqual(server.ctx.response.body, {
sessionId: 'sessionId',
status: 0,
value: '',
});
});
});
});

0 comments on commit 8a10dc2

Please sign in to comment.