【问题标题】:Selenium::WebDriver::Error::WebDriverError: unable to bind to locking port 7054 within 45 secondsSelenium::WebDriver::Error::WebDriverError: 无法在 45 秒内绑定到锁定端口 7054
【发布时间】:2014-02-20 04:41:58
【问题描述】:
import java.util.concurrent.CountDownLatch;
import com.performance.script.script1;
import com.performance.script.script2;
import com.performance.script.script3;
import com.support.*;

    public class ThreadsRunnable{
        static GetSessionID gsi = new GetSessionID();
        static int threadUsers=30;
        static Thread thr2;

        public void testmain() throws InterruptedException{

    //            final CountDownLatch latch = new CountDownLatch(1);
                  for (int i=1; i<=threadUsers; i++) {
                    Runnable runner = new Runnable() {
                      public void run() {

                        try {
                            Thread.sleep(1000);
    //                    latch.await();
                          script1 s1 = new script1();
                          s1.setUp();
                          s1.testscript1();
                          cnq.tearDown();
                        } catch (InterruptedException ie) { } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                      }
                    };
                    new Thread(runner, "TestThread"+i).start();
                    Thread.sleep(5000);
                  }
                  // all threads are waiting on the latch.
    //            latch.countDown();// release the latch

// 现在所有线程都在并发运行。 } 公共静态 void main(String arg[]) 抛出 InterruptedException{ ThreadsRunnable tr = new ThreadsRunnable(); tr.testmain(); } }

下面是我运行的代码来查找端口 7054 是否空闲并且 它始终在控制台上显示为免费。但是,当我通过这个端口时 运行firefox它会出错,端口绑定任何人都可以帮助我 这个。谢谢

 package GroboUtils;

 import java.io.IOException;
 import java.net.DatagramSocket;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;

 /**
  * * Finds an available port on localhost.
  */
 public class PortFinder {

 // the ports below 1024 are system ports   private final int
 MIN_PORT_NUMBER  = 7054;

 // the ports above 49151 are dynamic and/or private    private final
 int MAX_PORT_NUMBER = 49151;

 /**
 * * Finds a free port between * {@link #MIN_PORT_NUMBER} and
 * {@link #MAX_PORT_NUMBER}. * * @return a free port * @throw
 * RuntimeException if a port could not be found
 */
 public int
        findFreePort() {
    for (int i = MIN_PORT_NUMBER; i
            <= MAX_PORT_NUMBER; i++) {
        if (available(i)) {
            //        System.out.println("Free Port: "+i);
            return i;
        }
    }
    throw new RuntimeException("Could not find an available port between"
            + MIN_PORT_NUMBER + " and " + MAX_PORT_NUMBER);
 }

 /**
 * * Returns true if the specified port is available on this host. * *
 * @param port the port to check * @return true if the port is available,
 * false otherwise
 */
 private boolean
        available(final int port) {
    ServerSocket serverSocket = null;
    DatagramSocket dataSocket = null;
    try {
        serverSocket = new ServerSocket(port);
        serverSocket.setReuseAddress(true);
        dataSocket = new DatagramSocket(port);
        dataSocket.setReuseAddress(true);
        return true;
    } catch (final IOException e) {
        return false;
    } finally {
        if (dataSocket != null) {
            dataSocket.close();
        }
        if (serverSocket != null) {
            try {
                serverSocket.close();
            } catch (final IOException e) {
                // can never happen
            }
        }
    }
 }

 public void portReuse() {
    try {
        ServerSocket socket1 = new ServerSocket();
        ServerSocket socket2 = new ServerSocket();
        ServerSocket socket3 = new ServerSocket();
        int port = 7054;

        socket2.setReuseAddress(true);
        socket2.bind(new InetSocketAddress("127.0.0.1", port));

        Thread.sleep(Long.MAX_VALUE);
    } catch (Exception e) {
        e.printStackTrace();
    }
 }

 public static void main(String agr[]) {
    PortFinder pf = new PortFinder();
    pf.findFreePort();
 }

}

【问题讨论】:

  • 抱歉上面的格式化代码...
  • 除非这是我没有听说过的一些深奥的格式约定,否则您可能需要考虑使用 IDE 的漂亮格式功能来修复您的第二个代码 sn-p。

标签: java selenium-webdriver


【解决方案1】:

我认为您必须将以下主机条目添加到您的主机文件中。

127.0.0.1 localhost

它对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 2012-05-25
    相关资源
    最近更新 更多