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(字符串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();
}
}
我认为您必须将下面的主机条目添加到您的主机文件中。
127.0.0.1 localhost
这对我起作用了
我正在尝试使用Firefox运行Selenium测试。我正在使用C#。 我还尝试了配置文件集: 我收到的错误: 无法在45000毫秒内绑定到锁定端口7054 我甚至尝试卸载Firefox,包括配置文件,然后重新安装。没有帮助。 仅供参考:我有一个关于3个selenium webdrivers的问题。我试图把这个问题分成多个部分,这样讨论就更容易了。原文:Selenium WebDriver-没有适
问题内容: 尝试使用MVN测试命令行运行selenium测试时,出现此错误。奇怪的是,我三天前尝试了一下,并成功运行了: 这是我的测试: 问题答案: 我只是使用chromeDriver,它工作正常。
我收到一个错误,我的webdriver(2.22)无法在45000ms内绑定到锁定端口7054。 版本: null null null 新的FirefoxDriver(新的FirefoxBinary(新文件(“C:\Documents and Settings\Larsonre\Local Settings\Application Data\Mozilla Firefox\firefox.exe”
问题内容: 我正在尝试对JavaScript代码进行一些验收测试。但是,当我尝试将Capybara与Selenium结合使用时,我一直得到以下信息: 下面的代码是应该启动驱动程序的代码。我从http://code.google.com/p/chromedriver/downloads/list下载了适当的文件,然后通过运行PATH = $ PATH:/ directory / where / ch
我在firefox浏览器中执行selenium脚本时遇到了问题。 控制台错误: null
问题内容: 运行黄瓜测试时出现此错误: “ * 无法启动或无法连接到Chrome。请检查ChromeDriver是最新的。在以下位置使用Chrome二进制文件:/ opt / google / chrome / google-chrome(Selenium :: WebDriver :: Error :: UnknownError)* ” 我下载了chromdriver,将其解压缩,将其复制到路径