Webページのスナップショットを撮る必要があり、そのためにselenium RCを使用しています(これは良い選択ですよね?)Java言語のEclipseを使用しています。JUnitテストケースとして使用しています。これが私のコードです。
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();
}
}
それは正常に動作していますが、複数の URL のスナップショットを作成する必要がある場合、それを行う方法は何ですか? JUnitテストケースとして使用せず、メイン関数でセレンを使用せずに実行できますか?
このコードを実行しようとすると:
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");
}
}
このエラーが発生しました(cmdからサーバーを起動しましたが)。