How to use VisualTestingTask method of com.testsigma.tasks.VisualTestingTask class

Best Testsigma code snippet using com.testsigma.tasks.VisualTestingTask.VisualTestingTask

Source:TestCaseResultService.java Github

copy

Full Screen

...13import com.testsigma.mapper.TestCaseResultMapper;14import com.testsigma.mapper.TestDataProfileMapper;15import com.testsigma.model.*;16import com.testsigma.repository.TestCaseResultRepository;17import com.testsigma.tasks.VisualTestingTask;18import com.testsigma.web.request.TestCaseResultRequest;19import com.testsigma.web.request.TestStepResultRequest;20import lombok.RequiredArgsConstructor;21import lombok.extern.log4j.Log4j2;22import org.apache.commons.lang3.ObjectUtils;23import org.springframework.beans.factory.annotation.Autowired;24import org.springframework.context.annotation.Lazy;25import org.springframework.data.domain.Page;26import org.springframework.data.domain.Pageable;27import org.springframework.data.jpa.domain.Specification;28import org.springframework.stereotype.Service;29import java.io.UnsupportedEncodingException;30import java.sql.Timestamp;31import java.util.List;32import java.util.Map;33@Service34@Log4j235@RequiredArgsConstructor(onConstructor = @__({@Autowired, @Lazy}))36public class TestCaseResultService {37 private final TestCaseResultRepository testCaseResultRepository;38 private final TestCaseResultMapper testCaseResultMapper;39 private final TestStepResultService testStepResultService;40 private final TestDataProfileService testDataProfileService;41 private final TestDataProfileMapper testDataProfileMapper;42 private final TestSuiteResultService testSuiteResultService;43 private final TestDeviceResultService testDeviceResultService;44 private final TestPlanResultService testPlanResultService;45 private final VisualTestingService visualTestingService;46 private final StorageConfigService storageConfigService;47 public Page<TestCaseResult> findAll(Specification<TestCaseResult> spec, Pageable pageable) {48 return this.testCaseResultRepository.findAll(spec, pageable);49 }50 public List<TestCaseResult> findAllBytestPlanResultId(Long testPlanResultId) {51 return this.testCaseResultRepository.findAllBytestPlanResultId(testPlanResultId);52 }53 public Timestamp findMinTimeStampByEnvironmentResultId(Long environmentResultId) {54 return this.testCaseResultRepository.findMinTimeStampByEnvironmentResultId(environmentResultId);55 }56 public List<TestCaseResult> findActiveSuiteTestCaseResults(Long suiteResultId, StatusConstant status) {57 return this.testCaseResultRepository.findByActiveSuiteTestCaseResults(suiteResultId, status);58 }59 public List<TestCaseResult> findAllByParentIdAndStatus(Long parentId, StatusConstant status) {60 return this.testCaseResultRepository.findAllByParentIdAndStatus(parentId, status);61 }62 public List<TestCaseResult> findAllBySuiteResultIdAndResultIsNot(Long testSuiteResultId, ResultConstant result) {63 return this.testCaseResultRepository.findAllBySuiteResultIdAndResultIsNot(testSuiteResultId, result);64 }65 public List<TestCaseResult> findAllBySuiteResultId(Long suiteResultId) {66 return this.testCaseResultRepository.findAllBySuiteResultId(suiteResultId);67 }68 public List<TestCaseResult> findAllBySuiteResultIdAndTestCaseId(Long suiteResultId, Long preRequisite) {69 return this.testCaseResultRepository.findAllBySuiteResultIdAndTestCaseId(suiteResultId, preRequisite);70 }71 public List<TestCaseResult> findByTestCaseResultIds(List<Long> testCaseResultIds) {72 return this.testCaseResultRepository.findAllById(testCaseResultIds);73 }74 public List<TestCaseResult> findAllByEnvironmentResultId(Long environmentResultId) {75 return testCaseResultRepository.findAllByEnvironmentResultId(environmentResultId);76 }77 private List<TestCaseResult> findAllBySuiteResultIdAndIsVisuallyPassed(Long suiteResultId) {78 return this.testCaseResultRepository.findAllBySuiteResultIdAndIsVisuallyPassed(suiteResultId, false);79 }80 public TestCaseResult find(Long testCaseResultId) throws ResourceNotFoundException {81 return testCaseResultRepository.findById(testCaseResultId)82 .orElseThrow(() -> new ResourceNotFoundException(83 "TestCaseResult Resource not found with id:" + testCaseResultId));84 }85 public Integer countAllBySuiteResultIdAndStatusIsNot(Long testSuiteResultId, StatusConstant status) {86 return testCaseResultRepository.countAllBySuiteResultIdAndStatusIsNot(testSuiteResultId, status);87 }88 public ResultConstant findBySuiteResultIdAndMaxResult(Long testSuiteResultId) {89 return testCaseResultRepository.findMaximumResultBySuiteId(testSuiteResultId);90 }91 public TestCaseResult create(TestCaseResult testCaseResult) {92 return this.testCaseResultRepository.save(testCaseResult);93 }94 public TestCaseResult update(TestCaseResult testCaseResult) {95 return testCaseResultRepository.save(testCaseResult);96 }97 public void updateResultByEnvironmentId(ResultConstant result, StatusConstant status, String message, Long duration,98 Timestamp startTime, Timestamp endTime, Long environmentRunId,99 StatusConstant statusConstant) {100 log.info(String.format("Updating test cases with result - %s, status - %s, message - %s" +101 "with environment result id - %s and status in %s", result, status, message, environmentRunId, statusConstant));102 testCaseResultRepository.updateTestCaseResultByEnvironmentId(result, status, message, duration, startTime, endTime,103 environmentRunId, statusConstant);104 }105 public void updateResultByTestSuiteId(ResultConstant result, StatusConstant status, String message, Long duration,106 Timestamp startTime, Timestamp endTime, Long testSuiteResultId,107 StatusConstant statusConstant) {108 log.info(String.format("Updating test cases with result - %s, status - %s, message - %s" +109 "with test suite result id - %s and status in %s", result, status, message, testSuiteResultId, statusConstant));110 testCaseResultRepository.updateTestCaseResultBySuiteResultId(result, status, message, duration, startTime, endTime,111 testSuiteResultId, statusConstant);112 }113 public void updateResult(TestCaseResultRequest testCaseResultRequest) throws ResourceNotFoundException,114 TestsigmaDatabaseException, UnsupportedEncodingException {115 TestCaseResult testCaseResult = find(testCaseResultRequest.getId());116 if (testCaseResultRequest.getResult() == null || testCaseResultRequest.getResult().equals(ResultConstant.QUEUED)) {117 this.updateTestCaseSteps(testCaseResultRequest);118 this.updateResultCounts(testCaseResult);119 } else {120 this.updateTestCaseSteps(testCaseResultRequest);121 testCaseResultMapper.merge(testCaseResultRequest, testCaseResult);122 testCaseResult.setStatus(StatusConstant.STATUS_COMPLETED);123 update(testCaseResult);124 if (testCaseResultRequest.isVisualTestingEnabled() && !storageConfigService.getStorageConfig().getStorageType().equals(StorageType.ON_PREMISE))125 initiateScreenshotAnalysis(testCaseResult);126 if (!testCaseResult.getIsDataDriven())127 updateResultCounts(testCaseResult);128 if (testCaseResult.getParentId() != null) {129 updateIterationResultCount(testCaseResult.getParentResult());130 }131 testSuiteResultService.updateResultCounts(testCaseResult.getSuiteResultId());132 testDeviceResultService.updateResultCounts(testCaseResult.getEnvironmentResultId());133 }134 }135 public void updateTestCaseSteps(TestCaseResultRequest testCaseResultRequest) throws TestsigmaDatabaseException,136 UnsupportedEncodingException,137 ResourceNotFoundException {138 TestDataSet testDataSet = null;139 TestData testData = null;140 Map<String, TestDataSet> testDataSetList;141 if (testCaseResultRequest.getTestDataId() != null) {142 testData = testDataProfileService.find(testCaseResultRequest.getTestDataId());143 testDataSetList = testDataProfileMapper.map(testData);144 if (!testDataSetList.isEmpty()) {145 testDataSet = testDataSetList.get(testCaseResultRequest.getTestDataSetName());146 }147 }148 List<TestStepResultRequest> testCaseStepResultList = testCaseResultRequest.getTestCaseStepResults();149 if (!testCaseStepResultList.isEmpty()) {150 if (testCaseResultRequest.getCurrentIndex() == 0) {151 Integer removedSteps = testStepResultService.deleteByTestCaseResultIdAndEnvironmentResultId(152 testCaseResultRequest.getId(), testCaseResultRequest.getEnvRunId());153 }154 testStepResultService.createTestCaseSteps(testCaseResultRequest, testData, testDataSet);155 } else {156 log.info("There are no test step results in this test case result[" + testCaseResultRequest.getId() + "]...");157 }158 }159 public void updateParentResult(TestCaseResult result) throws Exception {160 TestCaseResult parentTestCaseResult = find(result.getParentId());161 if (result.getResult() == ResultConstant.QUEUED) {162 parentTestCaseResult.setResult(result.getResult());163 parentTestCaseResult.setStatus(StatusConstant.STATUS_IN_PROGRESS);164 parentTestCaseResult.setMessage(result.getMessage());165 parentTestCaseResult.setEndTime(new Timestamp(System.currentTimeMillis()));166 parentTestCaseResult.setDuration(0L);167 } else {168 Integer pendingTestCaseResultCount = testCaseResultRepository.countAllByParentIdAndStatusIsNot(169 parentTestCaseResult.getId(), StatusConstant.STATUS_COMPLETED);170 if (pendingTestCaseResultCount == 0) {171 ResultConstant maxResult =172 testCaseResultRepository.findMaximumResultByParentId(parentTestCaseResult.getId());173 Timestamp endTime = testCaseResultRepository.findMaximumEndTimeByParentId(parentTestCaseResult.getId());174 Timestamp startTime = testCaseResultRepository.findMinimumStartTimeByParentId(parentTestCaseResult.getId());175 startTime = ObjectUtils.defaultIfNull(startTime, result.getStartTime());176 endTime = ObjectUtils.defaultIfNull(endTime, result.getEndTime());177 parentTestCaseResult.setResult(maxResult);178 parentTestCaseResult.setStatus(StatusConstant.STATUS_COMPLETED);179 parentTestCaseResult.setMessage(result.getMessage());180 parentTestCaseResult.setStartTime(startTime);181 parentTestCaseResult.setEndTime(endTime);182 parentTestCaseResult.setDuration(startTime.getTime() - endTime.getTime());183 }184 }185 update(parentTestCaseResult);186 updateIterationResultCount(parentTestCaseResult);187 }188 public void updateResultCounts(TestCaseResult testCaseResult) {189 log.info("Updating result counts for test case result - " + testCaseResult.getId());190 this.testCaseResultRepository.updateTotalTestCaseResultsCount(testCaseResult.getId());191 this.testCaseResultRepository.updatePassedTestCaseResultsCount(testCaseResult.getId());192 this.testCaseResultRepository.updateFailedTestCaseResultsCount(testCaseResult.getId());193 this.testCaseResultRepository.updateAbortedTestCaseResultsCount(testCaseResult.getId());194 this.testCaseResultRepository.updateNotExecutedTestCaseResultsCount(testCaseResult.getId());195 this.testCaseResultRepository.updateQueuedTestCaseResultsCount(testCaseResult.getId());196 this.testCaseResultRepository.updateStoppedTestCaseResultsCount(testCaseResult.getId());197 this.testPlanResultService.updateResultCounts(testCaseResult.getTestPlanResult());198 }199 public void updateIterationResultCount(TestCaseResult testCaseResult) {200 log.info("Updating iteration result counts for test case result - " + testCaseResult.getId());201 this.testCaseResultRepository.updateIterationTotalTestCaseResultsCount(testCaseResult.getId());202 this.testCaseResultRepository.updateIterationPassedTestCaseResultsCount(testCaseResult.getId());203 this.testCaseResultRepository.updateIterationFailedTestCaseResultsCount(testCaseResult.getId());204 this.testCaseResultRepository.updateIterationAbortedTestCaseResultsCount(testCaseResult.getId());205 this.testCaseResultRepository.updateIterationNotExecutedTestCaseResultsCount(testCaseResult.getId());206 this.testCaseResultRepository.updateIterationQueuedTestCaseResultsCount(testCaseResult.getId());207 this.testCaseResultRepository.updateIterationStoppedTestCaseResultsCount(testCaseResult.getId());208 }209 public void propagateVisualResult(TestCaseResult testCaseResult) throws ResourceNotFoundException {210 TestCaseResult result = testCaseResult;211 if (testCaseResult.getParentId() != null) {212 result = find(testCaseResult.getParentId());213 updateVisualResult(result, true);214 }215 List<TestCaseResult> failedList = findAllBySuiteResultIdAndIsVisuallyPassed(result.getSuiteResultId());216 TestSuiteResult testSuiteResult = testSuiteResultService.find(result.getSuiteResultId());217 testSuiteResultService.updateVisualResult(testSuiteResult, failedList.isEmpty());218 List<TestSuiteResult> pendingList = testSuiteResultService.findAllByEnvironmentResultIdAndIsVisuallyPassedIsNull(testSuiteResult.getEnvironmentResultId());219 if (pendingList.isEmpty()) {220 testSuiteResultService.propagateVisualResult(testSuiteResult);221 }222 }223 public void updateVisualResult(TestCaseResult testCaseResult, boolean isVisuallyPassed) {224 this.testCaseResultRepository.updateVisualResult(testCaseResult.getId(), isVisuallyPassed);225 }226 public void markTestCaseResultAsInProgress(TestCaseResult testCaseResult) throws ResourceNotFoundException {227 log.info(String.format("Updating test case result with status - %s, message - %s with id %s",228 StatusConstant.STATUS_IN_PROGRESS, AutomatorMessages.MSG_EXECUTION_IN_PROGRESS, testCaseResult.getId()));229 testCaseResult.setStatus(StatusConstant.STATUS_IN_PROGRESS);230 testCaseResult.setMessage(AutomatorMessages.MSG_EXECUTION_IN_PROGRESS);231 testCaseResult.setStartTime(new Timestamp(java.lang.System.currentTimeMillis()));232 testCaseResultRepository.save(testCaseResult);233 if (testCaseResult.getParentId() != null) {234 TestCaseResult parentTestCaseResult = this.find(testCaseResult.getParentId());235 if (parentTestCaseResult.getStatus() != StatusConstant.STATUS_IN_PROGRESS) {236 log.info(String.format("Updating test case result(parent) with status - %s, message - %s with id %s",237 StatusConstant.STATUS_IN_PROGRESS, AutomatorMessages.MSG_EXECUTION_IN_PROGRESS, parentTestCaseResult.getId()));238 parentTestCaseResult.setStatus(StatusConstant.STATUS_IN_PROGRESS);239 parentTestCaseResult.setMessage(AutomatorMessages.MSG_EXECUTION_IN_PROGRESS);240 this.update(parentTestCaseResult);241 }242 }243 }244 public void stopIncompleteTestCaseResults(ResultConstant result, StatusConstant status,245 String message, Long duration, Timestamp startTime,246 Timestamp endTime, Long environmentRunId,247 StatusConstant notInStatus) {248 log.info(String.format("Updating test cases with result - %s, status - %s, message - %s" +249 "with environment result id - %s and status not in %s", result, status, message, environmentRunId, notInStatus));250 testCaseResultRepository.stopIncompleteTestCaseResults(result, status, message, duration, startTime,251 endTime, environmentRunId, notInStatus);252 testStepResultService.stopIncompleteTestStepResults(result, message, duration, startTime,253 endTime, environmentRunId);254 List<TestCaseResult> testCaseResults = testCaseResultRepository.findAllByEnvironmentResultId(environmentRunId);255 testCaseResults.forEach(testCaseResult -> {256 updateResultCounts(testCaseResult);257 });258 }259 public void stopTestCaseResultsByEnvironmentResult(String message, ResultConstant result, Long environmentRunId) {260 log.info(String.format("Updating test cases with result - %s, message - %s with environment result id %s",261 result, message, environmentRunId));262 Timestamp currentTime = new Timestamp(java.lang.System.currentTimeMillis());263 testCaseResultRepository.updateResultForStopped(result, message, currentTime, currentTime,264 0L, environmentRunId);265 }266 private void initiateScreenshotAnalysis(TestCaseResult result) {267 try {268 new VisualTestingTask(result, visualTestingService).start();269 } catch (Exception e) {270 log.error("Error in screenshot comparison/analysis", e);271 }272 }273 public void updateResultData(TestCaseResultRequest testCaseResultRequest) throws ResourceNotFoundException {274 TestCaseResult testCaseResult = find(testCaseResultRequest.getId());275 testCaseResultMapper.merge(testCaseResultRequest, testCaseResult);276 update(testCaseResult);277 }278}...

Full Screen

Full Screen

Source:VisualTestingTask.java Github

copy

Full Screen

...10import com.testsigma.model.TestCaseResult;11import com.testsigma.service.VisualTestingService;12import lombok.extern.log4j.Log4j2;13@Log4j214public class VisualTestingTask extends Thread {15 private final TestCaseResult testCaseResult;16 private final VisualTestingService visualTestingService;17 public VisualTestingTask(TestCaseResult testCaseResult, VisualTestingService visualTestingService) {18 this.testCaseResult = testCaseResult;19 this.visualTestingService = visualTestingService;20 }21 @Override22 public void run() {23 try {24 this.visualTestingService.initScreenshotComparision(testCaseResult);25 } catch (Exception e) {26 log.error(e.getMessage(), e);27 log.error("Exception while handling ImageComparison for testCaseResult:" + testCaseResult, e);28 }29 }30}...

Full Screen

Full Screen

VisualTestingTask

Using AI Code Generation

copy

Full Screen

1import com.testsigma.tasks.VisualTestingTask;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.chrome.ChromeOptions;5import org.testng.annotations.Test;6public class VisualTesting {7 public void visualTesting() throws Exception {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");9 ChromeOptions options = new ChromeOptions();10 options.addArguments("headless");11 WebDriver driver = new ChromeDriver(options);12 VisualTestingTask.visualTestingTask(driver, "VisualTesting", "VisualTesting");13 driver.quit();14 }15}16import com.testsigma.tasks.VisualTestingTask;17import org.openqa.selenium.WebDriver;18import org.openqa.selenium.chrome.ChromeDriver;19import org.openqa.selenium.chrome.ChromeOptions;20import org.testng.annotations.Test;21public class VisualTesting {22 public void visualTesting() throws Exception {23 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");24 ChromeOptions options = new ChromeOptions();25 options.addArguments("headless");26 WebDriver driver = new ChromeDriver(options);27 VisualTestingTask.visualTestingTask(driver, "VisualTesting", "VisualTesting");28 driver.quit();29 }30}31import com.testsigma.tasks.VisualTestingTask;32import org.openqa.selenium.WebDriver;33import org.openqa.selenium.chrome.ChromeDriver;34import org.openqa.selenium.chrome.ChromeOptions;35import org.testng.annotations.Test

Full Screen

Full Screen

VisualTestingTask

Using AI Code Generation

copy

Full Screen

1package com.testsigma.examples;2import com.testsigma.tasks.VisualTestingTask;3public class VisualTestingTaskExample {4 public static void main(String[] args) {5 String img1 = "C:\\Users\\cavis\\Desktop\\img1.jpg";6 String img2 = "C:\\Users\\cavis\\Desktop\\img2.jpg";7 String img3 = "C:\\Users\\cavis\\Desktop\\img3.jpg";8 String img4 = "C:\\Users\\cavis\\Desktop\\img4.jpg";9 String img5 = "C:\\Users\\cavis\\Desktop\\img5.jpg";10 VisualTestingTask visualTestingTask = new VisualTestingTask();

Full Screen

Full Screen

VisualTestingTask

Using AI Code Generation

copy

Full Screen

1import com.testsigma.tasks.VisualTestingTask;2import com.testsigma.testengine.TestPlan;3import com.testsigma.testengine.TestSigma;4import com.testsigma.testengine.TestSuite;5import com.testsigma.testengine.TestTask;6import com.testsigma.testengine.TestTaskResult;7import com.testsigma.testengine.TestTaskResult.Status;8import com.testsigma.testengine.TestTaskResult.TaskResultType;9import com.testsigma.testengine.TestTaskResult.TaskType;10import com.testsigma.testengine.TestTaskResult.VisualTestResult;11import com.testsigma.testengine.TestTaskResult.VisualTestResult.VisualTestStatus;

Full Screen

Full Screen

VisualTestingTask

Using AI Code Generation

copy

Full Screen

1import com.testsigma.tasks.VisualTestingTask;2import com.testsigma.utils.TestSigmaLogger;3import com.testsigma.utils.TestSigmaUtils;4public class VisualTesting{5public static void main(String[] args) {6String testCaseId = args[0];7String testCaseName = args[1];8String testSuiteId = args[2];9String testSuiteName = args[3];10String projectId = args[4];11String projectName = args[5];12String buildId = args[6];13String buildName = args[7];14String environmentId = args[8];15String environmentName = args[9];16String executionId = args[10];17String executionName = args[11];18String executionType = args[12];19String browserName = args[13];20String browserVersion = args[14];21String operatingSystem = args[15];22String operatingSystemVersion = args[16];23String deviceName = args[17];24String deviceType = args[18];25String deviceResolution = args[19];26String deviceOrientation = args[20];27String testCaseStatus = args[21];28String testCaseComment = args[22];

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in VisualTestingTask

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful