Best Webtau code snippet using org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder.matcher
Source:ConsoleStepReporter.java
1/*2 * Copyright 2020 webtau maintainers3 * Copyright 2019 TWO SIGMA OPEN SOURCE, LLC4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17package org.testingisdocumenting.webtau.reporter;18import org.testingisdocumenting.webtau.console.ConsoleOutputs;19import org.testingisdocumenting.webtau.console.IndentedConsoleOutput;20import org.testingisdocumenting.webtau.console.ansi.Color;21import org.testingisdocumenting.webtau.utils.StringUtils;22import org.testingisdocumenting.webtau.utils.TimeUtils;23import java.util.function.Supplier;24import java.util.stream.Stream;25public class ConsoleStepReporter implements StepReporter {26 private final TokenizedMessageToAnsiConverter toAnsiConverter;27 private final Supplier<Integer> verboseLevelSupplier;28 public ConsoleStepReporter(TokenizedMessageToAnsiConverter toAnsiConverter, Supplier<Integer> verboseLevelSupplier) {29 this.toAnsiConverter = toAnsiConverter;30 this.verboseLevelSupplier = verboseLevelSupplier;31 }32 @Override33 public void onStepStart(WebTauStep step) {34 executeIfWithinVerboseLevel(step, () -> printStepStart(step));35 }36 @Override37 public void onStepSuccess(WebTauStep step) {38 executeIfWithinVerboseLevel(step, () -> printStepSuccess(step));39 }40 @Override41 public void onStepFailure(WebTauStep step) {42 executeIfWithinVerboseLevel(step, () -> printStepFailure(step));43 }44 @Override45 public void onStepRepeatStart(WebTauStep step, int current, int total) {46 executeIfWithinVerboseLevel(step, () -> printStepRepeatStart(step, current, total));47 }48 @Override49 public void onStepRepeatSuccess(WebTauStep step, int current, int total) {50 executeIfWithinVerboseLevel(step, () -> printStepRepeatSuccess(step, current, total));51 }52 @Override53 public void onStepRepeatFailure(WebTauStep step, int current, int total) {54 executeIfWithinVerboseLevel(step, () -> printStepRepeatFailure(step, current, total));55 }56 private void printStepStart(WebTauStep step) {57 ConsoleOutputs.out(58 Stream.concat(59 Stream.concat(60 stepStartBeginningStream(step),61 personaStream(step)),62 toAnsiConverter.convert(step.getInProgressMessage()).stream()63 ).toArray());64 printStepInput(step);65 }66 private void printStepSuccess(WebTauStep step) {67 TokenizedMessage completionMessage = step.getCompletionMessage();68 TokenizedMessage completionMessageToUse = isLastTokenMatcher(completionMessage) ?69 completionMessage.subMessage(0, completionMessage.getNumberOfTokens() - 1)70 .add(reAlignText(step.getNumberOfParents() + 2, completionMessage.getLastToken())) :71 completionMessage;72 printStepOutput(step);73 ConsoleOutputs.out(Stream.concat(Stream.concat(Stream.concat(stepSuccessBeginningStream(step), personaStream(step)),74 toAnsiConverter.convert(completionMessageToUse).stream()),75 timeTakenTokenStream(step)).toArray());76 }77 private void printStepFailure(WebTauStep step) {78 TokenizedMessage completionMessageToUse = messageTokensForFailedStep(step);79 printStepOutput(step);80 ConsoleOutputs.out(Stream.concat(Stream.concat(Stream.concat(stepFailureBeginningStream(step), personaStream(step)),81 toAnsiConverter.convert(completionMessageToUse).stream()),82 timeTakenTokenStream(step)).toArray());83 }84 private void printStepRepeatStart(WebTauStep step, int currentIdx, int total) {85 ConsoleOutputs.out(Stream.concat(stepStartBeginningStream(step),86 stepCurrentIdxOfTotalStream(currentIdx, total)).toArray());87 }88 private void printStepRepeatSuccess(WebTauStep step, int currentIdx, int total) {89 ConsoleOutputs.out(Stream.concat(stepSuccessBeginningStream(step),90 Stream.concat(91 stepCurrentIdxOfTotalStream(currentIdx, total),92 timeTakenTokenStream(step))).toArray());93 }94 private void printStepRepeatFailure(WebTauStep step, int currentIdx, int total) {95 printStepFailure(step);96 }97 private Stream<Object> stepStartBeginningStream(WebTauStep step) {98 return Stream.of(createIndentation(step.getNumberOfParents()), Color.YELLOW, "> ");99 }100 private Stream<Object> stepSuccessBeginningStream(WebTauStep step) {101 return Stream.of(createIndentation(step.getNumberOfParents()), Color.GREEN, ". ");102 }103 private Stream<Object> stepFailureBeginningStream(WebTauStep step) {104 return Stream.of(createIndentation(step.getNumberOfParents()), Color.RED, "X ");105 }106 private Stream<Object> stepCurrentIdxOfTotalStream(int currentIdx, int total) {107 return Stream.of(Color.BLUE, currentIdx + 1, Color.YELLOW, "/", Color.BLUE, total);108 }109 private Stream<Object> timeTakenTokenStream(WebTauStep step) {110 return Stream.of(Color.YELLOW, " (", Color.GREEN, renderTimeTaken(step), Color.YELLOW, ')');111 }112 private String renderTimeTaken(WebTauStep step) {113 return TimeUtils.renderMillisHumanReadable(step.getElapsedTime());114 }115 private void printStepInput(WebTauStep step) {116 if (skipRenderRequestResponse()) {117 return;118 }119 step.getInput().prettyPrint(createIndentedConsoleOutput(step));120 }121 private void printStepOutput(WebTauStep step) {122 if (skipRenderRequestResponse()) {123 return;124 }125 step.getOutput().prettyPrint(createIndentedConsoleOutput(step));126 }127 private IndentedConsoleOutput createIndentedConsoleOutput(WebTauStep step) {128 return new IndentedConsoleOutput(ConsoleOutputs.asCombinedConsoleOutput(),129 numberOfSpacedForIndentLevel(step.getNumberOfParents() + 1));130 }131 private boolean skipRenderRequestResponse() {132 return verboseLevelSupplier.get() <= WebTauStep.getCurrentStep().getNumberOfParents() + 1;133 }134 private TokenizedMessage messageTokensForFailedStep(WebTauStep step) {135 TokenizedMessage completionMessage = step.getCompletionMessage();136 int numberOfParents = step.getNumberOfParents();137 boolean isLastTokenError = isLastTokenError(completionMessage);138 if (!isLastTokenError) {139 return completionMessage;140 }141 if (step.hasFailedChildrenSteps() && !skipRenderRequestResponse()) {142 // we don't render children errors one more time in case this step has failed children steps143 // last two tokens of a message are delimiter and error tokens144 // so we remove them145 return completionMessage.subMessage(0, completionMessage.getNumberOfTokens() - 2);146 }147 return completionMessage.subMessage(0, completionMessage.getNumberOfTokens() - 1)148 .add(reAlignText(numberOfParents + 2, completionMessage.getLastToken()));149 }150 private Stream<Object> personaStream(WebTauStep step) {151 if (step.getPersonaId().isEmpty()) {152 return Stream.empty();153 }154 return Stream.of(Color.YELLOW, step.getPersonaId(), " ", Color.RESET);155 }156 private MessageToken reAlignText(int indentLevel, MessageToken token) {157 if (token.getValue() == null) {158 return token;159 }160 String text = token.getValue().toString();161 return new MessageToken(token.getType(),162 StringUtils.indentAllLinesButFirst(createIndentation(indentLevel), text));163 }164 private boolean isLastTokenMatcher(TokenizedMessage completionMessage) {165 return completionMessage.getLastToken().getType().equals(166 IntegrationTestsMessageBuilder.TokenTypes.MATCHER.getType());167 }168 private boolean isLastTokenError(TokenizedMessage completionMessage) {169 return completionMessage.getLastToken().getType().equals(170 IntegrationTestsMessageBuilder.TokenTypes.ERROR.getType());171 }172 private String createIndentation(int indentLevel) {173 return StringUtils.createIndentation(numberOfSpacedForIndentLevel(indentLevel));174 }175 private int numberOfSpacedForIndentLevel(int indentLevel) {176 return indentLevel * 2;177 }178 private void executeIfWithinVerboseLevel(WebTauStep step, Runnable code) {179 int currentLevel = step.getNumberOfParents() + 1;180 if (currentLevel <= verboseLevelSupplier.get()) {181 code.run();182 }183 }184}...
Source:ActualValue.java
...117 if (flow != Flow.Terminate) {118 throw new AssertionError("\n" + message);119 }120 }121 private String mismatchMessage(ValueMatcher matcher, boolean isNegative) {122 return isNegative ?123 matcher.negativeMismatchedMessage(actualPath, actual):124 matcher.mismatchedMessage(actualPath, actual);125 }126 private static ActualPath extractPath(Object actual) {127 return (actual instanceof ActualPathAndDescriptionAware) ?128 (((ActualPathAndDescriptionAware) actual).actualPath()):129 createActualPath("[value]");130 }131 private static TokenizedMessage extractDescription(Object actual, ActualPath path) {132 return (actual instanceof ActualPathAndDescriptionAware) ?133 (((ActualPathAndDescriptionAware) actual).describe()):134 TokenizedMessage.tokenizedMessage(IntegrationTestsMessageBuilder.id(path.getPath()));135 }136 private Object extractActualValue(Object actual) {137 if (actual instanceof ActualValueAware) {138 return ((ActualValueAware) actual).actualValue();139 }140 return actual;141 }142 private static void executeStep(Object value, TokenizedMessage elementDescription,143 ValueMatcher valueMatcher, boolean isNegative,144 TokenizedMessage messageStart, Runnable expectationValidation,145 StepReportOptions stepReportOptions) {146 WebTauStep step = createStep(147 messageStart.add(elementDescription)148 .add(matcher(isNegative ? valueMatcher.negativeMatchingMessage() : valueMatcher.matchingMessage())),149 () -> tokenizedMessage(elementDescription)150 .add(matcher(isNegative ?151 valueMatcher.negativeMatchedMessage(null, value) :152 valueMatcher.matchedMessage(null, value))),153 expectationValidation);154 step.execute(stepReportOptions);155 }156}...
Source:CliForegroundCommand.java
1/*2 * Copyright 2020 webtau maintainers3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package org.testingisdocumenting.webtau.cli;17import org.testingisdocumenting.webtau.cli.expectation.CliValidationExitCodeOutputHandler;18import org.testingisdocumenting.webtau.cli.expectation.CliValidationOutputOnlyHandler;19import org.testingisdocumenting.webtau.expectation.ActualPath;20import org.testingisdocumenting.webtau.expectation.ExpectationHandler;21import org.testingisdocumenting.webtau.expectation.ExpectationHandlers;22import org.testingisdocumenting.webtau.expectation.ValueMatcher;23import org.testingisdocumenting.webtau.reporter.StepReportOptions;24import org.testingisdocumenting.webtau.reporter.WebTauStep;25import java.util.function.Consumer;26import static org.testingisdocumenting.webtau.Matchers.equal;27import static org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder.action;28import static org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder.stringValue;29import static org.testingisdocumenting.webtau.reporter.TokenizedMessage.tokenizedMessage;30public class CliForegroundCommand {31 CliForegroundCommand() {32 }33 public CliRunResult run(String command, CliProcessConfig config, CliValidationOutputOnlyHandler handler) {34 return cliStep(command, config, (validationResult) -> handler.handle(35 validationResult.getOut(),36 validationResult.getErr()));37 }38 public CliRunResult run(String command, CliProcessConfig config, CliValidationExitCodeOutputHandler handler) {39 return cliStep(command, config,40 (validationResult) -> handler.handle(41 validationResult.getExitCode(),42 validationResult.getOut(),43 validationResult.getErr()));44 }45 private CliRunResult cliStep(String command, CliProcessConfig config, Consumer<CliValidationResult> validationCode) {46 CliValidationResult validationResult = new CliValidationResult(command);47 validationResult.setConfig(config);48 WebTauStep step = WebTauStep.createStep(49 tokenizedMessage(action("running cli command "), stringValue(command)),50 () -> tokenizedMessage(action("ran cli command"), stringValue(command)),51 () -> runAndValidate(validationResult, command, config, validationCode));52 try {53 step.setInput(config.createStepInput());54 step.setOutputSupplier(() -> validationResult);55 step.execute(StepReportOptions.REPORT_ALL);56 return new CliRunResult(command,57 validationResult.getExitCode().get(),58 validationResult.getOut().get(),59 validationResult.getErr().get());60 } finally {61 Cli.cli.setLastDocumentationArtifact(validationResult.createDocumentationArtifact());62 }63 }64 private void runAndValidate(CliValidationResult validationResult,65 String command,66 CliProcessConfig config,67 Consumer<CliValidationResult> validationCode) {68 try {69 long startTime = System.currentTimeMillis();70 ProcessRunResult runResult = ProcessUtils.run(command, config);71 long endTime = System.currentTimeMillis();72 if (!runResult.isTimeOut()) {73 validationResult.setExitCode(exitCode(runResult.getExitCode()));74 }75 validationResult.setOut(runResult.getOutput());76 validationResult.setErr(runResult.getError());77 validationResult.setStartTime(startTime);78 validationResult.setElapsedTime(endTime - startTime);79 if (runResult.isTimeOut()) {80 throw new RuntimeException("process timed-out");81 }82 if (runResult.getErrorReadingException() != null) {83 throw runResult.getErrorReadingException();84 }85 if (runResult.getOutputReadingException() != null) {86 throw runResult.getOutputReadingException();87 }88 ExpectationHandler recordAndThrowHandler = new ExpectationHandler() {89 @Override90 public Flow onValueMismatch(ValueMatcher valueMatcher, ActualPath actualPath, Object actualValue, String message) {91 validationResult.addMismatch(message);92 return ExpectationHandler.Flow.PassToNext;93 }94 };95 ExpectationHandlers.withAdditionalHandler(recordAndThrowHandler, () -> {96 validationCode.accept(validationResult);97 validateExitCode(validationResult);98 return null;99 });100 } catch (AssertionError e) {101 throw e;102 } catch (Throwable e) {103 validationResult.setErrorMessage(e.getMessage());104 throw new CliException(e.getMessage(), e);105 }106 }107 private static void validateExitCode(CliValidationResult validationResult) {108 if (validationResult.getExitCode().isChecked()) {109 return;110 }111 validationResult.getExitCode().should(equal(0));112 }113 private CliExitCode exitCode(int exitCode) {114 return new CliExitCode(exitCode);115 }116}...
matcher
Using AI Code Generation
1import org.testingisdocumenting.webtau.Ddjt;2import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;3import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;4import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;5public class 1 {6 public static void main(String[] args) {7 String str = "google";8 IntegrationTestsMessageBuilder msg = Ddjt.msg("verify that the url contains " + str);9 msg.matcher(url).contains(str);10 }11}12import org.testingisdocumenting.webtau.Ddjt;13import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;14import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;15import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;16public class 2 {17 public static void main(String[] args) {18 String str = "google";19 IntegrationTestsMessageBuilder msg = Ddjt.msg("verify that the url does not contain " + str);20 msg.matcher(url).not().contains(str);21 }22}23import org.testingisdocumenting.webtau.Ddjt;24import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;25import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;26import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;27public class 3 {28 public static void main(String[] args) {29 String str = "google";
matcher
Using AI Code Generation
1package org.testingisdocumenting.webtau.reporter;2import org.junit.Test;3public class IntegrationTestsMessageBuilderTest {4 public void test() {5 IntegrationTestsMessageBuilder builder = new IntegrationTestsMessageBuilder();6 System.out.println(builder.matcher("abc", "abc"));7 }8}9package org.testingisdocumenting.webtau.reporter;10import org.junit.Test;11public class IntegrationTestsMessageBuilderTest {12 public void test() {13 IntegrationTestsMessageBuilder builder = new IntegrationTestsMessageBuilder();14 System.out.println(builder.matcher("abc", "abc"));15 }16}17package org.testingisdocumenting.webtau.reporter;18import org.junit.Test;19public class IntegrationTestsMessageBuilderTest {20 public void test() {21 IntegrationTestsMessageBuilder builder = new IntegrationTestsMessageBuilder();22 System.out.println(builder.matcher("abc", "abc"));23 }24}25package org.testingisdocumenting.webtau.reporter;26import org.junit.Test;27public class IntegrationTestsMessageBuilderTest {28 public void test() {29 IntegrationTestsMessageBuilder builder = new IntegrationTestsMessageBuilder();30 System.out.println(builder.matcher("abc", "abc"));31 }32}33package org.testingisdocumenting.webtau.reporter;34import org.junit.Test;35public class IntegrationTestsMessageBuilderTest {36 public void test() {37 IntegrationTestsMessageBuilder builder = new IntegrationTestsMessageBuilder();38 System.out.println(builder.matcher("abc", "abc"));39 }40}41package org.testingisdocumenting.webtau.reporter;42import org.junit.Test;43public class IntegrationTestsMessageBuilderTest {44 public void test() {
matcher
Using AI Code Generation
1package org.testingisdocumenting.webtau.reporter;2import org.testingisdocumenting.webtau.Ddjt;3public class Test1 {4 public static void main(String[] args) {5 Ddjt.createTest("test1", () -> {6 Ddjt.reporter().matcher("matcher1", "actual1", "expected1");7 }).run();8 }9}10package org.testingisdocumenting.webtau.reporter;11import org.testingisdocumenting.webtau.Ddjt;12public class Test2 {13 public static void main(String[] args) {14 Ddjt.createTest("test2", () -> {15 Ddjt.reporter().matcher("matcher2", "actual2", "expected2");16 }).run();17 }18}19package org.testingisdocumenting.webtau.reporter;20import org.testingisdocumenting.webtau.Ddjt;21public class Test3 {22 public static void main(String[] args) {23 Ddjt.createTest("test3", () -> {24 Ddjt.reporter().matcher("matcher3", "actual3", "expected3");25 }).run();26 }27}
matcher
Using AI Code Generation
1public class App {2 public static void main(String[] args) {3 WebTauDsl.createTest("test", () -> {4 WebTauDsl.http.get("/hello");5 WebTauDsl.http.get("/hello").should(equal(200));6 WebTauDsl.http.get("/hello").should(equal(200)).should(equal(200));7 WebTauDsl.http.get("/hello").should(equal(200)).should(equal(200)).should(equal(200));8 WebTauDsl.http.get("/hello").should(equal(200)).should(equal(200)).should(equal(200)).should(equal(200));9 WebTauDsl.http.get("/hello").should(equal(200)).should(equal(200)).should(equal(200)).should(equal(200)).should(equal(200));10 WebTauDsl.http.get("/hello").should(equal(200)).should(equal(200)).should(equal(200)).should(equal(200)).should(equal(200)).should(equal(200));
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!