Browsermob Proxy を実行し、WebDriver を介してテスト中のビデオ プレーヤー アプリにアクセスし、Web サービス呼び出しのヘッダーとコンテンツを読み取ることができます。具体的には、ドライバーが特定のリンクをクリックしたときに、正しいビデオ ファイル名が渡されるようにしたいと考えています。
BrowserMob によって生成された HAR オブジェクトを文字列に変換して、文字列を検索できるようにしたいと考えていますvideo_filename.flv
。プロキシ サーバーには、その内容を、、または のwriteTo()
いずれかにダンプする機能があります。今、ばかげて、結果をファイルにダンプしてから、ファイルを文字列に取り込んで解析しています。file
OutputStream
Writer
//...lots of WebDriver activity up here with BMP listening
//...
//get the HAR data
Har har = server.getHar();
//Output HAR to a file
FileOutputStream fos = null;
try {
fos = new FileOutputStream("C:\\output.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
har.writeTo(fos);
} catch (IOException e) {
e.printStackTrace();
}
String harString = readFile("C:\\output.txt", StandardCharsets.UTF_8);
System.out.println(harString);
これは機能します。
Writer
またはで同じことを試みたときOutputStream
、これらの型のいずれかを文字列に変換することを心配する前に、これらが null ポインターであるという苦情が寄せられました。このことを考慮:
//get the HAR data
Har har = server.getHar();
//Output HAR to a Writer
Writer harWriter = null;
try {
har.writeTo(harWriter);
} catch (IOException e) {
e.printStackTrace();
}
null ポインター例外を返します。
についても同様ですOutputStream
。harWriter
試す前に、null 以外の値に設定する必要がありますwriteTo()
か? どうすればそれを達成できますか?
見よ、スタックトレース:
java.lang.NullPointerException
at org.codehaus.jackson.impl.WriterBasedGenerator._flushBuffer(WriterBasedGenerator.java:1187)
at org.codehaus.jackson.impl.WriterBasedGenerator.close(WriterBasedGenerator.java:837)
at org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(ObjectMapper.java:2004)
at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1581)
at net.lightbody.bmp.core.har.Har.writeTo(Har.java:30)
at com.videoplayer.CorrectVideosAreSentToThePlayer.teardown(CorrectVideosAreSentToThePlayer.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)