selenium对安卓网页进行截图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.Augmenter; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; /** * Created by zsn on 2015/4/8. */ public class AndroidWebScreenshot { public static void main(String[] args) { DesiredCapabilities capability = DesiredCapabilities.android(); WebDriver driver = null; try { driver = new RemoteWebDriver( new URL("http://172.22.242.104:8080/wd/hub"), capability); } catch (MalformedURLException e) { e.printStackTrace(); } driver.get("http://izsn.xyz"); //对远程系统进行截图 driver = new Augmenter().augment(driver); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(scrFile, new File("./screenshot/screenshot.png")); } catch (IOException e) { e.printStackTrace(); } } } |
转载请注明:软件测试 » selenium对安卓网页进行截图
标签: android, RemoteWebDriver, selenium