/java/

Selenide example 1

2013-12-10 22:22:24

package selenide;

import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;

import java.util.UUID;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;

public class SomeClassTest {

    private static final String HTTP_BASE = "http://webpage.loc/admin";

    @BeforeClass
    public static void login() {
        open(HTTP_BASE);
        $(By.name("username")).setValue("admin");
        $(By.name("password")).setValue("admin");
        $(By.name("submit")).click();
    }

    @Test
    public void createNewAds() {
        //arrange
        open(HTTP_BASE + "/ads/form");
        $(By.name("content")).setValue(gerRandomValueWithPrefix("Content"));
        $(By.id("radioType2")).click();

        //act
        $(By.id("createNewAds")).click();

        //assert
        $(By.className("alert-success")).shouldHave(text("Add created"));
    }

    private String gerRandomValueWithPrefix(String prefix) {
        return prefix + " " + UUID.randomUUID();
    }

    @AfterClass
    public static void logout() {
        $(By.id("logoutButton")).click();
//      clearBrowserCache();
    }

}