現在、Firefox (および Firebug/NetExport プラグイン) で Selenium Webdriver を使用して、ユーザーがページの検索バーを使用した後に送信された HTTP 要求から特定のクエリ文字列パラメーターを取得する回帰テスト シナリオを実行しています。呼び出しが行われた後、NetExport は要求からの .HAR ファイルをローカル フォルダに保存します。実際には、最後のページが読み込まれる直前にトラフィックをキャプチャするコードがあるにもかかわらず、3 つのファイル (テスト中にアクセスしたページごとに 1 つ) が保存されますが、それは別の問題です。
ただし、次のことを行うには、これをもう少し自動化する必要があります。
1) キャプチャした HAR ファイルを読み取り可能な形式にロードする 2) 必要な値を見つける 3) 後で確認するためにその値を記録する
これを行う最初の試みは、HAR ファイルをローカル フォルダーからオンラインの HAR ビューアーにドラッグ アンド ドロップする方法を調査することでした。この特定のページには、HAR ファイルの内容をコピーして貼り付けるか、テキスト ボックスにドラッグ アンド ドロップしてプレビューを生成するためのボックスがあります。これに関するいくつかの異なる質問 (stackoverflow からのもの) を読み、それは不可能であるか、複雑で実用的ではないと判断しました。
「showPreview」設定を入力します。いくつかの異なるサイトでは、次のように説明されています。「 プレビューを表示: エクスポートされたデータのプレビューを表示します。デフォルトでは HAR Viewer が使用されます。extensions.firebug.netexport.viewerURL 設定を参照して ください。」
これにより、NetExport で HAR ファイルを新しいタブで開くビューアに自動的にキックすることができるという考えが浮かびました...しかし、これがどのように行われるかについての簡単な説明が見つかりません。あるサポート ページでは、profile.setPreference("extensions.firebug.netexport.viewerURL", " http://www.softwareishard.com/har/viewer1-1/ ");を使用するという回答がありました。 ただし、その URL を更新して最新の URL を指すようにし、この設定をロードしました...しかし、何をしても、HAR ファイルのプレビューを新しい Firefox タブやその他の場所に表示することはできません。その問題。
私はアイデアがありません。私はこれにかなり慣れていないので、一部の人々が他のやや関連する質問に対して与えた回答やヒントは、私の理解レベルを超えており、とにかく適合していないようです.
とにかく、これが私がこれまでに持っているものです。一番下のコメントアウトされたものは無視してください。これは私が試しているものであり、もう一度いじりたい場合に備えて参照用に残しておきたいものです.
package scn01pkg;
import java.io.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.lang.InterruptedException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class UsingBMP {
    public static void main(String[] args) {
    System.out.println(System.getProperty("user.dir"));
        // auto-install FireBug and NetExport into Firefox profile
        File firebug = new File("firebug-2.0.11-fx.xpi");
        File netExport = new File("netExport-0.9b7.xpi");
        FirefoxProfile profile = new FirefoxProfile();
        try {
            profile.addExtension(firebug);
            profile.addExtension(netExport);
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Setting Firebug preferences
        profile.setPreference("extensions.firebug.currentVersion", "2.0.11");
        profile.setPreference("extensions.firebug.addonBarOpened", true);
        profile.setPreference("extensions.firebug.console.enableSites", true);
        profile.setPreference("extensions.firebug.script.enableSites", true);
        profile.setPreference("extensions.firebug.net.enableSites", true);
        profile.setPreference("extensions.firebug.previousPlacement", 1);
        profile.setPreference("extensions.firebug.allPagesActivation", "on");
        profile.setPreference("extensions.firebug.onByDefault", true);
        profile.setPreference("extensions.firebug.defaultPanelName", "net");
        // Setting netExport preferences
        profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
        //  ---profile under this comment is a test---
        profile.setPreference("extensions.firebug.netexport.viewerURL", "http://www.softwareishard.com/har/viewer/");
        profile.setPreference("extensions.firebug.netexport.autoExportToFile", true);
        profile.setPreference("extensions.firebug.netexport.Automation", true);
        profile.setPreference("extensions.firebug.netexport.showPreview", true);
        profile.setPreference("extensions.firebug.netexport.defaultLogDir", "C:\\workspace\\CaptureNetworkTraffic");
        // Launch Firefox with the desired capabilities
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("firefox");
        capabilities.setPlatform(org.openqa.selenium.Platform.ANY);
        capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        WebDriver driver = new FirefoxDriver(capabilities);
        // Wait until Firebug is loaded - 5s
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 
        // Load tested website mainpage
        driver.get("http://www.website.com");
        // Wait for page to load (10s)
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        // Clicking "Login" from the main page
        driver.findElement(By.cssSelector("#login-block a")).click();
        // Wait until tested website's login page is loaded - 10s
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        // Enter username
        driver.findElement(By.id("username")).sendKeys("myusername");
        // Waiting after entering in Username, 5s (increase if script failing persists)
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 
        // Enter password
        driver.findElement(By.id("password")).sendKeys("mypassword");
        // Clicking "Sign in" after entering UN and PW
        driver.findElement(By.name("loginbutton")).click();
        // Waiting for page to load - implicitly wait 10s
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);    
        // Capture traffic
        try {
            //arbitrary wait time to avoid "issues"
            Thread.sleep(3000);
            //searching for product
            driver.findElement(By.id("parts")).sendKeys("searchterm");
            driver.findElement(By.cssSelector("#keyword-button-div button")).click();
            //Time to process request, print to file, and quit.
            Thread.sleep(6000);
            } catch(InterruptedException ie) {
            ie.printStackTrace();
            }
        //  ------Last bit commented out until proper use is determined--------
        // Extra wait time - uncomment out if needed
        //driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        // Load the HAR viewer website
        //driver.get("http://www.softwareishard.com/har/viewer/");
        // Wait for page to load
        //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        // Upload file to the online HAR viewer
        //WebElement inputField = driver.findElement(By.xpath("//*[@id=sourceEditor]"));
        //WebElement inputField = driver.findElement(By.id("sourceEditor"));
        //inputField.sendKeys("C:\\workspace\\CaptureNetworkTraffic\\www.freescale.com+2015-08-24+11-23-46.har");
        // Wait 2 seconds
        //driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        // Submit the data
        // driver.findElement(By.name("appendPreview")).click();
        // Wait for page to load
        // driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        // ---------uncomment out when script is working to this point--------------
        // driver.quit();
        }
}
私の文章の壁を読むのに時間を割いてくれた人に、前もって感謝します!