0

セレンのメソッド内でresponse.flushbufferを使用する必要があります。

私のコード

static PrintWriter writer;
static int timer = 0;

protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
{
    runDriver("radio", "click", "complete");
}

public static void runDriver(String col1, String Col2, String col3)
{
    WebElement ack1 = driver.findElement(By.id("represent"));
    try
    {
        ack1.click();
        String click1 = "<tr><td>" + col1 + "</td><td>" + col2 + "</td><td>" + col3 + "</td></tr>";
        writer.println(click1);
        response.flushBuffer(); // Won't let me put this here!
        Thread.sleep(timer);                                                                                        
     }
    catch(InterruptedException e)
    {
        writer.println( e+" ID:21");
    }
}

私がしようとしているのは、Webdriver による同じアクションを 1 つのメソッドに分離して、それを繰り返す必要がないようにすることです。私もこんな風にしてみました。

static PrintWriter writer;
static int timer = 0;

protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
{
    String radio1 = "Radio";
    String clicked = "Click";
    String complete = " Complete";

    top(radio1, clicked, complete);
    response.flushBuffer();
    bottom();
}

    public static void top(String col1, String col2, String col3)
    {
        writer.println("<tr><td>" + col1 + "</td><td>" + col2 + "</td><td>" + col3 + "</td></tr>");
    }

    public static void bottom()
    {
        try
        {
            Thread.sleep(timer);
        }
        catch(Exception e)
        {
            writer.println( "error: " + e);
        }
    }

しかし、それは私に NullPointerException を与えました。response.flushBuffer() を使用する必要がある理由は、ユーザーがプロセスを発生時に確認できるようにするためです。それ以外の場合は、プロセスを完了してからテキストを出力します。

アップデート **

NPEを修正しました。doget メソッド内でまだ Printer writer が宣言されていることがわかりました。doget メソッドの外でもまだ response.flushbuffer を取得できます。

4

1 に答える 1