Вадим Герасимов |
Андрей Солнцев |
@Test
public void userCanLogin() {
open("/login");
$(By.name("user.name")).setValue("john");
$("#submit").click();
$(".menu").shouldHave(text("Hello, John!"));
}
$(".loading_progress").shouldBe(visible);
$("#menu").shouldHave(text("Hello, John!"));
$(By.name("sex")).shouldNotBe(selected);
import static com.codeborne.selenide.Selectors.*;
$(byText("Привет, чертяка!"))
.shouldBe(visible);
$(withText("ертяк"))
.shouldHave(text("Привет, чертяка"));
DesiredCapabilities cap = htmlUnit();
cap.setCapability(INVALIDSELECTIONERROR, true);
cap.setCapability(INVALIDXPATHERROR, false);
cap.setJavascriptEnabled(true);
WebDriver driver = new HtmlUnitDriver(cap);
open("/my-application/login");
WebElement customer =
driver.findElement(By.id("customerContainer"));
WebElement customer = $("#customerContainer");
assertEquals("Customer profile",
driver.findElement(
By.id("customerContainer")).getText());
$("#customerContainer").shouldHave(
text("Customer profile"),
text("John"),
cssClass("active-profile"));
FluentWait<By> fluentWait = new FluentWait<By>(By.tagName("TEXTAREA"));
fluentWait.pollingEvery(100, TimeUnit.MILLISECONDS);
fluentWait.withTimeout(1000, TimeUnit.MILLISECONDS);
fluentWait.until(new Predicate<By>() {
public boolean apply(By by) {
try {
return browser.findElement(by).isDisplayed();
} catch (NoSuchElementException ex) {
return false;
}
}
});
assertEquals("John", browser.findElement(By.tagName("TEXTAREA")).getAttribute("value"));
$("TEXTAREA").shouldHave(value("John"));
public class SignupPage {
@FindBy(name = "email")
public SelenideElement email;
@FindBy(name = "password")
public SelenideElement password;
@FindBy(id = "signup")
private SelenideElement signup;
public DashboardPage loginValid() {
signup.click();
return page(DashboardPage.class);
}
}
@Test
public void afterSignupUserLandsOnDashboard() {
open("/signup");
SignupPage signupPage = page(SignupPage.class);
signupPage.email.shouldHave(value(""))
.val("existing@email.com");
signupPage.password.shouldHave(value(""))
.val("validPassword");
DashboardPage dashboardPage =
signupPage.signupValid();
// do some dashboard page assertions
}