diff --git a/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/Image.java b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/Image.java new file mode 100644 index 00000000..56e57c60 --- /dev/null +++ b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/Image.java @@ -0,0 +1,41 @@ +package ru.yandex.qatools.htmlelements.element; + +import org.openqa.selenium.WebElement; + +/** + * Represents image + * + * @author Nikolay Mulyar proxeter@yandex-team.ru + */ +public class Image extends TypifiedElement { + + public Image(WebElement wrappedElement) { + super(wrappedElement); + } + + /** + * Retrieves path to image from "src" attribute + * + * @return Path to the image + */ + public String getSource() { + return getWrappedElement().getAttribute("src"); + } + + /** + * Retrieves alternative text from "alt" attribute + * + * @return alternative text for image + */ + public String getAlt() { + return getWrappedElement().getAttribute("alt"); + } + + /** + * Click on image + */ + public void click() { + getWrappedElement().click(); + } + +} diff --git a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/PageInitializationTest.java b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/PageInitializationTest.java index 3e4238dd..b5d70af4 100644 --- a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/PageInitializationTest.java +++ b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/PageInitializationTest.java @@ -73,6 +73,18 @@ public void radioShouldHaveCorrectButtonsNumber() { page.getRadio().getButtons().size(), is(equalTo(3))); } + @Test + public void imageFieldShouldNotBeNull() { + assertThat("Image field should be not null after initialization", + page.getImage(), is(notNullValue())); + } + + @Test + public void imageSourceShouldNotBeNull() { + assertThat("Image source attribute should be not empty after initialization", + page.getImage().getSource(), is(not(isEmptyString()))); + } + @Test public void textInputListFiledShouldNotBeNull() { assertThat("List field should be not null after initialization", diff --git a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/testpages/AllElementTypesPage.java b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/testpages/AllElementTypesPage.java index 1bb158fc..46c238f7 100644 --- a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/testpages/AllElementTypesPage.java +++ b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/testpages/AllElementTypesPage.java @@ -4,10 +4,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -import ru.yandex.qatools.htmlelements.element.Button; -import ru.yandex.qatools.htmlelements.element.HtmlElement; -import ru.yandex.qatools.htmlelements.element.Radio; -import ru.yandex.qatools.htmlelements.element.TextInput; +import ru.yandex.qatools.htmlelements.element.*; import java.util.Arrays; import java.util.List; @@ -31,6 +28,7 @@ public AllElementTypesPage(WebDriver webDriver) { private static final String TEXT_INPUT_ID = "text-input"; private static final String BUTTON_ID = "button"; private static final String RADIO_NAME = "radio"; + private static final String IMAGE_NAME = "image"; @FindBy(id = ELEMENT_ID) private WebElement element; @@ -47,6 +45,9 @@ public AllElementTypesPage(WebDriver webDriver) { @FindBy(name = RADIO_NAME) private Radio radio; + @FindBy(name = IMAGE_NAME) + private Image image; + @FindBy(id = TEXT_INPUT_ID) private List textInputList; @@ -76,6 +77,10 @@ public Radio getRadio() { return radio; } + public Image getImage() { + return image; + } + public List getTextInputList() { return textInputList; } @@ -95,6 +100,7 @@ public static WebDriver mockDriver() { WebElement textInput = mock(WebElement.class); WebElement button = mock(WebElement.class); WebElement radioButton = mock(WebElement.class); + WebElement image = mock(WebElement.class); List radioGroup = Arrays.asList(radioButton, radioButton, radioButton); List textInputList = Arrays.asList(textInput, textInput, textInput); List htmlElementList = Arrays.asList(htmlElement, htmlElement, htmlElement); @@ -105,6 +111,7 @@ public static WebDriver mockDriver() { when(driver.findElement(By.id(TEXT_INPUT_ID))).thenReturn(textInput); when(driver.findElement(By.id(BUTTON_ID))).thenReturn(button); when(driver.findElement(By.name(RADIO_NAME))).thenReturn(radioButton); + when(driver.findElement(By.name(IMAGE_NAME))).thenReturn(image); when(driver.findElements(By.name(RADIO_NAME))).thenReturn(radioGroup); when(driver.findElements(By.id(TEXT_INPUT_ID))).thenReturn(textInputList); @@ -118,4 +125,5 @@ public static WebDriver mockDriver() { return driver; } + }