簡體   English   中英

如何使用Java WebDriver中的線程運行firefox的兩個實例

[英]How do you run two instances of firefox using threads in java webdriver

我是一個基本的Java用戶,目前我正在嘗試創建一個自動測試用例來測試我的電子郵件功能。 所以我想到的是:

  1. 該程序在Java中使用Selenium Webdriver,該程序創建了一個線程,該線程啟動瀏覽器,轉到Google電子郵件,創建測試電子郵件並將其發送到我的yahoo電子郵件帳戶。 之后,它會無限期休眠,直到收到消息或信號以發送另一封電子郵件為止。
  2. 完成此操作后,正在創建另一個線程以轉到yahoo電子郵件帳戶並監視新的傳入電子郵件。 一旦收到電子郵件,就會將消息或信號發送到第一個線程以發送另一封電子郵件。
  3. 整個過程總共重復兩次,因此gmail和yahoo電子郵件之間將交換三封電子郵件。

到目前為止,代碼是這樣的。 我不太確定如何從這里開始。 更具體地說,我不確定如何在其中添加線程,以便兩個實例可以同時運行。

import static org.junit.Assert.fail;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.concurrent.TimeUnit;

public class multi_test {

    public WebDriver driver1;
    protected WebDriver driver2;
    public String baseUrl1;
    public String baseUrl2;
    protected StringBuffer verificationErrors = new StringBuffer();

    public class setup1 implements Runnable{
        public void run(){
            driver1.get(baseUrl1);
        }
    }

    public class setup2 implements Runnable{
        public void run(){
            driver2.get(baseUrl2);
        }
    }
    @Before
    public void setUp() throws Exception {
        driver1 = new FirefoxDriver();
        baseUrl1 = "http://www.yahoo.com";
        driver1.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        System.out.println(driver1);
        driver2 = new FirefoxDriver();
        baseUrl2 = "https://google.com";
        driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testing1() throws Exception {
        driver1.get(baseUrl1);
    }

    @After
    public void tearDown() throws Exception {
        //driver1.quit();
        //driver2.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

為什么要使用線程? 更好地准備兩個測試? 發送和接收? 一個發送郵件傳遞? 好,我們可以繼續進行下一個接收者將等待一封電子郵件,例如在接下來的XX分鍾左右檢查30個間隔嗎?

您可以在TestNG中運行它重復3次嗎?

順便說一句。 好帖子,為什么不自動化gmail :)))

https://groups.google.com/d/msg/selenium-users/8jR6Fw5ndxU/7peVDuzkNN4J

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM