简体   繁体   English

如何使用Java WebDriver中的线程运行firefox的两个实例

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

I am a basic java user and currently I am trying to create an automated test case that tests my email functions. 我是一个基本的Java用户,目前我正在尝试创建一个自动测试用例来测试我的电子邮件功能。 So what I have in mind is: 所以我想到的是:

  1. Using selenium webdriver in java the program creates a thread that starts a browser, goes to google email, creates a test email and sends it to my yahoo email account. 该程序在Java中使用Selenium Webdriver,该程序创建了一个线程,该线程启动浏览器,转到Google电子邮件,创建测试电子邮件并将其发送到我的yahoo电子邮件帐户。 After that it sleeps indefinitely till it receives a message or signal to send another email. 之后,它会无限期休眠,直到收到消息或信号以发送另一封电子邮件为止。
  2. While that is being done, another thread is being created to go to yahoo email account and monitor new incoming email. 完成此操作后,正在创建另一个线程以转到yahoo电子邮件帐户并监视新的传入电子邮件。 Once it receives an email, a message or signal is sent to the first thread to send another email. 一旦收到电子邮件,就会将消息或信号发送到第一个线程以发送另一封电子邮件。
  3. The whole process will repeat itself for a total of two more times, so there will be three email exchanged between gmail and yahoo email. 整个过程总共重复两次,因此gmail和yahoo电子邮件之间将交换三封电子邮件。

So far the code is this. 到目前为止,代码是这样的。 I am not really sure how to progress from here. 我不太确定如何从这里开始。 More specifically I am not sure how to add the threads in there so that the two instances will run concurrently. 更具体地说,我不确定如何在其中添加线程,以便两个实例可以同时运行。

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);
        }
    }
}

Why use threads? 为什么要使用线程? Not better prepare two tests? 更好地准备两个测试? Send and receive? 发送和接收? One sends mail - passed ? 一个发送邮件传递? good we can proceed to next one Receiver will wait for an email, checking in interval for example 30 in next XX minutes or so? 好,我们可以继续进行下一个接收者将等待一封电子邮件,例如在接下来的XX分钟左右检查30个间隔吗?

U can run it in TestNG for repeat 3 times? 您可以在TestNG中运行它重复3次吗?

Btw. 顺便说一句。 good post why don't automate gmail :))) 好帖子,为什么不自动化gmail :)))

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium webdriver 和 Java 为 firefox 设置代理? - How do I set a proxy for firefox using Selenium webdriver with Java? 你如何在用java编写的selenium webdriver程序中使用firefox插件? - How do you use a firefox plugin within a selenium webdriver program written in java? 使用相同的Firefox窗口在Selenium WebDriver(Java)中运行多个测试 - Using the same Firefox Window to run multiple tests in Selenium WebDriver (Java) 如何在java中同时运行两个线程 - How to run two threads at the same time in java Webdriver 实例 - 如何使用一个测试库运行多个测试 - Webdriver instances - how to run multiple tests using one test base 如何在JAVA中使用Selenium在firefox Webdriver上接受下载提示? - How do I accept the download prompt on the firefox webdriver using selenium in JAVA? 如何使用带有Java的Selenium Webdriver处理允许弹出的Firefox插件 - How do I handle allow pop-up of plug-in for firefox using Selenium Webdriver with Java 如何在同一个程序中运行多个实例以在Eclipse中模拟多个客户端?(Java) - How do you run multiple instances of the same program to simulate multiple clients in eclipse?(Java) 如何在Java中运行不同的线程? - How do I run different threads in Java? Java中的Selenium Firefox Webdriver(运行参数) - Selenium Firefox Webdriver in Java (run parameters)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM