Skip to content

Commit

Permalink
Merge pull request #4 from bobsilverberg/master
Browse files Browse the repository at this point in the history
Added some helper methods to selenium.cfc
  • Loading branch information
bcswartz committed Jun 22, 2011
2 parents 2a923f2 + 0260c57 commit 3b257d7
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CFSeleniumTestCase.cfc
Expand Up @@ -11,8 +11,8 @@
</cffunction>

<cffunction name="afterTests" output="false" access="public" returntype="any" hint="">
<!--- NOTE: this will only stop the Java if it was started by this test case --->
<cfset selenium.stop() />
<!--- NOTE: this will only stop the Java server if it was started by this test case --->
<cfset selenium.stopServer() />
</cffunction>

Expand Down
Binary file added formats/cfml-formatters-1.3.xpi
Binary file not shown.
2 changes: 1 addition & 1 deletion formats/chrome/content/formats/cfml-rc-mxunit.js
Expand Up @@ -43,7 +43,7 @@ function joinExpression(expression) {
}

function waitFor(expression) {
return "for (int second = 0;; second++) {\n" +
return "for (second = 0;; second++) {\n" +
"\tif (second >= 60) fail(\"timeout\");\n" +
"\ttry { " + (expression.setup ? expression.setup() + " " : "") +
"if (" + expression.toString() + ") break; } catch (Exception e) {}\n" +
Expand Down
2 changes: 1 addition & 1 deletion formats/chrome/install.rdf
Expand Up @@ -4,7 +4,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>cfml-formatters@silverwareconsulting.com</em:id>
<em:name>Selenium IDE: CFML Formatter</em:name>
<em:version>1.2</em:version>
<em:version>1.3</em:version>
<em:creator>Bob Silverberg</em:creator>
<em:description>A plugin to add CFML (ColdFusion) formatters to Selenium-IDE</em:description>
<em:type>2</em:type> <!-- type extension -->
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -12,7 +12,7 @@ CFSelenium is a ColdFusion Component (CFC) which provides a native client librar

### Usage ###

Optionally, start the Selenium-RC server. Selenium.cfc will automatically start the Selenium-RC server for you in the background if it isn't already started. To start it manually, the command is similar to this:
Optionally, start the Selenium-RC server. Selenium.cfc will automatically start the Selenium-RC server for you in the background if it isn't already started (note this does not work on CF7). To start it manually, the command is similar to this:

java -jar selenium-server-standalone-2.0b2.jar

Expand Down
38 changes: 36 additions & 2 deletions selenium.cfc
Expand Up @@ -17,7 +17,8 @@
*/

public any function init (string host = "localhost", numeric port = 4444,
numeric executionDelay = 200, string seleniumJarPath = "/cfselenium/Selenium-RC/selenium-server-standalone-2.0b2.jar", boolean verbose = false, string seleniumServerArguments = "") {
numeric executionDelay = 200, string seleniumJarPath = "/cfselenium/Selenium-RC/selenium-server-standalone-2.0b2.jar", boolean verbose = false, string seleniumServerArguments = "",
numeric waitTimeout = 30000) {

structAppend(variables,arguments,true);
variables.sessionId = "";
Expand Down Expand Up @@ -56,7 +57,40 @@
throw("The Response of the Selenium RC is invalid: #response#");

}


public void function waitForElementPresent(required string locator, numeric timeout = variables.waitTimeout) {
var counter = 0;
while (not isElementPresent(arguments.locator)) {
sleep(100);
counter += 100;
if (counter eq arguments.timeout) {
throw (type="CFSelenium.elementNotFound", message="The element: #arguments.locator# was not found after #arguments.timeout/1000# seconds.");
}
}
}

public void function waitForElementVisible(required string locator, numeric timeout = variables.waitTimeout) {
var counter = 0;
while (not isVisible(arguments.locator)) {
sleep(100);
counter += 100;
if (counter eq arguments.timeout) {
throw (type="CFSelenium.elementNotVisible", message="The element: #arguments.locator# was not visible after #arguments.timeout/1000# seconds.");
}
}
}

public void function waitForElementNotVisible(required string locator, numeric timeout = variables.waitTimeout) {
var counter = 0;
while (isVisible(arguments.locator)) {
sleep(100);
counter += 100;
if (counter eq arguments.timeout) {
throw (type="CFSelenium.elementStillVisible", message="The element: #arguments.locator# was still visible after #arguments.timeout/1000# seconds.");
}
}
}

public string function getString(required string command, array args = arrayNew(1)) {

var result = doCommand(argumentCollection=arguments);
Expand Down
2 changes: 1 addition & 1 deletion test/cf9/readmeTest.cfc
Expand Up @@ -10,7 +10,7 @@ component extends="cfselenium.CFSeleniumTestCase" {
assertEquals("bobsilverberg/CFSelenium - GitHub", selenium.getTitle());
selenium.click("link=readme.md");
selenium.waitForPageToLoad("30000");
sleep(5000);
sleep(1000);
assertEquals("readme.md at master from bobsilverberg/cfselenium - github", selenium.getTitle());
selenium.click("raw-url");
selenium.waitForPageToLoad("30000");
Expand Down
11 changes: 0 additions & 11 deletions test/cf9/seleniumTest.cfc
Expand Up @@ -27,16 +27,5 @@ component extends="cfselenium.CFSeleniumTestCase" {

}

function testOpen() {

selenium.open("/pages/viewpage.action?pageId=786471");
//assertEndsWith("html/test_open.html", selenium.getLocation());
//assertEquals("This is a test of the open command.", selenium.getBodyText());
debug(selenium.getAllLinks());
debug(selenium.getLocation());
debug(selenium.getBodyText());

}

}

81 changes: 81 additions & 0 deletions test/cf9/waitForTest.cfc
@@ -0,0 +1,81 @@
component extends="cfselenium.CFSeleniumTestCase" {

public void function beforeTests() {
browserUrl = "http://localhost/CFSelenium/test/fixture/";
selenium = createObject("component", "cfselenium.selenium").init(waitTimeout=5000);
selenium.start(browserUrl,"*firefox");
selenium.setTimeout(30000);
}

function setup() {
selenium.open("http://localhost/CFSelenium/test/fixture/waitForFixture.htm");
}

function waitForElementPresentShouldFindElementThatIsAlreadyThere() {

selenium.waitForElementPresent("alwaysPresentAndVisible");
assertEquals("alwaysPresentAndVisible",selenium.getText("alwaysPresentAndVisible"));

}

function waitForElementPresentShouldThrowIfElementIsNeverThere() expectedException="CFSelenium.elementNotFound" {

selenium.waitForElementPresent("neverPresent");

}

function waitForElementPresentShouldFindElementThatAppears() {

assertEquals(false,selenium.isElementPresent("presentAfterAPause"));
selenium.click("createElement");
selenium.waitForElementPresent("presentAfterAPause");
assertEquals("presentAfterAPause",selenium.getText("presentAfterAPause"));

}

function waitForElementVisibleShouldFindElementThatIsAlreadyThere() {

selenium.waitForElementVisible("alwaysPresentAndVisible");
assertEquals("alwaysPresentAndVisible",selenium.getText("alwaysPresentAndVisible"));

}

function waitForElementVisibleShouldThrowIfElementIsNeverVisible() expectedException="CFSelenium.elementNotVisible" {

selenium.waitForElementVisible("neverVisible");

}

function waitForElementVisibleShouldFindElementThatAppears() {

assertEquals(false,selenium.isVisible("becomesVisible"));
selenium.click("showElement");
selenium.waitForElementVisible("becomesVisible");
assertEquals("becomesVisible",selenium.getText("becomesVisible"));

}

function waitForElementNotVisibleShouldSucceedIfElementIsAlreadyInvisible() {

selenium.waitForElementNotVisible("neverVisible");
assertEquals("",selenium.getText("neverVisible"));

}

function waitForElementNotVisibleShouldThrowIfElementIsAlwaysVisible() expectedException="CFSelenium.elementStillVisible" {

selenium.waitForElementNotVisible("alwaysPresentAndVisible");

}

function waitForElementNotVisibleShouldSucceedIfElementDisappears() {

assertEquals(true,selenium.isVisible("becomesInvisible"));
selenium.click("hideElement");
selenium.waitForElementNotVisible("becomesInvisible");
assertEquals("",selenium.getText("becomesInvisible"));

}

}

23 changes: 23 additions & 0 deletions test/fixture/waitForFixture.htm
@@ -0,0 +1,23 @@
<html>
<body>
<script src="//ajax.microsoft.com/ajax/jquery/jquery-1.5.min.js" type="text/javascript"></script>
<script type="text/javascript">
function createElement() {
$('<div id="presentAfterAPause">presentAfterAPause</div>').appendTo("body");
}
function showElement() {
$("#becomesVisible").show();
}
function hideElement() {
$("#becomesInvisible").hide();
}
</script>
<div id="alwaysPresentAndVisible">alwaysPresentAndVisible</div>
<div id="neverVisible" style="display:none">neverVisible</div>
<div id="becomesVisible" style="display:none">becomesVisible</div>
<div id="becomesInvisible">becomesInvisible</div>
<a id="createElement" href="javascript:createElement();">Create an element</a>
<a id="showElement" href="javascript:showElement();">Show an element</a>
<a id="hideElement" href="javascript:hideElement();">Hide an element</a>
</body>
</html>

0 comments on commit 3b257d7

Please sign in to comment.