How to use ScreenCaptureUtil class of com.testsigma.automator.utilities package

Best Testsigma code snippet using com.testsigma.automator.utilities.ScreenCaptureUtil

copy

Full Screen

...6import com.testsigma.automator.drivers.DriverManager;7import com.testsigma.automator.entity.*;8import com.testsigma.automator.exceptions.AutomatorException;9import com.testsigma.automator.service.ObjectMapperService;10import com.testsigma.automator.utilities.ScreenCaptureUtil;11import com.testsigma.automator.utilities.ScreenshotUploadTask;12import com.testsigma.automator.utilities.UploadThreadPool;13import lombok.extern.log4j.Log4j2;14import org.apache.commons.lang3.ObjectUtils;15import org.apache.commons.lang3.StringUtils;16import org.apache.logging.log4j.ThreadContext;17import java.sql.Timestamp;18import java.util.*;19@Log4j220public class TestcaseRunner {21 private static final String[] SKIP_GETURL = {"Close all windows", "Verify that the Alert is not present",22 "Verify that the Alert displays the message", "Click on Cancel button in the alert",23 "Click OK button in the alert", "Verify that an Alert with text", "Wait until an Alert is displayed in the current page", "Wait until the Alert currently displayed is absent"};24 public final int SAVE_BATCH_IMAGES = 10;25 protected TestDeviceEntity testDeviceEntity;26 protected EnvironmentRunResult environmentRunResult;27 protected TestPlanRunSettingEntity testPlanRunSettingEntity;28 protected TestDeviceSettings testDeviceSettings;29 protected String testPlanId;30 protected WorkspaceType workspaceType;31 protected TestCaseEntity testCaseEntity;32 protected TestCaseResult testCaseResult;33 protected Map<Long, TestCaseStepResult> mapStepResult;34 protected boolean skipExecution;35 protected String resultFailureMessage;36 public TestcaseRunner(TestCaseEntity testCaseEntity, TestCaseResult testCaseResult,37 Map<Long, TestCaseStepResult> mapStepResult, boolean skipExecution,38 String resultFailureMessage) {39 this.testDeviceEntity = EnvironmentRunner.getRunnerEnvironmentEntity();40 this.environmentRunResult = EnvironmentRunner.getRunnerEnvironmentRunResult();41 this.testPlanRunSettingEntity = testDeviceEntity.getTestPlanSettings();42 this.testDeviceSettings = testDeviceEntity.getEnvSettings();43 this.testPlanId = EnvironmentRunner.getRunnerExecutionId();44 this.workspaceType = testDeviceEntity.getWorkspaceType();45 this.testCaseEntity = testCaseEntity;46 this.testCaseResult = testCaseResult;47 this.mapStepResult = mapStepResult;48 this.skipExecution = skipExecution;49 this.resultFailureMessage = resultFailureMessage;50 }51 public void startSession() throws AutomatorException {52 DriverManager.getDriverManager(testDeviceEntity, testDeviceEntity.getWorkspaceType(), testDeviceSettings.getOs(),53 testCaseResult.getId(), DriverSessionType.TEST_CASE_SESSION);54 }55 public void endSession() throws AutomatorException {56 DriverManager driverManager = DriverManager.getDriverManager();57 if (driverManager != null) {58 driverManager.endSession();59 }60 }61 private void populateThreadContextData() {62 ThreadContext.put("TEST_CASE", testCaseEntity.getId() + "");63 ThreadContext.put("TEST_CASE_RESULT", testCaseResult.getId() + "");64 }65 private void resetThreadContextData() {66 ThreadContext.put("TEST_CASE", "");67 ThreadContext.put("TEST_CASE_RESULT", "");68 }69 public TestCaseResult run() throws Exception {70 resetThreadContextData();71 populateThreadContextData();72 log.info("Running testcase - " + testCaseEntity.getTestCaseName());73 if (testDeviceEntity.getCreateSessionAtCaseLevel()) {74 startSession();75 } else {76 restartCurrentSession();77 }78 environmentRunResult.setSessionCreatedOn(new Timestamp(System.currentTimeMillis()));79 ResultConstant result = ResultConstant.SUCCESS;80 List<TestCaseStepEntity> stepList = testCaseEntity.getTestSteps();81 List<TestCaseStepResult> testCaseStepsResult = new ArrayList<>();82 testCaseResult.setTestCaseStepResults(testCaseStepsResult);83 testCaseResult.setIsStepGroup(testCaseEntity.getIsStepGroup());84 testCaseResult.setDataDriven(testCaseEntity.getIsDataDriven());85 testCaseResult.setTestPlanResultId(testDeviceEntity.getExecutionRunId());86 testCaseResult.setTestCaseName(testCaseEntity.getTestCaseName());87 try {88 HashMap<Long, TestCaseStepResult> parentStatus = new HashMap<>();89 int currentIndex = 0;90 testCaseResult.setCurrentIndex(currentIndex);91 int lastStep = stepList.size() - 1;92 ScreenCaptureUtil screenCaptureUtil = new ScreenCaptureUtil(new ArrayList<>());93 for (int i = 0; i < stepList.size(); i++) {94 TestCaseStepEntity testCaseStepEntity = stepList.get(i);95 TestCaseStepResult testCaseStepResult = new TestCaseStepResult();96 testCaseStepResult.setTestCaseStepId(testCaseStepEntity.getId());97 testCaseStepResult.setSkipExe(skipExecution);98 testCaseStepResult.setSkipMessage(resultFailureMessage);99 /​* if (!skipExecution && (workspaceType.equals(WorkspaceType.WebApplication) || workspaceType100 .equals(WorkspaceType.MobileWeb))) {101 url = getUrl();102 }*/​103 boolean skipGetUrl = false;104 if (testCaseStepEntity.getAction() != null) {105 skipGetUrl = Arrays.asList(SKIP_GETURL).stream().filter(action -> testCaseStepEntity.getAction().contains(action)).count() > 0;106 }...

Full Screen

Full Screen
copy

Full Screen

...7import com.testsigma.automator.exceptions.TestsigmaNoParallelRunException;8import com.testsigma.automator.http.HttpClient;9import com.testsigma.automator.utilities.ErrorUtil;10import com.testsigma.automator.utilities.PathUtil;11import com.testsigma.automator.utilities.ScreenCaptureUtil;12import lombok.Data;13import lombok.extern.log4j.Log4j2;14import org.apache.commons.io.FileUtils;15import org.apache.logging.log4j.ThreadContext;16import java.io.File;17import java.io.IOException;18import java.nio.file.Paths;19@Log4j220@Data21public abstract class EnvironmentRunner {22 protected static final ThreadLocal<ExecutionStatus> executionStatus = new ThreadLocal<>();23 protected static final ThreadLocal<TestDeviceEntity> _runnerEnvironmentEntity = new ThreadLocal<>();24 protected static final ThreadLocal<EnvironmentRunResult> _runnerEnvironmentRunResult = new ThreadLocal<>();25 protected static final ThreadLocal<String> _runnerExecutionId = new ThreadLocal<>();26 protected static final ThreadLocal<HttpClient> _webAppHttpClient = new ThreadLocal<>();27 protected static final ThreadLocal<HttpClient> _assetsHttpClient = new ThreadLocal<>();28 protected TestDeviceEntity testDeviceEntity;29 protected EnvironmentRunResult environmentRunResult;30 protected String testPlanId;31 protected WorkspaceType workspaceType;32 public EnvironmentRunner(TestDeviceEntity testDeviceEntity, EnvironmentRunResult environmentRunResult, HttpClient webAppHttpClient,33 HttpClient assetsHttpClient) {34 this.testDeviceEntity = testDeviceEntity;35 this.environmentRunResult = environmentRunResult;36 this.workspaceType = testDeviceEntity.getWorkspaceType();37 this.testPlanId = getTestPlanId();38 _webAppHttpClient.set(webAppHttpClient);39 _assetsHttpClient.set(assetsHttpClient);40 testDeviceEntity.getEnvSettings().setExecutionRunId(testDeviceEntity.getExecutionRunId());41 testDeviceEntity.getEnvSettings().setOs(this.getOs());42 }43 public static ExecutionStatus getExecutionStatus() {44 return executionStatus.get();45 }46 public static boolean isRunning() {47 return executionStatus.get() == ExecutionStatus.STARTED;48 }49 public static void setStartedStatus() {50 executionStatus.set(ExecutionStatus.STARTED);51 }52 public static void setStoppedStatus() {53 executionStatus.set(ExecutionStatus.STOPPED);54 }55 public static TestDeviceEntity getRunnerEnvironmentEntity() {56 return _runnerEnvironmentEntity.get();57 }58 public static void setRunnerEnvironmentEntity(TestDeviceEntity testDeviceEntity) {59 _runnerEnvironmentEntity.set(testDeviceEntity);60 }61 public static EnvironmentRunResult getRunnerEnvironmentRunResult() {62 return _runnerEnvironmentRunResult.get();63 }64 public static void setRunnerEnvironmentRunResult(EnvironmentRunResult environmentRunResult) {65 _runnerEnvironmentRunResult.set(environmentRunResult);66 }67 public static String getRunnerExecutionId() {68 return _runnerExecutionId.get();69 }70 public static void setRunnerExecutionId(String testPlanId) {71 _runnerExecutionId.set(testPlanId);72 }73 public static HttpClient getWebAppHttpClient() {74 return _webAppHttpClient.get();75 }76 public static HttpClient getAssetsHttpClient() {77 return _assetsHttpClient.get();78 }79 protected void beforeExecute() throws AutomatorException {80 checkForEmptyEnvironment();81 new ScreenCaptureUtil().createScreenshotsFolder();82 new ErrorUtil().checkError(testDeviceEntity.getErrorCode(), null);83 new DriversUpdateService().syncBrowserDriver(testDeviceEntity);84 }85 public EnvironmentRunResult run() {86 try {87 populateThreadContextData();88 setRunnerEnvironmentEntity(testDeviceEntity);89 setRunnerEnvironmentRunResult(environmentRunResult);90 setRunnerExecutionId(testPlanId);91 beforeExecute();92 setStartedStatus();93 execute();94 afterExecute();95 setEnvironmentResult();...

Full Screen

Full Screen

ScreenCaptureUtil

Using AI Code Generation

copy

Full Screen

1package com.testsigma.automator.utilities;2import java.io.File;3import java.io.IOException;4import org.apache.commons.io.FileUtils;5import org.openqa.selenium.OutputType;6import org.openqa.selenium.TakesScreenshot;7import org.openqa.selenium.WebDriver;8public class ScreenCaptureUtil {9 public static String captureScreen(WebDriver driver, String screenShotName) {10 try {11 TakesScreenshot ts = (TakesScreenshot) driver;12 File source = ts.getScreenshotAs(OutputType.FILE);13 String dest = System.getProperty("user.dir") + "/​screenshots/​" + screenShotName + ".png";14 File destination = new File(dest);15 FileUtils.copyFile(source, destination);16 System.out.println("Screenshot taken");17 return dest;18 } catch (Exception e) {19 System.out.println("Exception while taking screenshot " + e.getMessage());20 return e.getMessage();21 }22 }23}24package com.testsigma.automator.utilities;25import java.io.File;26import java.io.IOException;27import java.text.SimpleDateFormat;28import java.util.Date;29import org.apache.commons.io.FileUtils;30import org.openqa.selenium.OutputType;31import org.openqa.selenium.TakesScreenshot;32import org.openqa.selenium.WebDriver;33public class ScreenCaptureUtil {34 public static String captureScreen(WebDriver driver, String screenShotName) {35 try {36 TakesScreenshot ts = (TakesScreenshot) driver;37 File source = ts.getScreenshotAs(OutputType.FILE);38 String dest = System.getProperty("user.dir") + "/​screenshots/​" + screenShotName + ".png";39 File destination = new File(dest);40 FileUtils.copyFile(source, destination);41 System.out.println("Screenshot taken");42 return dest;43 } catch (Exception e) {44 System.out.println("Exception while taking screenshot " + e.getMessage());45 return e.getMessage();46 }47 }48 public static String captureScreen(WebDriver driver) {49 String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());50 TakesScreenshot ts = (TakesScreenshot) driver;51 File source = ts.getScreenshotAs(OutputType.FILE);52 String destination = System.getProperty("user.dir") + "/​screenshots/​" + dateName + ".png";53 File finalDestination = new File(destination);54 try {55 FileUtils.copyFile(source, finalDestination);56 } catch (

Full Screen

Full Screen

ScreenCaptureUtil

Using AI Code Generation

copy

Full Screen

1import com.testsigma.automator.utilities.ScreenCaptureUtil;2import java.io.IOException;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.remote.DesiredCapabilities;10import org.openqa.selenium.remote.RemoteWebDriver;11import org.testng.Assert;12import org.testng.annotations.AfterMethod;13import org.testng.annotations.BeforeMethod;14import org.testng.annotations.Test;15public class ScreenCaptureUtilTest {16 private WebDriver driver;17 public void setUp() throws MalformedURLException {18 DesiredCapabilities capabilities = new DesiredCapabilities();19 capabilities.setCapability("deviceName", "Android Emulator");20 capabilities.setCapability("platformName", "Android");21 capabilities.setCapability("platformVersion", "7.1.1");22 capabilities.setCapability("appPackage", "com.android.calculator2");23 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

ScreenCaptureUtil

Using AI Code Generation

copy

Full Screen

1import com.testsigma.automator.utilities.ScreenCaptureUtil;2public class 2 {3 public static void main(String[] args) {4 String filePath = "C:\\Users\\username\\Desktop\\";5 String fileName = "image";6 String fileExtension = ".png";7 ScreenCaptureUtil.captureScreenShot(filePath, fileName, fileExtension);8 }9}10import com.testsigma.automator.utilities.ScreenCaptureUtil;11public class 3 {12 public static void main(String[] args) {13 String filePath = "C:\\Users\\username\\Desktop\\";14 String fileName = "image";15 String fileExtension = ".png";16 ScreenCaptureUtil.captureScreenShot(filePath, fileName, fileExtension);17 }18}19import com.testsigma.automator.utilities.ScreenCaptureUtil;20public class 4 {21 public static void main(String[] args) {22 String filePath = "C:\\Users\\username\\Desktop\\";23 String fileName = "image";24 String fileExtension = ".png";25 ScreenCaptureUtil.captureScreenShot(filePath, fileName, fileExtension);26 }27}28import com.testsigma.automator.utilities.ScreenCaptureUtil;29public class 5 {30 public static void main(String[] args) {31 String filePath = "C:\\Users\\username\\Desktop\\";32 String fileName = "image";33 String fileExtension = ".png";34 ScreenCaptureUtil.captureScreenShot(filePath, fileName, fileExtension);35 }36}37import com.testsigma.automator.utilities.ScreenCaptureUtil;38public class 6 {39 public static void main(String[] args) {

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Agile in Distributed Development &#8211; A Formula for Success

Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.

Unveiling Samsung Galaxy Z Fold4 For Mobile App Testing

Hey LambdaTesters! We’ve got something special for you this week. ????

Top 7 Programming Languages For Test Automation In 2020

So you are at the beginning of 2020 and probably have committed a new year resolution as a tester to take a leap from Manual Testing To Automation . However, to automate your test scripts you need to get your hands dirty on a programming language and that is where you are stuck! Or you are already proficient in automation testing through a single programming language and are thinking about venturing into new programming languages for automation testing, along with their respective frameworks. You are bound to be confused about picking your next milestone. After all, there are numerous programming languages to choose from.

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful