Example #1
0
  private void given(Task... tasks) {

    ensureOpenedTodoMVCPage();
    StringBuilder jsStringBuilder =
        new StringBuilder("localStorage.setItem(\"todos-troopjs\", \"[");

    for (int i = 0; i < tasks.length; i++) {
      String taskData = tasks[i].toString();

      jsStringBuilder.append(taskData);
      if (i < tasks.length - 1) {
        jsStringBuilder.append(",");
      }
    }
    jsStringBuilder.append("]\")");

    executeJavaScript(jsStringBuilder.toString());
    getWebDriver().navigate().refresh();
  }
Example #2
0
  private void given(Task... tasks) {
    givenEmptyTodoMVCPage();
    StringBuilder jsStringBuilder =
        new StringBuilder("localStorage.setItem(\"todos-troopjs\", \"[");
    int i = 0;
    for (Task task : tasks) {
      String taskData = task.toString();
      if (i < tasks.length - 1) {
        jsStringBuilder.append(taskData).append(", ");
      } else if (i == tasks.length - 1) {
        jsStringBuilder.append(taskData);
      }
      i++;
    }
    jsStringBuilder.append("]\")");

    executeJavaScript(jsStringBuilder.toString());
    getWebDriver().navigate().refresh();
  }