Skip to content

Commit

Permalink
more transformations
Browse files Browse the repository at this point in the history
fixes #5
  • Loading branch information
christian-bromann committed Apr 15, 2021
1 parent b2aa41f commit 2b3af85
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
9 changes: 7 additions & 2 deletions protractor/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ exports.ELEMENT_COMMANDS = [
'isEnabled',
'isSelected',
'isDisplayed',
'takeScreenshot'
'takeScreenshot',
'getPosition',
'setSize'
]
exports.COMMANDS_TO_REMOVE = ['allowAnimations']
exports.UNSUPPORTED_COMMANDS = [
Expand Down Expand Up @@ -157,7 +159,10 @@ exports.REPLACE_TIMEOUTS = {
exports.REPLACE_WINDOW_COMMANDS = {
fullscreen: 'fullscreenWindow',
maximize: 'maximizeWindow',
minimize: 'minimizeWindow'
minimize: 'minimizeWindow',
getPosition: 'getWindowRect',
setSize: 'setWindowRect',
deleteAllCookies: 'deleteCookies'
}

exports.UNSUPPORTED_CONFIG_OPTION_ERROR = '' +
Expand Down
22 changes: 20 additions & 2 deletions protractor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,12 @@ module.exports = function transformer(file, api) {
*/
root.find(j.CallExpression)
.filter((path) => (
path.value.callee &&
path.value.callee.property &&
['get', ...Object.keys(REPLACE_TIMEOUTS), ...Object.keys(REPLACE_WINDOW_COMMANDS)].includes(path.value.callee.property.name) &&
path.value.callee.object &&
path.value.callee.object.callee &&
path.value.callee.object.callee.property &&
['logs', 'timeouts', 'window'].includes(path.value.callee.object.callee.property.name)
['logs', 'timeouts', 'window', 'manage'].includes(path.value.callee.object.callee.property.name)
))
.replaceWith((path) => {
const scope = path.value.callee.object.callee.property.name
Expand Down Expand Up @@ -433,6 +432,25 @@ module.exports = function transformer(file, api) {
]
)
} else if (scope === 'window') {
const args = []

if (command === 'setSize') {
args.push(
j.literal(0),
j.literal(0),
path.value.arguments[0],
path.value.arguments[1]
)
}

return j.callExpression(
j.memberExpression(
j.identifier('browser'),
j.identifier(REPLACE_WINDOW_COMMANDS[command])
),
args
)
} else if (scope === 'manage') {
return j.callExpression(
j.memberExpression(
j.identifier('browser'),
Expand Down
4 changes: 4 additions & 0 deletions protractor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ function replaceCommands (prtrctrCommand) {
return 'waitUntil'
case 'close':
return 'closeWindow'
case 'getPosition':
return 'getWindowRect'
case 'setSize':
return 'setWindowRect'
case 'restart':
case 'restartSync':
return 'reloadSession'
Expand Down
6 changes: 6 additions & 0 deletions test/__fixtures__/protractor/source/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ browser.executeScript(function() {console.error('error from test'); });
await browser.getProcessedConfig().then((config) => {
console.log(config);
})
const windowLocation = await browser.manage().window().getPosition()
})

browser.switchTo().frame('composeWidget');
Expand All @@ -65,3 +66,8 @@ browser.manage().logs().get(logging.Type.BROWSER);

var row = element.all(by.repeater('dataRow in displayedCollection')).get(1);
var cells = row.all(by.tagName('td'));

var width = 800;
var height = 600;
browser.driver.manage().window().setSize(width, height);
browser.manage().deleteAllCookies();
6 changes: 6 additions & 0 deletions test/__fixtures__/protractor/transformed/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ browser.execute(function() {console.error('error from test'); });
const config = await browser.config
let config = await browser.config;
console.log(config);
const windowLocation = await browser.getWindowRect()
})

browser.switchToFrame('composeWidget');
Expand Down Expand Up @@ -64,3 +65,8 @@ browser.getLogs("browser");

var row = $$("*[ng-repeat=\"dataRow in displayedCollection\"]")[1];
var cells = row.$$('td');

var width = 800;
var height = 600;
browser.setWindowRect(0, 0, width, height);
browser.deleteCookies();

0 comments on commit 2b3af85

Please sign in to comment.