How can I execute Selenide in Chrome using ChromeDriver

后端 未结 5 2119
甜味超标
甜味超标 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:07

    Another way is to use this command line switch with Maven:

    mvn test -P chrome
    

    It requires the Maven profiles in the pom.xml file such as are seen here:

    https://github.com/selenide-examples/google

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-14 03:13

    You need to tell Selenide what browser to use. That can be done using Configuration properties:

    import com.codeborne.selenide.Configuration;
    
    public class Tests {
    
    @Before
    public void setBrowser() {
        Configuration.browser = "chrome";
    }
    

    Remember: your webdriver should be placed on the standard path. For unix/linux it is: /usr/local/bin; If your webdriver is located on a different path or renamed -- you need to set a system property with right path to the webdriver. For example:

    Windows:

    System.setProperty("webdriver.chrome.driver", "C:\\Program files\\chromedriver.exe");
    

    Linux\Unix:

    System.setProperty("webdriver.chrome.driver","/usr/share/chromedriver");
    

    Make sure that your unix / linux chromedriver is executable. After this, you should have a fully working example (in my case, chromedriver is renamed and has version information):

    import com.codeborne.selenide.*;
    import org.openqa.selenium.*;
    import org.junit.*;
    
    import static com.codeborne.selenide.Selenide.$;
    import static com.codeborne.selenide.Selenide.open;
    import static com.codeborne.selenide.WebDriverRunner.getWebDriver;
    
    public class TestClass {
        @Before
        public void setBrowser(){
            Configuration.browser = "chrome";
            Configuration.browserSize = "1920x1080";
            Configuration.holdBrowserOpen = true;
            System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver_2.33");
        }
    
        @Test
        public void gotoGoogle(){
            open("https://www.google.com");
    
            WebElement searchBox = $(By.xpath("//input[@id='lst-ib']"));
            $(searchBox).shouldBe(Condition.visible).setValue("How can I execute Selenide in Chrome using ChromeDriver").pressEnter();
    
            WebElement firstResultLink = $(By.xpath("(//div[@class='rc']//a)[1]"));
            $(firstResultLink).click();
    
            System.out.println(getWebDriver().getCurrentUrl());
        }
    }
    
    0 讨论(0)
  • 2021-01-14 03:13

    You can use System.setProperty("selenide.browser", "chrome"); for running in the chrome browser. If the same test you need to perform in safari just change the chrome to safari. Eg:

    System.setProperty("selenide.browser", "safari"); open("http://idemo.bspb.ru/");
    
    0 讨论(0)
  • 2021-01-14 03:18

    Try this

    System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
    System.setProperty("selenide.browser", "Chrome");
    open("http://google.com");
    

    You can find some documentation here.

    0 讨论(0)
提交回复
热议问题