Run Selenide web app test

Step 1: Setup environment

Requirements

  • JDK (Highly recommended to use JDK 8 SE)
  • Java build framework
  • Selenide framework
  • Access key
    • You can generate an Access key using the following instruction – Access key
  • Billing unit
    • The billing unit is your team’s unique identifier, or just the word “personal” in the case of an individual account.
      More information can be found here.

Step 2: Run sample test

NOTE: The Selenide adds goog:chromeOptions capability inside ChromeDriverFactory class and it will cause the invalid argument: cannot parse capability error if you will start a WebDriver session using default Selenide way – set capabilities to Configuration.browserCapabilities and just call Selenide.open method.
According to this, we recommend to start a RemoteWebDriver session and then just call WebDriverRunner.setWebDriver using received WebDriver instance.

package com.mobitru;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.WebDriverRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;


public class SelenideDemo {
    private static final String PROJECT_NAME = "--------- BILLING_UNIT -----------";

    private static final String ACCESS_KEY = "--------- YOU ACCESS KEY -----------";
    private static final String APPIUM_HUB = "app.mobitru.com";
    private static final String PLATFORM_VERSION = "11"; //or 15.6 for iOS
    private static final String BROWSER_NAME = "chrome"; //or safari for iOS
    private static final String DEVICE_NAME = "GOOGLE Pixel 4 XL"; //or IPHONE iPhone13,2 for iOS

    private final DesiredCapabilities capabilities;

    

    public SelenideDemo() {
        capabilities = new DesiredCapabilities();
        capabilities.setCapability("appium:platformName", "Android"); //or iOS
        capabilities.setCapability("appium:browserName", BROWSER_NAME);
        capabilities.setCapability("appium:deviceName", DEVICE_NAME);
    }

    @Before
    public void before() throws Exception {
        String connectionUrl = format("https://%s:%s@%s/wd/hub", PROJECT_NAME, ACCESS_KEY, APPIUM_HUB);
        if (!WebDriverRunner.hasWebDriverStarted()) {
            WebDriver driver = new RemoteWebDriver(new URL(connectionUrl), capabilities);
            WebDriverRunner.setWebDriver(driver);
        }
    }

    @Test
    public void demoTest() {
         final String openUrl = "https://www.google.com/";
        Selenide.open(openUrl);
        Selenide.$(By.name("q")).shouldBe(Condition.exist);
        assertEquals("Current url is incorrect", openUrl, Selenide.webdriver().driver().url());
        assertEquals("Page title is incorrect", "Google", Selenide.title());
    }

    @After
    public void after() {
        Selenide.closeWebDriver();
    }
}
Scroll to Top