Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image element #57

Merged
merged 3 commits into from
Apr 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ru.yandex.qatools.htmlelements.element;

import org.openqa.selenium.WebElement;

/**
* Represents image <img />
*
* @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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextInput> field should be not null after initialization",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<TextInput> textInputList;

Expand Down Expand Up @@ -76,6 +77,10 @@ public Radio getRadio() {
return radio;
}

public Image getImage() {
return image;
}

public List<TextInput> getTextInputList() {
return textInputList;
}
Expand All @@ -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<WebElement> radioGroup = Arrays.asList(radioButton, radioButton, radioButton);
List<WebElement> textInputList = Arrays.asList(textInput, textInput, textInput);
List<WebElement> htmlElementList = Arrays.asList(htmlElement, htmlElement, htmlElement);
Expand All @@ -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);
Expand All @@ -118,4 +125,5 @@ public static WebDriver mockDriver() {

return driver;
}

}