Skip to content

Commit

Permalink
Merge ee06004 into 21ae654
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed May 23, 2017
2 parents 21ae654 + ee06004 commit a78a853
Show file tree
Hide file tree
Showing 30 changed files with 1,761 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ chromedriver.log
phantomjsdriver.log
.settings
integration/ScreenshotTest/canTakeScreenshotOfElement/
classes
77 changes: 77 additions & 0 deletions src/test/java/com/codeborne/selenide/CollectionConditionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.codeborne.selenide;

import com.codeborne.selenide.collections.*;
import org.junit.Test;

import java.util.Arrays;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public class CollectionConditionTest {

@Test
public void testSizeIsEmptyListSize() {
CollectionCondition collectionCondition = CollectionCondition.size(10);
assertThat(collectionCondition, instanceOf(ListSize.class));
}

@Test
public void testSizeGreaterThan() {
CollectionCondition collectionCondition = CollectionCondition.sizeGreaterThan(10);
assertThat(collectionCondition, instanceOf(SizeGreaterThan.class));
}

@Test
public void testSizeGraterThenOrEqual() {
CollectionCondition collectionCondition = CollectionCondition.sizeGreaterThanOrEqual(10);
assertThat(collectionCondition, instanceOf(SizeGreaterThanOrEqual.class));
}

@Test
public void testSizeLessThan() {
CollectionCondition collectionCondition = CollectionCondition.sizeLessThan(10);
assertThat(collectionCondition, instanceOf(SizeLessThan.class));
}

@Test
public void testSizeLessThanOrEqual() {
CollectionCondition collectionCondition = CollectionCondition.sizeLessThanOrEqual(10);
assertThat(collectionCondition, instanceOf(SizeLessThanOrEqual.class));
}

@Test
public void testSizeNotEqual() {
CollectionCondition collectionCondition = CollectionCondition.sizeNotEqual(10);
assertThat(collectionCondition, instanceOf(SizeNotEqual.class));
}

@Test
public void testTextsWithObjectsList() {
CollectionCondition collectionCondition = CollectionCondition.texts("One", "Two", "Three");
assertThat(collectionCondition, instanceOf(Texts.class));
assertEquals("Texts content", "Texts [One, Two, Three]", collectionCondition.toString());
}

@Test
public void testTextsWithListOfStrings() {
CollectionCondition collectionCondition = CollectionCondition.texts(Arrays.asList("One", "Two", "Three"));
assertThat(collectionCondition, instanceOf(Texts.class));
assertEquals("Texts content", "Texts [One, Two, Three]", collectionCondition.toString());
}

@Test
public void testExactTextsWithObjectsList() {
CollectionCondition collectionCondition = CollectionCondition.exactTexts("One", "Two", "Three");
assertThat(collectionCondition, instanceOf(ExactTexts.class));
assertEquals("Exact texts content", "Exact texts [One, Two, Three]", collectionCondition.toString());
}

@Test
public void testExactTextsWithListOfStrings() {
CollectionCondition collectionCondition = CollectionCondition.exactTexts(Arrays.asList("One", "Two", "Three"));
assertThat(collectionCondition, instanceOf(ExactTexts.class));
assertEquals("Exact texts content", "Exact texts [One, Two, Three]", collectionCondition.toString());
}
}
190 changes: 190 additions & 0 deletions src/test/java/com/codeborne/selenide/ConditionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,194 @@ public void value() {
assertTrue(Condition.value("John Malkovich").apply(element));
}

@Test
public void elementIsVisible() {
WebElement element = mock(WebElement.class);
when(element.isDisplayed()).thenReturn(true);
assertTrue(Condition.visible.apply(element));
}

@Test
public void elementExists() {
WebElement element = mock(WebElement.class);
when(element.isDisplayed()).thenReturn(true);
assertTrue(Condition.exist.apply(element));
}

@Test
public void elementIsHidden() {
WebElement element = mock(WebElement.class);
when(element.isDisplayed()).thenReturn(false);
assertTrue(Condition.hidden.apply(element));
}

@Test
public void elementHasAttribute() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("name")).thenReturn("selenide");
assertTrue(Condition.attribute("name").apply(element));
}

@Test
public void elementHasAttributeWithGivenValue() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("name")).thenReturn("selenide");
assertTrue(Condition.attribute("name", "selenide").apply(element));
}

@Test
public void elementHasValue() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("value")).thenReturn("selenide");
assertTrue(Condition.value("selenide").apply(element));
}

@Test
public void elementHasValueMethod() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("value")).thenReturn("selenide");
assertTrue(Condition.hasValue("selenide").apply(element));
}

@Test
public void elementHasName() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("name")).thenReturn("selenide");
assertTrue(Condition.name("selenide").apply(element));
}

@Test
public void elementHasType() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("type")).thenReturn("selenide");
assertTrue(Condition.type("selenide").apply(element));
}

@Test
public void elementHasId() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("id")).thenReturn("selenide");
assertTrue(Condition.id("selenide").apply(element));
}

@Test
public void elementMatchesText() {
WebElement element = mock(WebElement.class);
when(element.getText()).thenReturn("selenidehello");
assertTrue(Condition.matchesText("selenide").apply(element));
}

@Test
public void elementHasText() {
WebElement element = mock(WebElement.class);
when(element.getText()).thenReturn("selenidehello");
assertTrue(Condition.hasText("selenide").apply(element));
}

@Test
public void elementHasClass() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("class")).thenReturn("selenide");
assertTrue(Condition.hasClass("selenide").apply(element));
}

@Test
public void elementHasClassForElement() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("class")).thenReturn("selenide");
assertTrue(Condition.hasClass(element, "selenide"));
}

@Test
public void elementHasCssClass() {
WebElement element = mock(WebElement.class);
when(element.getAttribute("class")).thenReturn("selenide");
assertTrue(Condition.hasClass(element, "selenide"));
}

@Test
public void elementEnabled() {
WebElement element = mock(WebElement.class);
when(element.isEnabled()).thenReturn(true);
assertTrue(Condition.enabled.apply(element));
}

@Test
public void elementDisabled() {
WebElement element = mock(WebElement.class);
when(element.isEnabled()).thenReturn(false);
assertTrue(Condition.disabled.apply(element));
}

@Test
public void elementSelected() {
WebElement element = mock(WebElement.class);
when(element.isSelected()).thenReturn(true);
assertTrue(Condition.selected.apply(element));
}

@Test
public void elementNotSelected() {
WebElement element = mock(WebElement.class);
when(element.isSelected()).thenReturn(false);
assertFalse(Condition.selected.apply(element));
}

@Test
public void elementChecked() {
WebElement element = mock(WebElement.class);
when(element.isSelected()).thenReturn(true);
assertTrue(Condition.checked.apply(element));
}


@Test
public void elementNotChecked() {
WebElement element = mock(WebElement.class);
when(element.isSelected()).thenReturn(false);
assertFalse(Condition.checked.apply(element));
}

@Test
public void elementNotCondition() {
WebElement element = mock(WebElement.class);
when(element.isSelected()).thenReturn(false);
assertTrue(Condition.not(Condition.checked).apply(element));
}

@Test
public void elementVisibleButNotSelected() {
WebElement element = mock(WebElement.class);
when(element.isDisplayed()).thenReturn(true);
when(element.isSelected()).thenReturn(false);
assertTrue(Condition.or("Visible, not Selected",
Condition.visible,
Condition.checked).apply(element));
}

@Test
public void conditionBe() {
Condition condition = Condition.be(Condition.visible);
assertEquals("be visible", condition.toString());
}

@Test
public void conditionHave() {
Condition condition = Condition.have(Condition.attribute("name"));
assertEquals("have attribute name", condition.toString());
}

@Test
public void conditionApplyNull() {
Condition condition = Condition.attribute("name");
assertFalse(condition.applyNull());
}

@Test
public void condtionToString() {
Condition condition = Condition.attribute("name").because("it's awesome");
assertEquals("attribute name (because it's awesome)", condition.toString());
}


}
60 changes: 58 additions & 2 deletions src/test/java/com/codeborne/selenide/SelectorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.junit.Test;
import org.openqa.selenium.By;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*;

public class SelectorsTest {
@Test
Expand Down Expand Up @@ -72,4 +72,60 @@ public void byValueUsesXPath() {
By selector = Selectors.byValue("водокачка");
assertEquals("By.cssSelector: [value='водокачка']", selector.toString());
}

@Test
public void byName() {
String name = "selenide";
By nameSelector = Selectors.byName(name);
assertThat(nameSelector, instanceOf(By.ByName.class));
assertEquals("By.name: " + name, nameSelector.toString());
}

@Test
public void byXpath() {
String xpath = "html/body/div[2]/section/div[2]/div/ul/li[2]/a/span/strong/h4";
By nameSelector = Selectors.byXpath(xpath);
assertThat(nameSelector, instanceOf(By.ByXPath.class));
assertEquals("By.xpath: " + xpath, nameSelector.toString());
}

@Test
public void byLinkText() {
String linkText = "click me";
By linkTextSelector = Selectors.byLinkText(linkText);
assertThat(linkTextSelector, instanceOf(By.ByLinkText.class));
assertEquals("By.linkText: " + linkText, linkTextSelector.toString());
}

@Test
public void byPartialLinkText() {
String partialLinkText = "click me";
By linkPartialTextSelector = Selectors.byPartialLinkText(partialLinkText);
assertThat(linkPartialTextSelector, instanceOf(By.ByPartialLinkText.class));
assertEquals("By.partialLinkText: " + partialLinkText, linkPartialTextSelector.toString());
}

@Test
public void byId() {
String id = "clickMe";
By idSelector = Selectors.byId(id);
assertThat(idSelector, instanceOf(By.ById.class));
assertEquals("By.id: " + id, idSelector.toString());
}

@Test
public void byCssSelector() {
String css = ".ql>h3";
By cssSelector = Selectors.byCssSelector(css);
assertThat(cssSelector, instanceOf(By.ByCssSelector.class));
assertEquals("By.cssSelector: " + css, cssSelector.toString());
}

@Test
public void byClassName() {
String className = "selenide";
By classNameSelector = Selectors.byClassName(className);
assertThat(classNameSelector, instanceOf(By.ByClassName.class));
assertEquals("By.className: " + className, classNameSelector.toString());
}
}
Loading

0 comments on commit a78a853

Please sign in to comment.