<small id='elME5'></small><noframes id='elME5'>

<legend id='elME5'><style id='elME5'><dir id='elME5'><q id='elME5'></q></dir></style></legend>

  • <i id='elME5'><tr id='elME5'><dt id='elME5'><q id='elME5'><span id='elME5'><b id='elME5'><form id='elME5'><ins id='elME5'></ins><ul id='elME5'></ul><sub id='elME5'></sub></form><legend id='elME5'></legend><bdo id='elME5'><pre id='elME5'><center id='elME5'></center></pre></bdo></b><th id='elME5'></th></span></q></dt></tr></i><div id='elME5'><tfoot id='elME5'></tfoot><dl id='elME5'><fieldset id='elME5'></fieldset></dl></div>
  • <tfoot id='elME5'></tfoot>

        <bdo id='elME5'></bdo><ul id='elME5'></ul>

        Selenium 在并行运行测试时处理 ProtocolHandshake 错误

        Selenium handles ProtocolHandshake error while running tests parallel(Selenium 在并行运行测试时处理 ProtocolHandshake 错误)
          <tbody id='aGjGA'></tbody>
        1. <legend id='aGjGA'><style id='aGjGA'><dir id='aGjGA'><q id='aGjGA'></q></dir></style></legend>

            <tfoot id='aGjGA'></tfoot>

            <i id='aGjGA'><tr id='aGjGA'><dt id='aGjGA'><q id='aGjGA'><span id='aGjGA'><b id='aGjGA'><form id='aGjGA'><ins id='aGjGA'></ins><ul id='aGjGA'></ul><sub id='aGjGA'></sub></form><legend id='aGjGA'></legend><bdo id='aGjGA'><pre id='aGjGA'><center id='aGjGA'></center></pre></bdo></b><th id='aGjGA'></th></span></q></dt></tr></i><div id='aGjGA'><tfoot id='aGjGA'></tfoot><dl id='aGjGA'><fieldset id='aGjGA'></fieldset></dl></div>

              <small id='aGjGA'></small><noframes id='aGjGA'>

                  <bdo id='aGjGA'></bdo><ul id='aGjGA'></ul>
                • 本文介绍了Selenium 在并行运行测试时处理 ProtocolHandshake 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试练习使用 TestNG invocationCountthreadPoolSize 并行执行测试.

                  I try practicing to execute tests in parallel using TestNG invocationCount and threadPoolSize.

                  A.我这样写了一个一体机测试,成功了

                  A. I write a all-in-one test like this, and it is successful

                  @Test(invocationCount = 5, threadPoolSize = 5)
                  public void testThreadPool() {        
                      WebDriver driver = new ChromeDriver();
                      driver.get("http://www.google.com");
                      driver.findElement(By.name("q")).sendKeys("Amazon");
                      driver.quit();*/        
                  }
                  

                  =>5个Chrome浏览器同时打开(并行),测试成功.

                  => 5 Chrome browsers are opened at the same time (parallel), and tests are successfully executed.

                  B.我在@before 和@after 中定义了我的测试,但它不起作用

                  B. I define my test in @before and @after, and it doesn't work

                  @BeforeTest
                  public void setUp() {
                     WebDriver driver = driverManager.setupDriver("chrome");
                  }
                  
                  @Test(invocationCount = 5, threadPoolSize = 5)
                  public void testThreadPool() {    
                      driver.get("http://www.google.com");
                      driver.findElement(By.name("q")).sendKeys("Amazon");            
                  }
                  
                  @AfterTest
                  public void tearDown() {
                     driver.quit()
                  }
                  

                  =>打开1个chrome浏览器,好像刷新了5次,最后在文本字段中输入了5个亚马逊词,日志信息如下:

                  => 1 chrome browser is opened, and it seems it is refreshed 5 times, and at the end, there are 5 Amazon words entered in text field, with the following log message:

                  [1593594530,792][SEVERE]: bind() failed: Cannot assign requested address (99)
                  ChromeDriver was started successfully.
                  Jul 01, 2020 11:08:51 AM org.openqa.selenium.remote.ProtocolHandshake createSession
                  

                  我知道,对于 B,5 个线程使用相同的对象驱动程序,这就是为什么只打开一个 chrome.但我不知道在这种情况下如何管理驱动程序对象,因此我可以获得与 A 中相同的结果.

                  I understand that, with B, 5 threads use the same object driver, that's why only one chrome is opened. But I don't know how to manage driver object in this case so I can get the same result like in A.

                  任何想法表示赞赏.

                  推荐答案

                  你可以使用 ThreadLocal 类来让你的 webdriver 线程安全

                  You can use ThreadLocal class to make your webdriver Threadsafe

                  private ThreadLocal<WebDriver> webdriver = new ThreadLocal<WebDriver>();
                  
                     @BeforeMethod
                      public void setUp() {
                         webdriver.set(driverManager.setupDriver("chrome"));
                      }
                      
                      @Test(invocationCount = 5, threadPoolSize = 5)
                      public void testThreadPool() {    
                          webdriver.get().get("http://www.google.com");
                          webdriver.get().findElement(By.name("q")).sendKeys("Amazon");            
                      }
                      
                      @AfterMethod
                      public void tearDown() {
                         webdriver.get().quit()
                      }
                  

                  您需要在上述上下文中使用 BeforeMethod/AfterMethod.

                  Edit : You will need to use BeforeMethod/AfterMethod in above context.

                  这篇关于Selenium 在并行运行测试时处理 ProtocolHandshake 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                      <i id='H8qom'><tr id='H8qom'><dt id='H8qom'><q id='H8qom'><span id='H8qom'><b id='H8qom'><form id='H8qom'><ins id='H8qom'></ins><ul id='H8qom'></ul><sub id='H8qom'></sub></form><legend id='H8qom'></legend><bdo id='H8qom'><pre id='H8qom'><center id='H8qom'></center></pre></bdo></b><th id='H8qom'></th></span></q></dt></tr></i><div id='H8qom'><tfoot id='H8qom'></tfoot><dl id='H8qom'><fieldset id='H8qom'></fieldset></dl></div>
                        <tbody id='H8qom'></tbody>
                    1. <legend id='H8qom'><style id='H8qom'><dir id='H8qom'><q id='H8qom'></q></dir></style></legend>
                      • <small id='H8qom'></small><noframes id='H8qom'>

                      • <tfoot id='H8qom'></tfoot>

                            <bdo id='H8qom'></bdo><ul id='H8qom'></ul>