本文整理了Java中org.mozilla.zest.core.v1.ZestJSON.fromString()
方法的一些代码示例,展示了ZestJSON.fromString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestJSON.fromString()
方法的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestJSON
类名称:ZestJSON
方法名:fromString
[英]From string.
[中]从字符串。
代码示例来源: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 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);
}
代码示例来源:origin: mozilla/zest
private static void assertZestScript(String name) throws Exception {
ZestElement zestElement = ZestJSON.fromString(readScript(name));
assertTrue(name, zestElement instanceof ZestScript);
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerializationLoopFile() throws FileNotFoundException {
ZestLoopFile loop = new ZestLoopFile(ZestLoopFileUnitTest.file.getAbsolutePath());
for (ZestStatement stmt : statements) {
loop.addStatement(stmt);
}
String loopString = ZestJSON.toString(loop);
ZestLoopFile copy = (ZestLoopFile) ZestJSON.fromString(loopString);
String copyString = ZestJSON.toString(copy);
// System.out.println("===============================");
// System.out.println(" LOOP FILE");
// System.out.println("===============================");
// System.out.println(copyString);
assertTrue(loopString.equals(copyString));
}
}
代码示例来源:origin: mozilla/zest
getClass().getResource("/data/assignRegexDelimiters-script.zest"),
StandardCharsets.UTF_8);
ZestScript zestScript = (ZestScript) ZestJSON.fromString(zestString);
代码示例来源:origin: mozilla/zest
@Test
public void testSerializationLoopInteger() {
ZestLoopInteger loop = new ZestLoopInteger(0, 1235);
for (ZestStatement stmt : statements) {
loop.addStatement(stmt);
}
String loopString = ZestJSON.toString(loop);
ZestLoopInteger copy = (ZestLoopInteger) ZestJSON.fromString(loopString);
String copyString = ZestJSON.toString(copy);
// System.out.println("===============================");
// System.out.println(" LOOP INTEGER");
// System.out.println("===============================");
// System.out.println(copyString);
assertTrue(copyString.equals(loopString));
}
代码示例来源:origin: mozilla/zest
ZestRequest deserialisedRequest = (ZestRequest) ZestJSON.fromString(serialisation);
代码示例来源:origin: mozilla/zest
@Test
public void testSerializationLoopString() {
ZestLoopString loop = new ZestLoopString(values);
for (ZestStatement stmt : statements) {
loop.addStatement(stmt);
}
String loopString = ZestJSON.toString(loop);
// System.out.println(loopString);
ZestLoopString copy = (ZestLoopString) ZestJSON.fromString(loopString);
String copyString = ZestJSON.toString(copy);
// System.out.println("===============================");
// System.out.println(" LOOP STRING");
// System.out.println("===============================");
// System.out.println(copyString);
assertTrue(copyString.equals(loopString));
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestLoopString loop = new ZestLoopString(values);
String str = ZestJSON.toString(loop);
System.out.println(str);
ZestLoopString loop2 = (ZestLoopString) ZestJSON.fromString(str);
if (loop2.getValues().length != values.length) {
fail("The two arrays do not have same length!");
}
for (int i = 0; i < values.length; i++) {
assertTrue(
i + " expected " + values[i] + " instead of " + loop2.getValues()[i],
loop2.getValues()[i].equals(values[i]));
}
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestActionInvoke inv = new ZestActionInvoke();
inv.setVariableName("test");
inv.setCharset(StandardCharsets.UTF_8.name());
inv.setParameters(params(param("first", "AAA"), param("second", "BBB")));
inv.setScript(
ZestActionInvokeUnitTest.class.getResource("/data/simple-script.js").getPath());
String str = ZestJSON.toString(inv);
ZestActionInvoke inv2 = (ZestActionInvoke) ZestJSON.fromString(str);
assertEquals(inv.getElementType(), inv2.getElementType());
assertEquals(inv.getVariableName(), inv2.getVariableName());
assertEquals(inv.getScript(), inv2.getScript());
assertEquals(inv.getCharset(), inv2.getCharset());
assertEquals(inv.getParameters().size(), inv2.getParameters().size());
for (int i = 0; i < inv.getParameters().size(); i++) {
assertEquals(inv.getParameters().get(i).length, inv2.getParameters().get(i).length);
for (int j = 0; j < inv.getParameters().get(i).length; j++) {
assertEquals(inv.getParameters().get(i)[j], inv2.getParameters().get(i)[j]);
}
}
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestActionSleep inv = new ZestActionSleep();
inv.setMilliseconds(1000);
String str = ZestJSON.toString(inv);
ZestActionSleep inv2 = (ZestActionSleep) ZestJSON.fromString(str);
assertEquals(inv.getElementType(), inv2.getElementType());
assertEquals(inv.getMilliseconds(), inv2.getMilliseconds());
}
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSerialiseAndDeserialise() {
// Given
ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(401);
// When
String serialisation = ZestJSON.toString(statusCodeExpression);
ZestExpressionStatusCode deserialisedStatusCodeExpression =
(ZestExpressionStatusCode) ZestJSON.fromString(serialisation);
// Then
assertTrue(deserialisedStatusCodeExpression != statusCodeExpression);
assertEquals(deserialisedStatusCodeExpression.getCode(), statusCodeExpression.getCode());
assertEquals(
deserialisedStatusCodeExpression.isInverse(), statusCodeExpression.isInverse());
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSerialiseAndDeserialise() {
// Given
ZestExpressionProtocol protocolExpression = new ZestExpressionProtocol("http");
// When
String serialisation = ZestJSON.toString(protocolExpression);
ZestExpressionProtocol deserialisedProtocolExpression =
(ZestExpressionProtocol) ZestJSON.fromString(serialisation);
// Then
assertTrue(deserialisedProtocolExpression != protocolExpression);
assertEquals(
deserialisedProtocolExpression.getProtocol(), protocolExpression.getProtocol());
assertEquals(deserialisedProtocolExpression.isInverse(), protocolExpression.isInverse());
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestAssignString assign = new ZestAssignString("var", "io;hjvd9740[w9u;sdz");
String str = ZestJSON.toString(assign);
ZestAssignString assign2 = (ZestAssignString) ZestJSON.fromString(str);
assertEquals(assign.getElementType(), assign2.getElementType());
assertEquals(assign.getVariableName(), assign2.getVariableName());
assertEquals(assign.getString(), assign2.getString());
}
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestAssignStringDelimiters assign =
new ZestAssignStringDelimiters("var", "BODY", ">>", "<<");
String str = ZestJSON.toString(assign);
// System.out.println(str);
ZestAssignStringDelimiters assign2 = (ZestAssignStringDelimiters) ZestJSON.fromString(str);
assertEquals(assign.getElementType(), assign2.getElementType());
assertEquals(assign.getLocation(), assign2.getLocation());
assertEquals(assign.getPrefix(), assign2.getPrefix());
assertEquals(assign.getPostfix(), assign2.getPostfix());
}
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestClientLaunch zcl1 =
new ZestClientLaunch("htmlunit", "HtmlUnit", getServerUrl(PATH_SERVER_FILE));
String str = ZestJSON.toString(zcl1);
ZestClientLaunch zcl2 = (ZestClientLaunch) ZestJSON.fromString(str);
assertEquals(zcl1.getElementType(), zcl2.getElementType());
assertEquals(zcl1.getBrowserType(), zcl2.getBrowserType());
assertEquals(zcl1.getWindowHandle(), zcl2.getWindowHandle());
assertEquals(zcl1.getUrl(), zcl2.getUrl());
}
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestAssignReplace assign = new ZestAssignReplace("var", "aaa", "bbb", false, true);
String str = ZestJSON.toString(assign);
ZestAssignReplace assign2 = (ZestAssignReplace) ZestJSON.fromString(str);
assertEquals(assign.getElementType(), assign2.getElementType());
assertEquals(assign.getVariableName(), assign2.getVariableName());
assertEquals(assign.getReplace(), assign2.getReplace());
assertEquals(assign.getReplacement(), assign2.getReplacement());
assertEquals(assign.isCaseExact(), assign2.isCaseExact());
assertEquals(assign.isRegex(), assign2.isRegex());
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSerialiseAndDeserialise() {
// Given
ZestClientScreenshot original =
new ZestClientScreenshot("windowHandle", "/path", "variableName");
original.setEnabled(false);
// When
String serialisation = ZestJSON.toString(original);
ZestClientScreenshot deserialised =
(ZestClientScreenshot) ZestJSON.fromString(serialisation);
// Then
assertEquals(deserialised.getElementType(), original.getElementType());
assertEquals(deserialised.getWindowHandle(), original.getWindowHandle());
assertEquals(deserialised.getFilePath(), original.getFilePath());
assertEquals(deserialised.getVariableName(), original.getVariableName());
assertEquals(deserialised.isEnabled(), original.isEnabled());
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestClientLaunch zcl1 =
new ZestClientLaunch(
"htmlunit", "HtmlUnit", getServerUrl(PATH_SERVER_FILE), false, "/profile");
String str = ZestJSON.toString(zcl1);
ZestClientLaunch zcl2 = (ZestClientLaunch) ZestJSON.fromString(str);
assertEquals(zcl1.getElementType(), zcl2.getElementType());
assertEquals(zcl1.getBrowserType(), zcl2.getBrowserType());
assertEquals(zcl1.getWindowHandle(), zcl2.getWindowHandle());
assertEquals(zcl1.getUrl(), zcl2.getUrl());
assertEquals(zcl1.isHeadless(), zcl2.isHeadless());
assertEquals(zcl1.getProfilePath(), zcl2.getProfilePath());
}
代码示例来源:origin: mozilla/zest
@Test
public void testSerialization() {
ZestAssignFromElement fromElement =
new ZestAssignFromElement("Var")
.whereElementIs("form")
.atIndex(1)
.selectAttributeValue("action");
String str = ZestJSON.toString(fromElement);
ZestAssignFromElement fromElement2 = (ZestAssignFromElement) ZestJSON.fromString(str);
assertEquals(fromElement.getElementType(), fromElement2.getElementType());
assertEquals(fromElement.getVariableName(), fromElement2.getVariableName());
assertEquals(fromElement.getAttributeNameFilter(), fromElement2.getAttributeNameFilter());
assertEquals(fromElement.getAttributeValueFilter(), fromElement2.getAttributeValueFilter());
assertEquals(fromElement.getElementNameFilter(), fromElement2.getElementNameFilter());
assertEquals(
fromElement.getReturnedAttributeName(), fromElement2.getReturnedAttributeName());
assertEquals(
fromElement.getAttributeValueFilterFlags(),
fromElement2.getAttributeValueFilterFlags());
assertEquals(fromElement.getElementIndex(), fromElement2.getElementIndex());
assertEquals(
fromElement.areFilteredElementsReversed(),
fromElement2.areFilteredElementsReversed());
assertEquals(fromElement.isReturningAttribute(), fromElement2.isReturningAttribute());
assertEquals(fromElement.isReturningElement(), fromElement2.isReturningElement());
assertEquals(fromElement.isFilteredByAttribute(), fromElement2.isFilteredByAttribute());
assertEquals(fromElement.isFilteredByElementName(), fromElement2.isFilteredByElementName());
}
内容来源于网络,如有侵权,请联系作者删除!