gpt4 book ai didi

org.mozilla.zest.impl.ZestBasicRunner类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 09:34:55 25 4
gpt4 key购买 nike

本文整理了Java中org.mozilla.zest.impl.ZestBasicRunner类的一些代码示例,展示了ZestBasicRunner类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestBasicRunner类的具体详情如下:
包路径:org.mozilla.zest.impl.ZestBasicRunner
类名称:ZestBasicRunner

ZestBasicRunner介绍

暂无

代码示例

代码示例来源:origin: mozilla/zest

private static void run(ZestScript zs, Map<String, String> parameters, boolean debug) {
    ZestBasicRunner zbr = new ZestBasicRunner();
    zbr.setOutputWriter(new OutputStreamWriter(System.out));
    zbr.setStopOnAssertFail(false);
    zbr.setDebug(debug);
    try {
      zbr.run(zs, parameters);
    } catch (Exception e) {
      System.out.println("Error running script: " + e);
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: mozilla/zest

@Override
public String handleAssignment(
    ZestScript script, ZestAssignment assign, ZestResponse lastResponse)
    throws ZestAssignFailException {
  try {
    String result = assign.assign(lastResponse, this);
    // Replace any variables
    this.setVariable(
        assign.getVariableName(), this.replaceVariablesInString(result, false));
    if (result != null) {
      this.debug(
          assign.getIndex()
              + " Assign: "
              + assign.getVariableName()
              + " = "
              + result);
    }
    return result;
  } catch (ZestAssignFailException e) {
    this.output(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: mozilla/zest

@Override
public void responseFailed(ZestRequest request, ZestResponse response, ZestAssertion assertion)
    throws ZestAssertFailException {
  this.debug(request.getIndex() + " Assertion FAILED: " + assertion.getClass().getName());
  if (this.getStopOnAssertFail()) {
    throw new ZestAssertFailException(assertion);
  }
}

代码示例来源:origin: mozilla/zest

@Override
public String handleClient(ZestScript script, ZestClient client)
    throws ZestClientFailException {
  this.debug(client.getIndex() + " Client invoke: " + client.getClass().getName());
  try {
    String result = client.invoke(this);
    if (result != null) {
      this.debug(client.getIndex() + " Client result: " + result);
    }
    return result;
  } catch (ZestClientFailException e) {
    this.output(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: mozilla/zest

this.lastRequest = ((ZestRequest) stmt).deepCopy();
  this.lastRequest.replaceTokens(this.variables);
  this.debug(this.lastRequest.getMethod() + " : " + this.lastRequest.getUrl());
  this.lastResponse = send(this.lastRequest);
  this.setStandardVariables(lastRequest);
  this.setStandardVariables(lastResponse);
  handleResponse(this.lastRequest, this.lastResponse);
  return this.lastResponse;
  ZestConditional zc = (ZestConditional) stmt;
  if (zc.isTrue(this)) {
    this.debug(stmt.getIndex() + " Conditional TRUE: " + zc.getClass().getName());
    for (ZestStatement ifStmt : zc.getIfStatements()) {
      lastResponse = this.runStatement(script, ifStmt, lastResponse);
    this.debug(stmt.getIndex() + " Conditional FALSE: " + zc.getClass().getName());
    for (ZestStatement elseStmt : zc.getElseStatements()) {
      lastResponse = this.runStatement(script, elseStmt, lastResponse);
  handleAction(script, (ZestAction) stmt, lastResponse);
} else if (stmt instanceof ZestAssignment) {
  handleAssignment(script, (ZestAssignment) stmt, lastResponse);
} else if (stmt instanceof ZestLoop) {
  lastResponse = handleLoop(script, (ZestLoop<?>) stmt, lastResponse);
} else if (stmt instanceof ZestControlLoopBreak) {
  debug(stmt.getIndex() + " Break");
  handleControlLoopBreak();

代码示例来源:origin: mozilla/zest

@Test
public void testClientXpathLoopReturningType() throws Exception {
  ZestScript script = new ZestScript();
  script.add(new ZestClientLaunch("htmlunit", "HtmlUnit", getServerUrl(PATH_SERVER_FILE)));
  ZestLoopClientElements loop =
      new ZestLoopClientElements("val", "htmlunit", "xpath", "//*", "type");
  loop.addStatement(new ZestActionPrint("{{val}}"));
  script.add(loop);
  script.add(new ZestClientWindowClose("htmlunit", 0));
  ZestBasicRunner runner = new ZestBasicRunner();
  // Uncomment this to proxy via ZAP
  // runner.setProxy("localhost", 8090);
  StringWriter sw = new StringWriter();
  runner.setOutputWriter(sw);
  runner.run(script, null);
  assertEquals("text\n" + "password\n" + "select-one\n" + "submit\n", sw.toString());
}

代码示例来源:origin: mozilla/zest

@Test(expected = IllegalArgumentException.class)
public void shouldFailToRunNonPassiveStatementsInPassiveScripts() throws Exception {
  // Given
  ZestScript script = new ZestScript();
  script.setType(ZestScript.Type.Passive);
  script.add(new ZestRequest());
  ZestBasicRunner runner = new ZestBasicRunner();
  // When
  runner.run(script, new HashMap<String, String>());
  // Then = IllegalArgumentException
}

代码示例来源:origin: mozilla/zest

request.setData(data);
script.add(request);
ZestBasicRunner runner = new ZestBasicRunner();
runner.run(script, new HashMap<String, String>());
request = runner.getLastRequest();
assertThat(request).isNotNull();
assertThat(request.getTimestamp()).isCloseTo(System.currentTimeMillis(), byLessThan(2000L));
assertThat(request.getData()).isEqualTo(data);
ZestResponse response = runner.getLastResponse();
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(404);

代码示例来源:origin: mozilla/zest

loop.addStatement(zaAppendComma);
ZestBasicRunner runner = new ZestBasicRunner();
runner.run(script, null);
assertEquals(" 1, 2, 3, 4, 5, 6, 7,", runner.getVariable("res"));
runner.run(script, null);
assertEquals(",,,,,,,", runner.getVariable("res"));
runner.run(script, null);
assertEquals(" 1 2 3 4 5 6 7", runner.getVariable("res"));
loop.setEnabled(false);
runner.run(script, null);
assertEquals("", runner.getVariable("res"));

代码示例来源:origin: mozilla/zest

this.setVariable(loop.getVariableName(), loop.getCurrentToken().toString());
  loops.push(loop);
  while (loop.hasMoreElements()) {
      token = loop.getCurrentToken().toString();
      loopOutput += ", Current Token: " + token;
      this.setVariable(loop.getVariableName(), token);
    this.debug(loopOutput);
    lastResponse = this.runStatement(script, loop.nextElement(), lastResponse);
    if (skipStatements) { // a LoopControl occurred
      skipStatements = false;
  this.setVariable(loop.getVariableName(), "");
  return lastResponse;
} catch (ZestAssertFailException e) {
  this.output(e.getMessage());
  throw e;
} catch (ZestActionFailException e) {
  this.output(e.getMessage());
  throw e;
} catch (ZestInvalidCommonTestException e) {
  this.output(e.getMessage());
  throw e;
} catch (IOException e) {
  this.output(e.getMessage());
  throw e;
} catch (ZestAssignFailException e) {
  this.output(e.getMessage());

代码示例来源:origin: mozilla/zest

@Override
public String run(ZestScript script, Map<String, String> params)
    throws ZestAssertFailException, ZestActionFailException, IOException,
        ZestInvalidCommonTestException, ZestAssignFailException,
        ZestClientFailException {
  return this.run(script, null, params);
}

代码示例来源:origin: mozilla/zest

@Override
public void responsePassed(
    ZestRequest request, ZestResponse response, ZestAssertion assertion) {
  this.debug("Assertion PASSED: " + assertion.getClass().getName());
}

代码示例来源:origin: mozilla/zest

@Test
public void testClientXpathLoopReturningName() throws Exception {
  ZestScript script = new ZestScript();
  script.add(new ZestClientLaunch("htmlunit", "HtmlUnit", getServerUrl(PATH_SERVER_FILE)));
  ZestLoopClientElements loop =
      new ZestLoopClientElements("val", "htmlunit", "xpath", "//*", "name");
  loop.addStatement(new ZestActionPrint("{{val}}"));
  script.add(loop);
  script.add(new ZestClientWindowClose("htmlunit", 0));
  ZestBasicRunner runner = new ZestBasicRunner();
  // Uncomment this to proxy via ZAP
  // runner.setProxy("localhost", 8090);
  StringWriter sw = new StringWriter();
  runner.setOutputWriter(sw);
  runner.run(script, null);
  // Expected string split up for clarity
  assertEquals("something\n" + "a\n" + "b\n" + "c" + "\n" + "submit\n", sw.toString());
}

代码示例来源:origin: mozilla/zest

ZestBasicRunner runner = new ZestBasicRunner();
String result = runner.run(zestScript, req, map);

代码示例来源:origin: mozilla/zest

@Override
public String runScript(String script, Map<String, String> params)
    throws ZestAssertFailException, ZestActionFailException, IOException,
        ZestInvalidCommonTestException, ZestAssignFailException,
        ZestClientFailException {
  return run((ZestScript) ZestJSON.fromString(script), params);
}

代码示例来源:origin: mozilla/zest

@Override
public String handleAction(ZestScript script, ZestAction action, ZestResponse lastResponse)
    throws ZestActionFailException {
  this.debug(action.getIndex() + " Action invoke: " + action.getClass().getName());
  try {
    String result = action.invoke(lastResponse, this);
    if (result != null) {
      this.debug(action.getIndex() + " Action result: " + result);
    }
    return result;
  } catch (ZestActionFailException e) {
    this.output(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: mozilla/zest

@Override
public void responsePassed(ZestRequest request, ZestResponse response) {
  this.debug(request.getIndex() + " Response PASSED");
}

代码示例来源:origin: mozilla/zest

@Test
public void testClientXpathLoopReturningText() throws Exception {
  ZestScript script = new ZestScript();
  script.add(new ZestClientLaunch("htmlunit", "HtmlUnit", getServerUrl(PATH_SERVER_FILE)));
  ZestLoopClientElements loop =
      new ZestLoopClientElements(
          "val", "htmlunit", "xpath", "//input[@type='text']", "name");
  loop.addStatement(new ZestActionPrint("{{val}}"));
  script.add(loop);
  script.add(new ZestClientWindowClose("htmlunit", 0));
  ZestBasicRunner runner = new ZestBasicRunner();
  // Uncomment this to proxy via ZAP
  // runner.setProxy("localhost", 8090);
  StringWriter sw = new StringWriter();
  runner.setOutputWriter(sw);
  runner.run(script, null);
  assertEquals("a\n", sw.toString());
}

代码示例来源:origin: mozilla/zest

@Test(expected = ZestClientFailException.class)
public void testInvalidName() throws Exception {
  ZestScript script = new ZestScript();
  script.add(new ZestClientLaunch("bad", "baddriver", getServerUrl(PATH_SERVER_FILE)));
  script.add(new ZestClientWindowClose("bad", 0));
  ZestBasicRunner runner = new ZestBasicRunner();
  runner.run(script, null);
}

代码示例来源:origin: mozilla/zest

@Override
public String runScript(Reader reader, Map<String, String> params)
    throws ZestAssertFailException, ZestActionFailException, IOException,
        ZestInvalidCommonTestException, ZestAssignFailException,
        ZestClientFailException {
  StringBuilder sb = new StringBuilder();
  try (BufferedReader fr = new BufferedReader(reader)) {
    String line;
    while ((line = fr.readLine()) != null) {
      sb.append(line);
    }
  }
  return run((ZestScript) ZestJSON.fromString(sb.toString()), params);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com