How can I execute Selenide in Chrome using ChromeDriver

后端 未结 5 2120
甜味超标
甜味超标 2021-01-14 02:31

I started using selenide (selenium wrapper api) and must say its a great tool but my only issue is its lack of documentation or usage examples online yet.

Any idea h

5条回答
  •  攒了一身酷
    2021-01-14 03:11

    The below code will help you launch the Chrome Browser with Selenide, and not with the selenium. It means you don't have to issue a close or quit command at the end of the iteration.

    import static com.codeborne.selenide.CollectionCondition.size;
    import static com.codeborne.selenide.Condition.text;
    import static com.codeborne.selenide.Selenide.*;
    import org.junit.Rule;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import com.codeborne.selenide.junit.ScreenShooter;
    
    public class SimpleDateFormatClass {
    
    @Rule
    public ScreenShooter takeScreenshotSelenide = ScreenShooter.failedTests().succeededTests();
    
    @Test
    public void checkGoogleSearchResultsReturnValidResultNumberAndText() {
        System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver_2");
        //Doesn't matter chrome or Chrome as this is case insensitive.
        System.setProperty("selenide.browser", "Chrome");
        open("http://google.com");
        $(By.name("q")).setValue("Selenide").pressEnter();
    
        // assure there are 10 results in the page
        // static import shortcut, place the cursor on the method and press
        // ctrl+shift+m/ cmd+shift+m
        // $ -> driver.findElement, $$ -> driver.findElements
        $$(".iris li.g").shouldHave(size(10));
        $(".iris li.g").shouldHave(text("Selenide World!"));
    }
    

    }

    This should help you even if you are running from the command prompt/ terminal, but if you want to exclusively pass on the Chrome from cmd you can use the "browser" parameter as below

    -Dselenide.browser=chrome
    

提交回复
热议问题