diff --git a/CFSeleniumTestCase.cfc b/CFSeleniumTestCase.cfc index 07b3828..12a6f5c 100755 --- a/CFSeleniumTestCase.cfc +++ b/CFSeleniumTestCase.cfc @@ -11,8 +11,8 @@ - + diff --git a/formats/cfml-formatters-1.3.xpi b/formats/cfml-formatters-1.3.xpi new file mode 100644 index 0000000..0cffb8b Binary files /dev/null and b/formats/cfml-formatters-1.3.xpi differ diff --git a/formats/chrome/content/formats/cfml-rc-mxunit.js b/formats/chrome/content/formats/cfml-rc-mxunit.js index 35e7eb0..339cb4a 100644 --- a/formats/chrome/content/formats/cfml-rc-mxunit.js +++ b/formats/chrome/content/formats/cfml-rc-mxunit.js @@ -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" + diff --git a/formats/chrome/install.rdf b/formats/chrome/install.rdf index e69039f..8757483 100755 --- a/formats/chrome/install.rdf +++ b/formats/chrome/install.rdf @@ -4,7 +4,7 @@ cfml-formatters@silverwareconsulting.com Selenium IDE: CFML Formatter - 1.2 + 1.3 Bob Silverberg A plugin to add CFML (ColdFusion) formatters to Selenium-IDE 2 diff --git a/readme.md b/readme.md index d4921bb..4cf8cbc 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/selenium.cfc b/selenium.cfc index 91fe907..533fa76 100644 --- a/selenium.cfc +++ b/selenium.cfc @@ -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 = ""; @@ -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); diff --git a/test/cf9/readmeTest.cfc b/test/cf9/readmeTest.cfc index 0ea7311..908a92d 100644 --- a/test/cf9/readmeTest.cfc +++ b/test/cf9/readmeTest.cfc @@ -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"); diff --git a/test/cf9/seleniumTest.cfc b/test/cf9/seleniumTest.cfc index a184175..60f0317 100644 --- a/test/cf9/seleniumTest.cfc +++ b/test/cf9/seleniumTest.cfc @@ -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()); - - } - } diff --git a/test/cf9/waitForTest.cfc b/test/cf9/waitForTest.cfc new file mode 100644 index 0000000..b3368b8 --- /dev/null +++ b/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")); + + } + +} + diff --git a/test/fixture/waitForFixture.htm b/test/fixture/waitForFixture.htm new file mode 100644 index 0000000..fcf3571 --- /dev/null +++ b/test/fixture/waitForFixture.htm @@ -0,0 +1,23 @@ + + + + +
alwaysPresentAndVisible
+ + +
becomesInvisible
+ Create an element + Show an element + Hide an element + + \ No newline at end of file