0

私はセレンが初めてです。実際、私はいくつかの Cookie 検証プロジェクトに取り組んでおり、複数のブラウザー (Firefox、つまり chrome、safari) で同意リンクをクリックする前後に存在する Cookie を手動で確認する必要があります。

以前のフェーズ 1 のプロジェクトで、qtp スクリプトを実行して、firefox をウィンドウ オブジェクトとして扱い、スクリーンショットをキャプチャしましたが、解像度が変わったり、ルック アンド フィールが少し変わったりすると、非常に面倒です。また、管理が非常に難しく、Firefox でしか動作せず、Chrome と Safari 用に同じスクリプトを再度作成する必要がありました。これとは別に、QTP はライセンス製品であり、現在はシート ライセンスを使用しているため、実行を高速化するために複数のマシンで実行することはできません。

だから私はSeleniumに移行することを考えました。今のところ、私の要件は次のとおりです。

1. open the page - take the screenshot once page loaded.
2. check the cookies using firebug or any other way  - take the screenshot
3. click the link to close the consent - take screenshot once consent closed.
4. refresh the page and again check the cookies using firebug - take screenshot

そのため、セレンについて調査したところ、verifyCookie を使用して Cookie を検証できることがわかりましたが、それでも Cookie の firebug ウィンドウのスクリーンショットが必要です。だから私はここで立ち往生しました。

ここで私を助けてください..

Firefoxでこれを行う方法をいくつか見つけましたが、可能であればChromeでも同様の方法を楽しみにしていました. ありがとう

4

3 に答える 3

1

Selenium は、Firefox の拡張機能やブラウザと思いどおりにやり取りできません。

あなたができることは、次のようにして、ページ上の Cookie のリストを収集することです。

driver.manage().getCookies()

これにより、Selenium に表示されるすべての Cookie のリストが表示されます。これは、JavaScript コンソールで表示される Cookie と同じであることに注意してください (HTTPOnly 属性で設定された Cookie など、すべての Cookie が JavaScript 経由で表示されるわけではありません)。

document.cookie

getCookies() を使用して、プログラムで Cookie を検証することをお勧めします。

于 2013-03-18T09:14:44.560 に答える
0

ページのスクリーンショットを撮りたい場合は、Selenium IDE でcaptureEntirePageScreenshotコマンドを使用します。

   captureEntirePageScreenshot | D:\\test.png | 

     D:\\test.png - path of file where you want to save the file
于 2013-03-21T11:50:47.897 に答える
0

いくつかの解決策を得ました

public class Selenium1st {

    /**
     * @param args
     */
    public static void main(String[] args) throws IOException, AWTException{
        // TODO Auto-generated method stub      
        System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\Firefox.exe");
        FirefoxProfile firefoxProfile = new FirefoxProfile();

        String domain = "extensions.firebug.";
        firefoxProfile.setPreference("app.update.enabled", false);
        firefoxProfile.addExtension(new File("E:\\softs\\selenium-2.29.0\\firebug\\firebug-1.11.2-fx.xpi"));
        firefoxProfile.setPreference(domain + "currentVersion", "1.11.2");
        firefoxProfile.setPreference("extensions.firebug.cookies.enableSites", true);
        firefoxProfile.setPreference("extensions.firebug.allPagesActivation", "on");

        firefoxProfile.setPreference(domain + "framePosition", "bottom");
        firefoxProfile.setPreference(domain + "defaultPanelName", "cookies");

        WebDriver driver = new FirefoxDriver(firefoxProfile);
        driver.get("http://www.google.com/webhp?complete=1&hl=en");
        WebElement query = driver.findElement(By.name("q"));
        query.sendKeys("Cheese");
        query.sendKeys("\n");
        Robot robot = new Robot();
        BufferedImage img = robot.createScreenCapture(new Rectangle(new Dimension(1024, 768)));

        File path = new File("E:\\abc");//Path to your file
        if(path.getName().indexOf(".jpg") == -1){
            path = new File(path.getPath() + ".jpg");
        }       
        ImageIO.write(img, "jpg", path);                
    }

}

役に立つかもしれません。

于 2013-04-12T08:12:26.870 に答える