Alex
Alex

Reputation: 41

Selenide and ChromeDriver (Java)

Can somebody help me, please? I'm working with Selenide framework using Java. Selenide has method for opening browser. It look's like: Selenide.open("http://www.google.com");

By default it uses FireFox. For use Chrome I need to set System property, like:

   @BeforeTest
    public void beforeTest() {
        Configuration.timeout=5000;
        System.setProperty("webdriver.chrome.driver", "chromedriver");
    }

Chromedriver in my default project folder. What I'm doing wrong?

Upvotes: 1

Views: 10240

Answers (10)

user9317883
user9317883

Reputation: 1

At me works so

  @BeforeClass
  public void baseSetUp() {
                File file = new File("/path/to/chromedriver.exe");
                System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
                driver = new ChromeDriver();
                WebDriverRunner.setWebDriver(driver);}

Upvotes: 0

Javed Ahmed
Javed Ahmed

Reputation: 233

You are not defining the value of Configuration.browser parameter. By default selenide will launch the firefox browser. In order to launch the chrome you should add following line Configuration.browser = "chrome";

Following code should work for you .

@BeforeTest
    public void beforeTest() {

System.setProperty("webdriver.chrome.driver", "chromedriver");
Configuration.browser = "chrome";
Configuration.timeout=5000;


    }

Upvotes: 3

inmydelorean
inmydelorean

Reputation: 518

To simplify all your work with browser's driver just add webdrivermanager dependency to your pom.xml (for Maven) or build.gradle (for Gradle). Then add

ChromeDriverManager.getInstance().setup();
Configuration.browser = "chrome";

as a precondition for your tests and they'll run in Chrome. You will not need to download any files. And you can use other browser by changing the value to its name (e.g. "firefox").

Upvotes: 0

Vivyen
Vivyen

Reputation: 85

you can use selenide configuration as below for the chrome browser

Configuration.browser = "chrome";

You can see this post for more details

Upvotes: 2

Mzia
Mzia

Reputation: 456

If driver is in your project folder, you can write:

  System.setProperty("webdriver.chrome.driver", "src\\packages\\to\\driver\\between\\src\\and\\driver's\\folder\\chromedriver.exe");

Upvotes: 0

Amar Nath Yadav
Amar Nath Yadav

Reputation: 57

@BeforeTest
public void setUp ()
{
    System.setProperty("webdriver.chrome.driver", "chromedriver exe file path");
    Configuration.timeout=5000;
    Configuration.browser = "chrome";
    open ("https://www.google.com");
}

Upvotes: 1

rikkitiikkitavvi
rikkitiikkitavvi

Reputation: 11

String chromeDriverPath = "/path/to/chromedriver.exe";
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService Service = Builder
    .usingAnyFreePort()
    .withLogFile(new File("./chromdriver.log"))
    .usingDriverExecutable(new File(chromeDriverPath))
    .build();
CommandExecutor commandExecutor = new DriverCommandExecutor(Service);
RemoteWebDriver driver = new RemoteWebDriver(commandExecutor, capabilities);
WebDriverRunner.setWebDriver(driver); //Set driver that Selenide should use

why you should use Chrome Service read here: http://www.qaautomationsimplified.com/selenium/run-chromedriver-with-chrome-driver-service-to-reduce-script-execution-time-significantly/

Upvotes: 0

cat-ninja
cat-ninja

Reputation: 39

You need just simply do this:

@Before
public void setUp ()
{
    System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
    Configuration.browser = "chrome";
    open ("your link here");
}

Upvotes: 2

Konstantin Firsanov
Konstantin Firsanov

Reputation: 64

Simply add the extension *.exe to the filename so, that you have full file name with its extension. I usually add the full path to the file name too. I came across this issue, when I configured webdriver sampler for jmeter. And I had to provide full path to chromedriver in the sampler settings. Later this approach turned out to be right with selenide too. More details about what I've mentioned can be found here - How to use Selenium with webdriver, perhaps it will be a useful solution to your task.

Upvotes: 0

Bruno Toffolo
Bruno Toffolo

Reputation: 1554

In this GitHub wiki page there is a nice explanation about how Selenide creates the WebDriver.

As stated in the section "How to run Selenide with another browser", you should set the driver by calling

System.setProperty("webdriver.chrome.driver", "/path/to/your/chrome/driver");
WebDriver driver = new ChromeDriver();

You could take a look at this SO question to retrieve some additional information.

Upvotes: 0

Related Questions