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 rewrite of java to new style #1661

Closed
wants to merge 5 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
1,091 changes: 0 additions & 1,091 deletions packages/code-export-java-junit/src/command.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Alert alert = driver.switchTo().alert();
alert.sendKeys({{{keys target}}});
alert.accept();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assertEquals(vars.get({{{string varName}}}).toString(), {{{string value}}});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assertThat(driver.switchTo().alert().getText(), is({{{string alertText}}})));
6 changes: 6 additions & 0 deletions packages/code-export-java-junit/src/commands/check.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
WebElement element = driver.findElement({{{locator target}}});
if (!element.isSelected()) {
element.click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver.switchTo().alert().dismiss();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver.switchTo().alert().accept();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver.findElement({{{locator target}}}).click();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver.close();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebElement element = driver.findElement({{{locator target}}});
Actions builder = new Actions(driver);
builder.doubleClick(element).perform();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
WebElement dragged = driver.findElement({{{locator target}}});
WebElement dropped = driver.findElement({{{locator value}}});
Actions builder = new Actions(driver);
builder.dragAndDrop(dragged, dropped).perform();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
System.out.println({{{string message}}});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebElement element = driver.findElement({{{locator target});
js.executeScript("if(arguments[0].contentEditable === 'true') {arguments[0].innerText = {{{string value}}}}", element);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const result = js.executeAsyncScript({{{expression target}}})
if (varName) {
vars[varName] = result
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const result = js.executeScript({{{async_script target}}})
if (varName) {
vars[varName] = result
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebElement element = driver.findElement({{{locator target}}});`,
Actions builder = new Actions(driver);
builder.moveToElement(element).clickAndHold().perform();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebElement element = driver.findElement({{{locator target}}});`,
Actions builder = new Actions(driver);
builder.moveToElement(element).clickAndHold().perform();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebElement element = driver.findElement({{{locator target}}});
Actions builder = new Actions(driver);
builder.moveToElement(element).perform();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebElement element = driver.findElement(By.tagName("body"));
Actions builder = new Actions(driver);
builder.moveToElement(element, 0, 0).perform();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WebElement element = driver.findElement({{{locator target}}});
Actions builder = new Actions(driver);
builder.moveToElement(element).release().perform();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WebElement element = driver.findElement({{{locator target}}});
Actions builder = new Actions(driver);
builder.moveToElement(element).release().perform();
5 changes: 5 additions & 0 deletions packages/code-export-java-junit/src/commands/open.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#if match target '^(file|http|https)://'}}
driver.get({{{string target}}});
{{else}}
driver.get({{{baseURL}}}{{{string target}}});
{{/if}}
5 changes: 5 additions & 0 deletions packages/code-export-java-junit/src/commands/pause.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try {
Thread.sleep({{{number time}}});
} catch (InterruptedException e) {
e.printStackTrace();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{test target}}}()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebElement dropdown = driver.findElement({{{locator target}}});
dropdown.findElement({{{locator value}}}).click();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{#if (eq frameLocation 'relative=top')}}
driver.switchTo().defaultContent();
{{else if (eq frameLocation 'relative=parent')}}
driver.switchTo().defaultContent();
{{else if (match frameLocation '^index')}}
driver.switchTo().frame({{{num ( target)}}});
{{else}}
{
WebElement element = driver.findElement({{{locator target}}});
driver.switchTo().frame(element);
}
{{/if}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{#if (match target '^handle=')}}
driver.switchTo().window({{{string (attribute target)}}});
{{else if (match target 'relative=parent')}}
driver.switchTo().window({{{string (attribute target)}}});
{{else if (match target '^win_ser_')}}
{
ArrayList<String> handles = new ArrayList<String>(driver.getWindowHandles());
{{#if (eq target 'win_ser_local')}}
driver.switchTo().window(handles.get(0));
{{else}}
driver.switchTo().window(handles.get({{{number (substr target 8)}}}));
{{/if}}
}
{{else}}
throw new Exception("Can only `select window` using handles");
{{/if}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver.findElement({{{locator target}}}).sendKeys({{{keys value}}});
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver.manage().window().setSize(new Dimension({{{size:size}}}));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vars[{{{varName}}}] = {{{value}}};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebElement element = driver.findElement({{{locator target}}});
vars[{{{varName}}}] = element.getAttribute({{{attributeName}}});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vars[{{{varName}] = driver.findElement({{{await location.emit(locator)}).getText();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vars[{{{varName}}}] = driver.getTitle();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vars[{{{varName}}}] = driver.findElement({{{locator target}}}).getAttribute("value");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vars[{{{varName}}}] = driver.getWindowHandle();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vars[{{{varName}}}] = driver.findElements({{{await location.emit(locator)}).size();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error("\`submit\` is not a supported command in Selenium WebDriver. Please re-record the step in the IDE.");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver.findElement({{{target}}}).sendKeys("keys:value");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
WebElement element = driver.findElement({{{locator});
if (element.isSelected()) {
element.click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assertTrue(driver.findElement({{{locator target}}}).isSelected());
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebElement element = driver.findElement({{{locator target}}});
Boolean isEditable = element.isEnabled() && element.getAttribute("readonly") == null;
assertTrue(isEditable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
List<WebElement> elements = driver.findElements({{{locator target}}});
assert(elements.size() == 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
List<WebElement> elements = driver.findElements({{{locator target}}});
assert(elements.size() > 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assertFalse(driver.findElement({{{locator target}}}).isSelected());
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebElement element = driver.findElement({{{locator target}}});
Boolean isEditable = element.isEnabled() && element.getAttribute("readonly") == null;
assertFalse(isEditable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
String value = driver.findElement({{{locator target}}}).getAttribute("value");
assertThat(value, is(not({{{text:expectedValue}}})));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
assertThat(
driver.findElement({{{locator target}}}).getText()
is(not({{{text:text}}}))
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
WebElement element = driver.findElement({{{locator target}}});
String value = element.getAttribute("value");
String locator = String.format("option[@value='%s']", value);
String selectedText = element.findElement(By.xpath(locator)).getText();
assertThat(selectedText, is({{{labelValue}}}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
String value = driver.findElement({{{locator target}}}).getAttribute("value");
assertThat(value, is({{{value}}}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assertThat(driver.findElement({{{locator target}}}).getText(), is({{{text:text}}}));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assertThat(driver.getTitle(), is({{{title}}}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
String value = driver.findElement({{{locator target}}}).getAttribute("value");
assertThat(value, is({{{value}}}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s:timeout}}});
wait.until(ExpectedConditions.elementToBeClickable({{{locator target}}}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s:timeout}}});
wait.until(ExpectedConditions.not(ExpectedConditions.elementToBeClickable({{{locator target}}})));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s:timeout}}});
WebElement element = driver.findElement({{{locator target}}});
wait.until(ExpectedConditions.stalenessOf(element));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s timeout}}});
wait.until(ExpectedConditions.invisibilityOfElementLocated({{{locator target}}}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s:timeout}}});
wait.until(ExpectedConditions.presenceOfElementLocated({{{locator target}}}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s:timeout}}});
wait.until(ExpectedConditions.visibilityOfElementLocated({{{locator target}}}));

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s:timeout}}});
wait.until(ExpectedConditions.textToBe({{{locator target}}}, {{{text}}}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
WebDriverWait wait = new WebDriverWait(driver, {{{ms-to-s:timeout}}});
wait.until(ExpectedConditions.invisibilityOfElementLocated({{{locator target}}}));
}
8 changes: 8 additions & 0 deletions packages/code-export-java-junit/src/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"displayName": "Java JUnit",
"name": "java-junit",
"fileExtension": ".java",
"commandPrefixPadding": " ",
"terminatingKeyword": "}",
"commentPrefix": "//"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
do {
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
} else {
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
} else if ({{{boolean_exec script}}}) {
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ArrayList collection{{{target}}} = (ArrayList) vars.get({{{target}}});
for (int i{{{value}}} = 0; i < collection{{{target}}}.size() - 1; i{{{value}}}++) {
vars.put({{{value}}}, collection{{{target}}}.get(i));
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if ({{{boolean_exec script}}}) {

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
} while ({{{boolean_exec script}}});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Integer times = {{{number target}}};
for (int i = 0; i < times; i++) {
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
while ({{{boolean_exec target }}}) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vars.put("window_handles", driver.getWindowHandles());
{{{emittedCommand}}}
vars.put({{{string windowHandleName}}}, waitForWindow({{{number command.windowTimeout}}}));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vars.get({{{string varName}}}).toString()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public String waitForWindow(int timeout) {
try {
Thread.sleep(timeout);
} catch (InterruptedException e) {
e.printStackTrace();
}
Set<String> whNow = driver.getWindowHandles();
Set<String> whThen = (Set<String>) vars.get("window_handles");
if (whNow.size() > whThen.size()) {
whNow.removeAll(whThen);
}
return whNow.iterator().next();
}
Loading