Selenoidでorg.openqa.selenium.InvalidArgumentException: Requested environment is not availableエラーがでる

# はじめに

Gauge+Kotlin+Selenide+SelenoidでE2Eの環境を作ろうとしてつまづいたエラーをまとめます
環境構築などに関しては以下の記事を参考にしています

https://qiita.com/nobutak/items/1eaa61e5323cacec6a6a

https://qiita.com/nobutak/items/31d0d91fb336aebc75d5

https://yuya-hirooka.hatenablog.com/entry/2021/07/10/220438

# 問題

環境構築を行って、`Setup`を書いたあとに試しに`mvn test`を実行したところ`Setup`でエラーが発生しました

```
/usr/local/bin/gauge run --machine-readable --hide-suggestion --simple-console /home/watanabejin/workspace/gauge-e2e/specs/example.spec:3
Testing started at 14:30 ...
exit status 1
Installed version of gauge-java (0.9.1) does not match with dependency gauge-java () specified in pom.xml file
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Failed: Before Suite
Message: org.openqa.selenium.InvalidArgumentException: Requested environment is not available
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'watanabejin-Latitude-3520', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.14.0-1057-oem', java.version: '18'
Driver info: driver.version: RemoteWebDriver
remote stacktrace: 
Stack Trace:
java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:1002)
java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
Setup.beforeSuit(Setup.kt:17)
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
java.base/java.lang.reflect.Method.invoke(Method.java:577)
com.thoughtworks.gauge.execution.MethodExecutor.execute(MethodExecutor.java:28)
com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.executeHook(HooksExecutor.java:92)
com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.execute(HooksExecutor.java:78)
com.thoughtworks.gauge.execution.HooksExecutor.execute(HooksExecutor.java:35)
com.thoughtworks.gauge.processor.MethodExecutionMessageProcessor.executeHooks(MethodExecutionMessageProcessor.java:55)
com.thoughtworks.gauge.processor.SuiteExecutionStartingProcessor.process(SuiteExecutionStartingProcessor.java:26)
com.thoughtworks.gauge.RunnerServiceHandler.lambda$startExecution$1(RunnerServiceHandler.java:62)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.base/java.lang.Thread.run(Thread.java:833)

Successfully generated html-report to => /home/watanabejin/workspace/gauge-e2e/reports/html-report/index.html

Specifications:	0 executed	0 passed	0 failed	0 skipped
Scenarios:	0 executed	0 passed	0 failed	0 skipped

Total time taken: 740ms

プロセスは終了コード 1 で終了しました
```

どうやら環境変数がおかしいと怒られているようです

以下が`Setup`を行っているコードです

```kotlin:Setup.kt
import com.codeborne.selenide.Configuration
import com.codeborne.selenide.WebDriverRunner
import com.thoughtworks.gauge.BeforeSuite
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver
import java.net.URI

class Setup {
    @BeforeSuite
    fun beforeSuit() {
        val capabilities = DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("browserVersion", "92.0");
        capabilities.setCapability("enableLog", true);
        capabilities.setCapability("enableVNC", true);
        capabilities.setCapability("enableVideo", true);
        val driver = RemoteWebDriver(
            URI.create("http://localhost:4445/wd/hub").toURL(),
            capabilities
        );
        WebDriverRunner.setWebDriver(driver);

        Configuration.fastSetValue = true;
    }
}
```

# 解決方法

まずSelenoidコンテナで読み込まれている設定ファイルを確認しました

```json:/selenoid/config/browser.json
{
  "chrome": {
    "default": "90.0",
    "versions": {
      "90.0": {
        "image": "selenoid/vnc_chrome:90.0",
        "port": "4444",
        "tmpfs": {"/tmp": "size=512m", "/var": "size=128m"},
        "path": "/"
      }
    }
  },
}
```

すると`Versions`が`90.0`しか設定されていませんでした
なので、`Setup`の`browserVersion`を`90.0`に変更したところ動くようになりました

```kotlin:Setup.kt
import com.codeborne.selenide.Configuration
import com.codeborne.selenide.WebDriverRunner
import com.thoughtworks.gauge.BeforeSuite
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver
import java.net.URI

class Setup {
    @BeforeSuite
    fun beforeSuit() {
        val capabilities = DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("browserVersion", "90.0"); // 変更
        capabilities.setCapability("enableLog", true);
        capabilities.setCapability("enableVNC", true);
        capabilities.setCapability("enableVideo", true);
        val driver = RemoteWebDriver(
            URI.create("http://localhost:4445/wd/hub").toURL(),
            capabilities
        );
        WebDriverRunner.setWebDriver(driver);

        Configuration.fastSetValue = true;
    }
}
```

# おわりに

E2Eの経験がまったくないので、最後までやれるか不安です

# 参考

https://qiita.com/nobutak/items/1eaa61e5323cacec6a6a

https://qiita.com/nobutak/items/31d0d91fb336aebc75d5

https://yuya-hirooka.hatenablog.com/entry/2021/07/10/220438