ScreenCapture in UI Automation
In UI automation, how to know if the script played correctly?
One way is check the log messages and the check the output. That will be an cumbersome process to do. The better way is to see screenshots of the page. QEngine has a function to do this.
| Code: |
| saveScreenShot(outFileName,waittime) |
| Code: |
|
import time def screenshot(): filename=time.strftime("%Y_%m_%d_%H_%M_%S") saveScreenShot(filename,"1") |
| Code: |
|
import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import java.io.File; import java.util.Calendar; public class SaveScreen { public static void main (String args[]) { } public void saveScreen() throws Exception { Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH); int day = now.get(Calendar.DAY_OF_MONTH); int hour = now.get(Calendar.HOUR_OF_DAY); int min = now.get(Calendar.MINUTE); int sec = now.get(Calendar.SECOND); String fileNameone = "Screenshot_" year "_" month "_" day "_" hour "_" min "_" sec ".png"; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screenRectangle = new Rectangle(screenSize); Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); ImageIO.write(image, "png", new File(fileNameone)); } } |
| Code: |
|
String fileNameone = "Screenshot_" year "_" month "_" day "_" hour "_" min "_" sec ".png"; |
| Code: |
|
String fileNameone = foldername "Screenshot_" year "_" month "_" day "_" hour "_" min "_" sec ".png"; |
Post Comment