0
点赞
收藏
分享

微信扫一扫

操作HTML5画画代码

package com.gloryroad.testcase;



import java.io.File;

import java.io.IOException;



import org.apache.commons.io.FileUtils;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;



import com.gloryroad.Demo.JavaScriptExcutorEk;



public class TestHTML5Canvs {

public WebDriver driver;

String baseUrl="http://www.w3school.com.cn/tiy/loadtext.asp?f=html5_canvas_line";

@BeforeMethod

public void setUp(){

driver=new FirefoxDriver();

driver.get(baseUrl);


}



@AfterMethod

public void tearDown(){

//
driver.close();

}


@Test

public void testHTML5canvs(){

File captureScreenShot=null;


JavascriptExecutor jS=(JavascriptExecutor) driver;

jS.executeScript("var c=document.getElementById('myCanvas');"+

"var cxt=c.getContext('2d');"+

"cxt.fillStyle='#FF0000';"+

"cxt.fillRect(0,0,150,150);");

captureScreenShot=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

try {

FileUtils.copyFile(captureScreenShot, new File("resource/666.png"));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}


}

举报

相关推荐

0 条评论