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

Port sideflow.js to also support Maven Selenium Plugin's selenese goal #12

Open
paulbors opened this issue Apr 15, 2015 · 3 comments
Open

Comments

@paulbors
Copy link

When the sideflow.js is added to the user-extensions.js for the Selenium Maven Plugin to run the Selenese HTML test suit, the script breaks inside initialiseLabels() as the testCase is not defined in this environment.

For Selenium Maven Plugin documentation see:
http://mojo.codehaus.org/selenium-maven-plugin/selenese-mojo.html

A code snippet I've been using in my POM:

...
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>selenium-maven-plugin</artifactId>
    <version>${maven.selenium.plugin.version}</version>
    <configuration>
        <userExtensions>src/test/selenium/user-extensions.js</userExtensions>
        <browser>*firefox</browser>
        <startURL>http://localhost:${maven.tomcat.port}</startURL>
        <suite>${basedir}/target/test-classes/selenium/DesktopTests.html</suite>
    </configuration>
    <executions>
        <!-- Sanity tests and also screenshots -->
        <execution>
            <id>run-selenium-tests-ff-desktop-sanity</id>
            <phase>integration-test</phase>
            <configuration>
                <browser>*firefox</browser>
                <multiWindow>true</multiWindow>
                <port>${maven.selenium.plugin.port}</port>
                <startURL>http://localhost:${maven.tomcat.port}</startURL>
                <suite>${basedir}/target/test-classes/selenium/DesktopScreenshots.html</suite>
                <results>${basedir}/target/selenium/results-firefox-desktop-screenshots-TestSuite.html</results>
            </configuration>
            <goals>
                <goal>selenese</goal>
            </goals>
        </execution>
        ...
     </executions>
</plugin>
...

I'm researching into a fix and will provide a PR if I find out...

@paulbors paulbors changed the title sideflow.js is not working with "mvn selenium:selenese test" sideflow.js is not working with "mvn selenium:selenese" Apr 15, 2015
@paulbors
Copy link
Author

So the problem here is that this script is written to work only for the Selenium IDE and not the Selenium RC. Good news is that it can be modified to work under both run-times environments and I'm in the middle of it.

As it turns out the script is a bit old too and is still accessing the deprecated testCase variable of the Slenium IDE window instead of invoking Application.prototype.getTestCase(). I'll fix that as well...

@paulbors
Copy link
Author

So far so good... I was able to implement the loop that initializes that custom commands inside Selenium.prototype.initialiseLabels() for Selenium RC. It will end up looking something like:

// Some utils to simplify life...
var sideflowJsUtils = {};
sideflowJsUtils.isIDE = (Application.prototype != undefined);
sideflowJsUtils.getTestCase = function() {
    if(sideflowJsUtils.isIDE) {
        return Application.prototype.getTestCase();
    }
    return testFrame.getCurrentTestCase();
};
sideflowJsUtils.getCommands = function() {
    var seleniumCommands;
    if(sideflowJsUtils.isIDE) {
        seleniumCommands = sideflowJsUtils.getTestCase().commands;
    } else {
        seleniumCommands = sideflowJsUtils.getTestCase().commandRows;
    }
    return seleniumCommands;
};

Selenium.prototype.initialiseLabels = function() {
    ...
    // For all active test commands in Selenium RC
    var command = command_rows[i].trElement.cells[0].innerHTML;
    var target = command_rows[i].trElement.cells[1].innerHTML;
    var value = command_rows[i].trElement.cells[2].innerHTML;
    switch (command.toLowerCase()) {
        case "label":
            gotoLabels[ target ] = i;
            break;
        case "while":
        case "endwhile":
            cycles.push([command.toLowerCase(), i]);
            break;
        case "foreach":
        case "endforeach":
            forEachCmds.push([command.toLowerCase(), i]);
            break;
    }
    ...
}

That's tested and working now is time to move on to implementing the commands themselves.

I see the extensive use of testCase.debugContext.debugIndex but the TestCase object is not available in Selenium RC so this might end up having to be forked inside an if as well and implemented in a second different way too to support Selenium RC and its Selenese scripts. That's for tomorrow...

@paulbors
Copy link
Author

I ended up refactoring most of the script and implemented the OOP Selenium's way.

I have tested it given your demos and my own scripts in both the Selenium IDE and Maven Selenium Plugin.

Feel free to test and accept the PR at your leisure.

paulbors added a commit to paulbors/sideflow that referenced this issue Apr 16, 2015
…nese"

* Refactored the script and adopted Selenium's OOP way of doing things
* Ported the script to support the Maven Selenium Plugin's selenese target
paulbors added a commit to paulbors/sideflow that referenced this issue Apr 16, 2015
…nese"

* Fixed SideFlow.initialize() for command loop in the IDE not to fall through the RC for comments
paulbors added a commit to paulbors/sideflow that referenced this issue Apr 17, 2015
…nese"

* Fixed SideFlow.initialize() and how the testFrame changes on page re-load for Selenium RC in Selenium Maven Plugin
* Fixed the while loop off by a row bug
* Refactored some of the undefined checks to also check for isNaN()
@paulbors paulbors changed the title sideflow.js is not working with "mvn selenium:selenese" Port sideflow.js to also support Maven Selenium Plugin's selenese goal Apr 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant