私は長時間試していますが、これを動作させることはできません。 私がやろうとしているのは、Fluentleniumをベースに負荷テストを行うことです。 テストを開始しようとすると、クロムブラウザが1つしか開きません。IDEで、同じメソッドが3回実行されています(例)テストに合格しないことがあります。それは別のポート(セレンによって生成された)の下で3つのクロムブラウザを起動すると仮定しますが、それは1つのブラウザを起動しません。Java Selenium - 1つの方法で複数のWebDriverを起動できません
ここで失敗しています私のコードです:
public class Example extends FluentTestNg {
private final static String DEFAULT_URL = "http://google.com";
@Override
public WebDriver newWebDriver() {
DesiredCapabilities caps = new DesiredCapabilities();
WebDriver driver = new ChromeDriver(caps);
return driver;
}
@Test(invocationCount = 3, threadPoolSize = 3)
public void GoogleTest() throws Exception {
goTo(DEFAULT_URL);
await().until($(".gsfi")).present();
System.out.println(getCookies());
}
}
相続人は、それは私が正常に動作し、別の方法があるが、私はそれをするためのnewWebDriver方法を渡す必要が
Starting ChromeDriver 2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262) on port 14851
Only local connections are allowed.
Jun 19, 2017 12:53:03 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Jun 19, 2017 12:53:03 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:14851: Broken pipe (Write failed)
Jun 19, 2017 12:53:03 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://localhost:14851
org.openqa.selenium.NoSuchSessionException: no such session
(Driver info: chromedriver=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262),platform=Mac OS X 10.12.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 59 milliseconds
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262), userDataDir=/var/folders/1j/tdgn9dcn6d9g9dcd3fs8nj8c0000gn/T/.org.chromium.Chromium.yRHaZe}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.86, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 25c29b733c90f9dff2afb69dee6dc1d5
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.isEnabled(RemoteWebElement.java:148)
at org.fluentlenium.core.proxy.ComponentHandler.isStale(ComponentHandler.java:52)
at org.fluentlenium.core.proxy.AbstractLocatorHandler.present(AbstractLocatorHandler.java:225)
at org.fluentlenium.core.proxy.LocatorProxies.present(LocatorProxies.java:113)
at org.fluentlenium.core.domain.FluentWebElement.present(FluentWebElement.java:132)
at org.fluentlenium.core.conditions.AbstractObjectConditions.verify(AbstractObjectConditions.java:36)
at org.fluentlenium.core.conditions.WebElementConditions.present(WebElementConditions.java:43)
at org.fluentlenium.core.conditions.AbstractFluentListConditions.lambda$present$0(AbstractFluentListConditions.java:79)
at org.fluentlenium.core.conditions.AtLeastOneElementConditions.lambda$buildAtLeastOnePredicate$0(AtLeastOneElementConditions.java:49)
at org.fluentlenium.core.conditions.AtLeastOneElementConditions.verify(AtLeastOneElementConditions.java:35)
at org.fluentlenium.core.conditions.AbstractFluentListConditions.present(AbstractFluentListConditions.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler$2.apply(WaitConditionInvocationHandler.java:216)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler$2.apply(WaitConditionInvocationHandler.java:212)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.lambda$until$0(WaitConditionInvocationHandler.java:156)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209)
at org.fluentlenium.core.wait.FluentWait.untilPredicate(FluentWait.java:131)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.until(WaitConditionInvocationHandler.java:144)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.until(WaitConditionInvocationHandler.java:175)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.waitForCondition(WaitConditionInvocationHandler.java:212)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.invoke(WaitConditionInvocationHandler.java:190)
at com.sun.proxy.$Proxy8.present(Unknown Source)
at Example.GoogleTest(Example.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
org.openqa.selenium.TimeoutException: Expected condition failed: Elements By.cssSelector: .gsfi (Lazy Element List) is not present (tried for 5 second(s) with 500 MILLISECONDS interval)
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:264)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:232)
at org.fluentlenium.core.wait.FluentWait.untilPredicate(FluentWait.java:131)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.until(WaitConditionInvocationHandler.java:144)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.until(WaitConditionInvocationHandler.java:175)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.waitForCondition(WaitConditionInvocationHandler.java:212)
at org.fluentlenium.core.conditions.wait.WaitConditionInvocationHandler.invoke(WaitConditionInvocationHandler.java:190)
at com.sun.proxy.$Proxy8.present(Unknown Source)
at Example.GoogleTest(Example.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
を失敗したことを提供されたスタックトレース仕事...
public class Example extends FluentTestNg {
private final static String DEFAULT_URL = "http://google.com";
private static ThreadLocal<WebDriver> drivers = new ThreadLocal<WebDriver>();
public void setWebdriver(WebDriver driver){
drivers.set(driver);
}
@Override
public WebDriver newWebDriver() {
return drivers.get();
}
@BeforeMethod
public void launchbrowser(){
WebDriver drivers = new ChromeDriver();
setWebdriver(drivers);
}
@Test(invocationCount = 3, threadPoolSize = 3)
public void GoogleTest() throws Exception {
newWebDriver().get(DEFAULT_URL);
}
}
Heresのコンソールログは、3つのブラウザFluentlenium構文は使用できません。
Starting ChromeDriver 2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262) on port 11700
Only local connections are allowed.
Starting ChromeDriver 2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262) on port 35621
Only local connections are allowed.
Starting ChromeDriver 2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262) on port 31113
Only local connections are allowed.
Jun 19, 2017 12:59:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Jun 19, 2017 12:59:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Jun 19, 2017 12:59:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
唯一の問題は、私はそれにFluentlenium構文で構築を使用することはできません(EXP:後藤GetCookies、待つ、電気ショック療法)。私はセレンの構文を使用する必要があります。
Fluentleniumだけで動作させる方法はありますか?
あなたを混乱させるかもしれない最初のものは、あなたの 'drivers'変数名です。私が知る限り、あなたは 'drivers'のコレクションを保存することは決してないので、すべてを' driver'に変更してください。第二に、一度に多数のインスタンスを実行したいので、 'WebDriver'を静的変数に格納しないでください。希望を少し助ける:) – mrfreester
ThreadLocalを使用している場合、おそらくあなたのgetメソッドを静的にするだけです。IE 'public static WebDriver newWebDriver()'。そのメソッド名を 'getDriver'または' getCurrentDriver'に変更したいのは、新しいメソッドも作成していないからです。 – mrfreester