Skip to content

Commit

Permalink
AlexeiBarantsev: Implementing alert handling commands formatting in J…
Browse files Browse the repository at this point in the history
…ava formatter.

r17931
  • Loading branch information
barancev committed Oct 8, 2012
1 parent c1443dd commit d602021
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 32 deletions.
20 changes: 20 additions & 0 deletions ide/main/src/content/formats/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,26 @@ SeleniumWebDriverAdaptor.prototype.getTitle = function() {
return driver.getTitle();
};

SeleniumWebDriverAdaptor.prototype.getAlert = function() {
var driver = new WDAPI.Driver();
return driver.getAlert();
};

SeleniumWebDriverAdaptor.prototype.getConfirmation = function() {
var driver = new WDAPI.Driver();
return driver.getAlert();
};

SeleniumWebDriverAdaptor.prototype.chooseOkOnNextConfirmation = function() {
var driver = new WDAPI.Driver();
return driver.chooseOkOnNextConfirmation();
};

SeleniumWebDriverAdaptor.prototype.chooseCancelOnNextConfirmation = function() {
var driver = new WDAPI.Driver();
return driver.chooseCancelOnNextConfirmation();
};

SeleniumWebDriverAdaptor.prototype.getValue = function(elementLocator) {
var locator = this._elementLocator(this.rawArgs[0]);
var driver = new WDAPI.Driver();
Expand Down
92 changes: 60 additions & 32 deletions ide/plugins/java-format/src/content/formats/webdriver-junit4.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,40 +207,56 @@ options.header =
"import org.openqa.selenium.support.ui.Select;\n" +
"\n" +
"public class ${className} {\n" +
"\tprivate WebDriver driver;\n" +
"\tprivate String baseUrl;\n" +
"\tprivate StringBuffer verificationErrors = new StringBuffer();\n" +
"\t@Before\n" +
"\tpublic void setUp() throws Exception {\n" +
"\t\tdriver = new FirefoxDriver();\n" +
"\t\tbaseUrl = \"${baseURL}\";\n" +
"\t\tdriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);\n" +
"\t}\n" +
"\n" +
"\t@Test\n" +
"\tpublic void ${methodName}() throws Exception {\n";
indents(1) + "private WebDriver driver;\n" +
indents(1) + "private String baseUrl;\n" +
indents(1) + "private boolean acceptNextAlert = true;\n" +
indents(1) + "private StringBuffer verificationErrors = new StringBuffer();\n" +
indents(0) + "\n" +
indents(1) + "@Before\n" +
indents(1) + "public void setUp() throws Exception {\n" +
indents(2) + "driver = new FirefoxDriver();\n" +
indents(2) + "baseUrl = \"${baseURL}\";\n" +
indents(2) + "driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);\n" +
indents(1) + "}\n" +
indents(0) + "\n" +
indents(1) + "@Test\n" +
indents(1) + "public void ${methodName}() throws Exception {\n";

options.footer =
"\t}\n" +
"\n" +
"\t@After\n" +
"\tpublic void tearDown() throws Exception {\n" +
"\t\tdriver.quit();\n" +
"\t\tString verificationErrorString = verificationErrors.toString();\n" +
"\t\tif (!\"\".equals(verificationErrorString)) {\n" +
"\t\t\tfail(verificationErrorString);\n" +
"\t\t}\n" +
"\t}\n" +
"\n" +
"\tprivate boolean isElementPresent(By by) {\n" +
"\t\ttry {\n" +
"\t\t\tdriver.findElement(by);\n" +
"\t\t\treturn true;\n" +
"\t\t} catch (NoSuchElementException e) {\n" +
"\t\t\treturn false;\n" +
"\t\t}\n" +
"\t}\n" +
"}\n";
indents(1) + "}\n" +
indents(0) + "\n" +
indents(1) + "@After\n" +
indents(1) + "public void tearDown() throws Exception {\n" +
indents(2) + "driver.quit();\n" +
indents(2) + "String verificationErrorString = verificationErrors.toString();\n" +
indents(2) + "if (!\"\".equals(verificationErrorString)) {\n" +
indents(3) + "fail(verificationErrorString);\n" +
indents(2) + "}\n" +
indents(1) + "}\n" +
indents(0) + "\n" +
indents(1) + "private boolean isElementPresent(By by) {\n" +
indents(2) + "try {\n" +
indents(3) + "driver.findElement(by);\n" +
indents(3) + "return true;\n" +
indents(2) + "} catch (NoSuchElementException e) {\n" +
indents(3) + "return false;\n" +
indents(2) + "}\n" +
indents(1) + "}\n" +
indents(0) + "\n" +
indents(1) + "private String closeAlertAndGetItsText() {\n" +
indents(2) + "try {\n" +
indents(3) + "Alert alert = driver.switchTo().alert();\n" +
indents(3) + "if (acceptNextAlert) {\n" +
indents(4) + "alert.accept();\n" +
indents(3) + "} else {\n" +
indents(4) + "alert.dismiss();\n" +
indents(3) + "}\n" +
indents(3) + "return alert.getText();\n" +
indents(2) + "} finally {\n" +
indents(3) + "acceptNextAlert = true;\n" +
indents(2) + "}\n" +
indents(1) + "}\n" +
indents(0) + "}\n";

this.configForm =
'<description>Variable for Selenium instance</description>' +
Expand Down Expand Up @@ -311,6 +327,18 @@ WDAPI.Driver.prototype.getTitle = function() {
return this.ref + ".getTitle()";
};

WDAPI.Driver.prototype.getAlert = function() {
return "closeAlertAndGetItsText()";
};

WDAPI.Driver.prototype.chooseOkOnNextConfirmation = function() {
return "acceptNextAlert = true";
};

WDAPI.Driver.prototype.chooseCancelOnNextConfirmation = function() {
return "acceptNextAlert = false";
};

WDAPI.Driver.prototype.refresh = function() {
return this.ref + ".navigate().refresh()";
};
Expand Down

0 comments on commit d602021

Please sign in to comment.