0

I am trying to configure a Selenide driver within the Selenium-Jupiter framework, to use my remote grid url but it keeps ignoring the configuration, and just runs the local installed browser. Here is how I am trying to configure it. Any idea what might be wrong here?

import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.SelenideConfig;
import io.github.bonigarcia.seljup.SelenideConfiguration;
import static com.codeborne.selenide.Browsers.CHROME;

public abstract class ChromeTest extends BaseTest {

    @SelenideConfiguration
    SelenideConfig selenideConfig = new SelenideConfig();

    private String getSeleniumRemote() {
        System.getProperty("selenide.remote", "");
    }

    public ChromeTest() {
        if (getSelenideRemote().isEmpty()) {
            selenideConfig.proxyEnabled(false)
                .browser(CHROME).startMaximized(false)
                .browserSize("800x1200").browserPosition("50x60");
        } else {
            Configuration.timeout = 6000;
            Configuration.remote = getSelenideRemote();
            selenideConfig.proxyEnabled(false)
                .startMaximized(true).browser(CHROME);
        }
    }

}

I know the regular RemoteWebDriver works and I can get that working but I am hoping to use Selenide in the above example:

Example:

@Test
void testWithRemoteSelenide(@DriverUrl("http://127.1:4444/wd/hub") 
  @DriverCapabilities("browserName=" + CHROME) SelenideDriver driver)

I can get it to work with the annotation, but the problem is that I need that annotation to be conditional on passing a param to the tests. I want to be able to easily switch using grid or local. Thanks for your help anyone.

djangofan
  • 28,471
  • 61
  • 196
  • 289

1 Answers1

0

Ok, after almost 48 hours an no reponse, I finally figured out the solution. Here it is:

//build.gradle
test {
    useJUnitPlatform()
    ignoreFailures = false
    beforeTest { descriptor ->
        logger.lifecycle("Running test: $descriptor.className")
    }
    systemProperty "env", System.getProperty("env")
    def remote = System.getProperty("selenide.remote", "")
    if (!remote.isEmpty()) {
        systemProperty("selenide.remote", remote)
    }
}

Then, in my test base class:

public abstract class ChromeTest extends BaseTest {
    @SelenideConfiguration
    SelenideConfig selenideConfig = new SelenideConfig();
    /**
     * This config is equivilant to the documented method:
     * Example: test(@DriverUrl("http://127.1:4444/wd/hub") 
     *   @DriverCapabilities("browserName=chrome") SelenideDriver sd)
     */
    public ChromeFormTest() {
      if (getSelenideRemote().isEmpty()) {
         selenideConfig.proxyEnabled(false).proxyHost("http://proxy.domain.com")
            .proxyPort(8080)
            .browser(CHROME).startMaximized(false)
            .browserSize("800x1200").browserPosition("50x60");

      } else {
          Configuration.timeout = 6000;
          Configuration.remote = getSelenideRemote();
          selenideConfig.proxyEnabled(false).proxyHost("http://proxy.domain.com")
             .proxyPort(8080)
             .startMaximized(false).browser(CHROME);
        }
    }
}

Then, when I execute, it looks like this:

gradle clean test -Denv=sys -Dselenide.remote=http://127.1:4444/wd/hub 
  --info --tests com.qa.suite.*

And the constructor of each test looks like:

@Test
public void testWhatever(SelenideDriver sd) {
djangofan
  • 28,471
  • 61
  • 196
  • 289