Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Control flow fork #198

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/selenium-ide/src/content/selenium-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,47 @@ Selenium.prototype.doVerifyElementPresent = function(locator) {
}
};

Selenium.prototype.doIf = function(string) {
return eval(string);
};

Selenium.prototype.doWhile = function(string) {
return eval(string);
};

Selenium.prototype.doTimes = function(counter) {
// return to it when 'eval' and stored variables properly figured out
return true;
};

Selenium.prototype.doElseIf = function(string) {
return eval(string);
};

Selenium.prototype.doRepeatIf = function(string) {
return eval(string);
};

Selenium.prototype.doElse = function() {
return true;
};

Selenium.prototype.doEnd = function() {
return true;
};

Selenium.prototype.doDo = function() {
return true;
};

Selenium.prototype.doContinue = function() {
return true;
};

Selenium.prototype.doBreak = function() {
return true;
};

Selenium.prototype.doVerifyElementNotPresent = function(locator) {
try {
this.browserbot.findElement(locator);
Expand Down
3 changes: 3 additions & 0 deletions packages/selenium-ide/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
"background":
{
"scripts": ["assets/background.js"]
},
"sandbox": {
"pages": ["assets/sandbox.html"]
}
}
65 changes: 54 additions & 11 deletions packages/selenium-ide/src/neo/IO/SideeX/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import PlaybackState, { PlaybackStates } from "../../stores/view/PlaybackState";
import UiState from "../../stores/view/UiState";
import ExtCommand, { isExtCommand } from "./ext-command";
import { xlateArgument } from "./formatCommand";
import PlaybackTree from "./playbackTree";
import SandboxCommand from "./sandboxCommand";

export const extCommand = new ExtCommand();
const sandboxCommand = new SandboxCommand();
// In order to not break the separation of the execution loop from the state of the playback
// I will set doSetSpeed here so that extCommand will not be aware of the state
extCommand.doSetSpeed = (speed) => {
Expand All @@ -37,6 +40,7 @@ let ignoreBreakpoint = false;

function play(currUrl) {
baseUrl = currUrl;
PlaybackTree.processCommands(PlaybackState.runningQueue);
prepareToPlay()
.then(executionLoop)
.then(finishPlaying)
Expand All @@ -51,7 +55,9 @@ function playAfterConnectionFailed() {
}

function executionLoop() {
(PlaybackState.currentPlayingIndex < 0) ? PlaybackState.setPlayingIndex(0) : PlaybackState.setPlayingIndex(PlaybackState.currentPlayingIndex + 1);
if (PlaybackState.currentPlayingIndex < 0) {
PlaybackState.setPlayingIndex(0);
}
// reached the end
if (PlaybackState.currentPlayingIndex >= PlaybackState.runningQueue.length && PlaybackState.isPlaying) return false;
const { id, command, target, value, isBreakpoint } = PlaybackState.runningQueue[PlaybackState.currentPlayingIndex];
Expand All @@ -68,11 +74,14 @@ function executionLoop() {
(extCommand["do" + upperCase](parsedTarget, value))
.then(() => {
PlaybackState.setCommandState(id, PlaybackStates.Passed);
}).then(executionLoop)
return doControlFlow(true);
}).then(doDelay).then(executionLoop)
));
} else if (isImplicitWait(command)) {
notifyWaitDeprecation(command);
return executionLoop();
return doControlFlow(true)
.then(doDelay)
.then(executionLoop);
} else {
return doPreparation()
.then(doPrePageWait)
Expand All @@ -81,10 +90,32 @@ function executionLoop() {
.then(doDomWait)
.then(doDelay)
.then(doCommand)
.then(doControlFlow)
.then(executionLoop);
}
}

function doControlFlow(result) {
let nextPlayingIndex;
if (result) {
// right
if (PlaybackState.runningQueue[PlaybackState.currentPlayingIndex].right) {
nextPlayingIndex = PlaybackState.runningQueue.indexOf(PlaybackState.runningQueue[PlaybackState.currentPlayingIndex].right);
} else {
nextPlayingIndex = PlaybackState.runningQueue.length + 1;
}
} else {
// left
if (PlaybackState.runningQueue[PlaybackState.currentPlayingIndex].left) {
nextPlayingIndex = PlaybackState.runningQueue.indexOf(PlaybackState.runningQueue[PlaybackState.currentPlayingIndex].left);
} else {
nextPlayingIndex = PlaybackState.runningQueue.length + 1;
}
}
PlaybackState.setPlayingIndex(nextPlayingIndex);
return Promise.resolve();
}

function prepareToPlay() {
PlaybackState.setPlayingIndex(PlaybackState.currentPlayingIndex - 1);
return extCommand.init();
Expand All @@ -101,7 +132,6 @@ function finishPlaying() {
function catchPlayingError(message) {
if (isReceivingEndError(message)) {
setTimeout(function() {
PlaybackState.setPlayingIndex(PlaybackState.currentPlayingIndex - 1);
playAfterConnectionFailed();
}, 100);
} else {
Expand Down Expand Up @@ -142,7 +172,7 @@ reaction(
function doPreparation() {
return extCommand.sendMessage("waitPreparation", "", "")
.then(function() {
return true;
return Promise.resolve();
});
}

Expand Down Expand Up @@ -232,13 +262,21 @@ function doCommand(res, implicitTime = Date.now(), implicitCount = 0) {
}, 500);
});

return p.then(() => (
command !== "type"
? extCommand.sendMessage(command, xlateArgument(target), xlateArgument(value), isWindowMethodCommand(command))
: extCommand.doType(xlateArgument(target), xlateArgument(value))
))
return p.then(() => {
if (command === "type") {
return extCommand.doType(xlateArgument(target), xlateArgument(value));
} else if (isConditinal(command)) {
return sandboxCommand.evalExpression(target);
} else {
return extCommand.sendMessage(command, xlateArgument(target), xlateArgument(value), isWindowMethodCommand(command));
}
})
.then(function(result) {
if (result.result !== "success") {
if (result.result === "truthy") {
return true;
} else if (result.result === "falsy") {
return false;
} else if (result.result !== "success") {
// implicit
if (result.result.match(/Element[\s\S]*?not found/)) {
if (implicitTime && (Date.now() - implicitTime > 30000)) {
Expand All @@ -258,10 +296,15 @@ function doCommand(res, implicitTime = Date.now(), implicitCount = 0) {
PlaybackState.setCommandState(id, PlaybackStates.Failed, result.result);
} else {
PlaybackState.setCommandState(id, PlaybackStates.Passed);
return true;
}
});
}

function isConditinal(commandName) {
return ["if", "while", "elseIf", "repeatIf", "times"].includes(commandName);
}

function doDelay() {
return new Promise((res) => {
if (PlaybackState.currentPlayingIndex + 1 === PlaybackState.runningQueue.length) {
Expand Down
Loading