I use Selenide(5.16.2) and Guice(4.2.3) to build crossplatform framework. And I got an exception "No webdriver is bound to current thread: 1. You need to call open(url) first" when run the test. With Selenide '4.14.2' everything works like a charm however I would like to use new Selenide. Could u please help me?
driver = (AppiumDriver) WebDriverRunner.getWebDriver(); in AppiumDriverProvider
@Guice(modules = {BaseDriverModule.class, IosBinds.class})
public class IosChooseLocationTest extends ChooseLocationTest {
public void checkChooseLocationScreen() {
// TODO Add verification of all elements, check methods should be in ChooseLocationScreen
}
}
public abstract class ChooseLocationTest extends BaseTest {
@TmsLink("2")
@Test(description = "Check all elements of choose new location")
public void chooseLocationTest() {
}
}
@Guice(modules = {AppiumServiceModule.class})
@Singleton
public class BaseTest {
@Inject
protected AppiumService appiumService;
@Inject
protected AppiumDriver driver;
@BeforeSuite
public void beforeSuite() {}
@AfterSuite(alwaysRun = true)
public void afterSuite() {}
}
public class BaseDriverModule extends AbstractModule {
public static final String ANDROID = "android";
public static final String IOS = "ios";
@Override
protected void configure() {
switch (load().mobileOS()) {
case ANDROID ->
com.codeborne.selenide.Configuration.browser = AndroidDriverProvider.class.getName();
case IOS ->
com.codeborne.selenide.Configuration.browser = IosDriverProvider.class.getName();
}
bind(new TypeLiteral<AppiumDriver>() {}).toProvider(new TypeLiteral<AppiumDriverProvider>() {});
}
}
@Singleton
public class AppiumDriverProvider implements Provider<AppiumDriver> {
private static AppiumDriver driver;
public AppiumDriver get() {
if (driver != null && driver.getSessionId() != null)
return driver;
else
return createDriver();
}
private AppiumDriver createDriver() {
driver = (AppiumDriver) WebDriverRunner.getWebDriver();
return driver;
}
}
@Singleton
public class AppiumService {
private AppiumServiceBuilder appiumServiceBuilder;
private AppiumDriverLocalService localService;
@Inject
public AppiumService() {
if (localService != null && localService.isRunning()) {
} else {
runServer();
}
}
public void runServer() {
appiumServiceBuilder = new AppiumServiceBuilder()
.withAppiumJS(new File(load().appiumJsPath()))
.usingPort(load().appiumPort())
.withArgument(GeneralServerFlag.LOG_LEVEL, load().appiumLogLevel());
localService = appiumServiceBuilder.build();
localService.start();
}
public void stopServer() {
localService.stop();
}
}
md5-db48e83c10f81193751040d2ead99a2a
public class IosDriverProvider implements WebDriverProvider {
public WebDriver createDriver(DesiredCapabilities capabilities) {
capabilities.setCapability(PLATFORM_NAME, "iOS");
capabilities.setCapability(UDID, load().udid());
capabilities.setCapability(DEVICE_NAME, load().deviceName());
capabilities.setCapability(APP, load().appPath());
capabilities.setCapability(AUTOMATION_NAME, "XCUITest");
capabilities.setCapability(PLATFORM_VERSION, load().platformVersion());
capabilities.setCapability(CLEAR_SYSTEM_FILES, true);
capabilities.setCapability(AUTO_ACCEPT_ALERTS, true);
capabilities.setCapability(XCODE_ORG_ID, "********");
capabilities.setCapability(XCODE_SIGNING_ID, "***********");
capabilities.setCapability("appium:useJSONSource", true);
capabilities.setCapability("appium:realDeviceScreenshotter", true);
try {
return new IOSDriver<SelenideElement>(new URL(
String.format("http://%s:%s/wd/hub", ConfigLoader.load().appiumHost(), ConfigLoader.load().appiumPort())), capabilities);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
md5-3625c5166b3bc2ea3c36d60db91cf9bd
com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Error in custom provider, java.lang.IllegalStateException: No webdriver is bound to current thread: 1. You need to call open(url) first.
while locating com.wood.common.providers.AppiumDriverProvider
while locating io.appium.java_client.AppiumDriver
for field at com.wood.client.tests.common.BaseTest.driver(BaseTest.java:14)
while locating com.wood.client.tests.ios.location.IosChooseLocationTest
1 error
at com.google.inject.internal.InternalProvisionException.toProvisionException(InternalProvisionException.java:226)
at com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1097)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1131)
at org.testng.internal.ClassImpl.getInstanceFromGuice(ClassImpl.java:127)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:103)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:167)
at org.testng.TestClass.getInstances(TestClass.java:102)
at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:82)
at org.testng.TestClass.init(TestClass.java:74)
at org.testng.TestClass.<init>(TestClass.java:39)
at org.testng.TestRunner.initMethods(TestRunner.java:457)
at org.testng.TestRunner.init(TestRunner.java:336)
at org.testng.TestRunner.init(TestRunner.java:289)
at org.testng.TestRunner.<init>(TestRunner.java:180)
at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:613)
at org.testng.SuiteRunner.init(SuiteRunner.java:178)
at org.testng.SuiteRunner.<init>(SuiteRunner.java:112)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1306)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1282)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1131)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: java.lang.IllegalStateException: No webdriver is bound to current thread: 1. You need to call open(url) first.
at com.codeborne.selenide.impl.WebDriverThreadLocalContainer.getWebDriver(WebDriverThreadLocalContainer.java:121)
at com.codeborne.selenide.WebDriverRunner.getWebDriver(WebDriverRunner.java:81)
at com.wood.common.providers.AppiumDriverProvider.createDriver(AppiumDriverProvider.java:23)
at com.wood.common.providers.AppiumDriverProvider.get(AppiumDriverProvider.java:19)
at com.wood.common.providers.AppiumDriverProvider.get(AppiumDriverProvider.java:10)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:85)
at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:77)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:59)
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61)
at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:52)
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:147)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:124)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306)
at com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1094)
... 22 more
Hi @getloud !
Yes, this change was intentionally made in Selenide 5.0.0 to avoid situations when people occasionally tried to access WebDriver or find WebElements before they actually did open a browser.
It's a little bit weird in case of mobile applications: currently Selenide requires you to call just open() before doing any other actions with AppiumDriver. We are thinking on a solution.
In your case, I would suggest to remove field @Inject protected AppiumDriver driver; from BaseTest.
If some places need a webdriver, they can use just (AppiumDriver) WebDriverRunner.getWebDriver().
Hi @getloud !
Yes, this change was intentionally made in Selenide 5.0.0 to avoid situations when people occasionally tried to access
WebDriveror findWebElements before they actually did open a browser.
It's a little bit weird in case of mobile applications: currently Selenide requires you to call justopen()before doing any other actions withAppiumDriver. We are thinking on a solution.In your case, I would suggest to remove field
@Inject protected AppiumDriver driver;fromBaseTest.
If some places need a webdriver, they can use just(AppiumDriver) WebDriverRunner.getWebDriver().
@asolntsev When I added open() before getWebDriver I got next exception
1) Error injecting constructor, org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'macs-MacBook-Pro.local', ip: 'fe80:0:0:0:c3c:b521:bdc1:d9d5%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '15.0.1'
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities {acceptInsecureCerts: true, acceptSslCerts: true, app: /Users/mac/Testing/Raketa D..., autoAcceptAlerts: true, automationName: XCUITest, browserName: , clearSystemFiles: true, databaseEnabled: false, deviceName: WoodPhone, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, noReset: true, pageLoadStrategy: normal, platform: MAC, platformName: iOS, platformVersion: 14.2, realDeviceScreenshotter: true, takesScreenshot: true, udid: c173b6fe90b21377b552ef7a642..., useJSONSource: true, webStorageEnabled: false, xcodeOrgId: UA4R9ZQWLZ, xcodeSigningId: iPhone Developer}
Session ID: 8a5ea2ff-7ff7-4a59-80a8-ec1917b90e71
at com.raketa.client.tests.ios.location.IosChooseLocationTest.<init>(IosChooseLocationTest.java:9)
while locating com.raketa.client.tests.ios.location.IosChooseLocationTest
1 error
at com.google.inject.internal.InternalProvisionException.toProvisionException(InternalProvisionException.java:226)
at com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1097)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1131)
at org.testng.internal.ClassImpl.getInstanceFromGuice(ClassImpl.java:127)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:103)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:167)
at org.testng.TestClass.getInstances(TestClass.java:102)
at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:82)
at org.testng.TestClass.init(TestClass.java:74)
at org.testng.TestClass.<init>(TestClass.java:39)
at org.testng.TestRunner.initMethods(TestRunner.java:457)
at org.testng.TestRunner.init(TestRunner.java:336)
at org.testng.TestRunner.init(TestRunner.java:289)
at org.testng.TestRunner.<init>(TestRunner.java:180)
at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:613)
at org.testng.SuiteRunner.init(SuiteRunner.java:178)
at org.testng.SuiteRunner.<init>(SuiteRunner.java:112)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1306)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1282)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1131)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'macs-MacBook-Pro.local', ip: 'fe80:0:0:0:c3c:b521:bdc1:d9d5%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '15.0.1'
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities {acceptInsecureCerts: true, acceptSslCerts: true, app: /Users/mac/Testing/Raketa D..., autoAcceptAlerts: true, automationName: XCUITest, browserName: , clearSystemFiles: true, databaseEnabled: false, deviceName: WoodPhone, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, noReset: true, pageLoadStrategy: normal, platform: MAC, platformName: iOS, platformVersion: 14.2, realDeviceScreenshotter: true, takesScreenshot: true, udid: c173b6fe90b21377b552ef7a642..., useJSONSource: true, webStorageEnabled: false, xcodeOrgId: UA4R9ZQWLZ, xcodeSigningId: iPhone Developer}
Session ID: 8a5ea2ff-7ff7-4a59-80a8-ec1917b90e71
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:802)
at com.codeborne.selenide.webdriver.BrowserResizer.adjustBrowserSize(BrowserResizer.java:32)
at com.codeborne.selenide.webdriver.WebDriverFactory.createWebDriver(WebDriverFactory.java:73)
at com.codeborne.selenide.drivercommands.CreateDriverCommand.createDriver(CreateDriverCommand.java:68)
at com.codeborne.selenide.impl.WebDriverThreadLocalContainer.createDriver(WebDriverThreadLocalContainer.java:153)
at com.codeborne.selenide.impl.WebDriverThreadLocalContainer.getAndCheckWebDriver(WebDriverThreadLocalContainer.java:139)
at com.codeborne.selenide.WebDriverRunner.getAndCheckWebDriver(WebDriverRunner.java:97)
at com.codeborne.selenide.impl.StaticDriver.getAndCheckWebDriver(StaticDriver.java:62)
at com.codeborne.selenide.SelenideDriver.getAndCheckWebDriver(SelenideDriver.java:188)
at com.codeborne.selenide.drivercommands.Navigator.open(Navigator.java:95)
at com.codeborne.selenide.SelenideDriver.open(SelenideDriver.java:80)
at com.codeborne.selenide.Selenide.open(Selenide.java:122)
at com.raketa.common.providers.AppiumDriverProvider.createDriver(AppiumDriverProvider.java:24)
at com.raketa.common.providers.AppiumDriverProvider.get(AppiumDriverProvider.java:20)
at com.raketa.client.tests.common.BaseTest.<init>(BaseTest.java:22)
at com.raketa.client.tests.common.location.ChooseLocationTest.<init>(ChooseLocationTest.java:14)
at com.raketa.client.tests.ios.location.IosChooseLocationTest.<init>(IosChooseLocationTest.java:9)
at com.raketa.client.tests.ios.location.IosChooseLocationTest$$FastClassByGuice$$9a8757b8.newInstance(<generated>)
at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:114)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306)
at com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1094)
... 22 more
@getloud Add Configuration.browserSize = null; before AppiumDriverProvider.java:20
@getloud I hope we can close the issue now. Feel free to add comments here if needed.
Most helpful comment
@getloud Add
Configuration.browserSize = null;beforeAppiumDriverProvider.java:20