[英]Taking webpages snapshot using selenium server in java
I need to take snapshot of webpage and for that I am using selenium RC (this is good choice right ? )with eclipse for java language . 我需要拍摄网页快照,为此我正在使用带有Java语言的eclipse的Selenium RC(这是不错的选择吗?)。 I am using it as JUnit test case .
我将其用作JUnit测试用例。 Here is my code.
这是我的代码。
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
@SuppressWarnings("deprecation")
public class mainClassTest extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.gmail.com/");
//water= new DefaultSelenium("localhost", 4444, "*firefox", "http://www.gmail.com/");
selenium.start();
}
@Test
public void testFinalSelenium() throws Exception {
selenium.windowMaximize();
selenium.open("/");
selenium.waitForPageToLoad("30000");
System.out.println("laoded\n");
// selenium.wait();
selenium.captureScreenshot("C:\\test\\simpleQuora.png");
selenium.captureEntirePageScreenshot("C:\\test\\CompleteQuora.png", "");
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
And it's working fine but If i have to take snapshot of multiple URLs, then what are the ways to do that ? 而且工作正常,但是如果我必须对多个URL进行快照,那么该怎么做呢? Can we do it without using it as JUnit test case and using selenium in main function ?
是否可以不将其用作JUnit测试用例并在主要功能中使用硒而做到这一点?
Because if I try to run this code : 因为如果我尝试运行以下代码:
package com.example.tests;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class MainClass {
void func(String url, String file)
{
Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", url);
selenium.start();
selenium.windowMaximize();
selenium.open("/");
selenium.waitForPageToLoad("30000");
System.out.println("laoded\n");
// selenium.wait();
String file1= "C:\\test\\"+file+".png";
String file2= "C:\\test\\"+file+"2.png";
selenium.captureScreenshot(file1);
selenium.captureEntirePageScreenshot(file2, "");
selenium.stop();
}
public static void main(String[] args)
{
MainClass demo = new MainClass();
demo.func("www.facebook.com","face");
//demo.func("www.reddit.com","reddit");
}
}
I got this error .(Although I have started server from cmd). 我收到此错误 。(尽管我已从cmd启动服务器)。
demo.func("www.facebook.com","face");
更改为
demo.func("http://www.facebook.com","face");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.