Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/main/java/aquality/selenium/elements/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,31 @@ public IElementStateProvider state() {
}

@Override
public String getAttribute(final String attr, HighlightState highlightState, long timeout) {
public String getAttribute(final String attr, HighlightState highlightState) {
getLogger().debug(getLocManager().getValue("loc.el.getattr"), attr);
if (highlightState.equals(HighlightState.HIGHLIGHT)) {
getJsActions().highlightElement();
}
return String.valueOf(ConditionalWait.<String>waitFor(y -> getElement(timeout).getAttribute(attr), timeout + 5L));
return String.valueOf(ConditionalWait.<String>waitFor(y -> getElement().getAttribute(attr)));
}

@Override
public String getAttribute(final String attr, long timeout) {
return getAttribute(attr, HighlightState.NOT_HIGHLIGHT, timeout);
public String getAttribute(final String attr) {
return getAttribute(attr, HighlightState.NOT_HIGHLIGHT);
}

@Override
public String getAttribute(final String attr) {
return getAttribute(attr, HighlightState.NOT_HIGHLIGHT, timeoutCondition);
public String getCssValue(final String propertyName, HighlightState highlightState) {
getLogger().debug(getLocManager().getValue("loc.el.cssvalue"), propertyName);
if (highlightState.equals(HighlightState.HIGHLIGHT)) {
getJsActions().highlightElement();
}
return String.valueOf(ConditionalWait.<String>waitFor(y -> getElement().getCssValue(propertyName)));
}

@Override
public String getAttribute(final String attr, HighlightState highlightState) {
return getAttribute(attr, highlightState, timeoutCondition);
public String getCssValue(final String propertyName) {
return getCssValue(propertyName, HighlightState.NOT_HIGHLIGHT);
}

@Override
Expand Down
32 changes: 15 additions & 17 deletions src/main/java/aquality/selenium/elements/interfaces/IElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,36 +107,34 @@ public interface IElement extends IParent, IElementWithState {
* Gets attribute value of the element.
*
* @param attr Attribute name
* @param highlightState if HIGHLIGHT: create red border around element that we interact while getting text
* @param timeout wait element timeout
* @return Attribute value
*/
String getAttribute(String attr, HighlightState highlightState, long timeout);
String getAttribute(String attr);

/**
* Gets attribute value of the element.
*
* @param attr Attribute name
* @param timeout wait element timeout
* returns attribute value of element with highlighting or not before getting text
* @param highlightState if HIGHLIGHT: create red border around element that we interact while getting text
* @param attr html attribute name
* @return Attribute value
*/
String getAttribute(String attr, long timeout);
String getAttribute(String attr, HighlightState highlightState);

/**
* Gets attribute value of the element.
* Gets css value of the element.
*
* @param attr Attribute name
* @return Attribute value
* @param propertyName css value name
* @return css value
*/
String getAttribute(String attr);
String getCssValue(String propertyName);

/**
* returns attribute value of element with highlighting or not before getting text
* @param highlightState if HIGHLIGHT: create red border around element that we interact while getting text
* @param attr html attribute name
* @return Attribute value
* Gets css value of the element.
*
* @param propertyName css value name
* @param highlightState if HIGHLIGHT: create red border around element that we interact while getting css value
* @return css value
*/
String getAttribute(String attr, HighlightState highlightState);
String getCssValue(String propertyName, HighlightState highlightState);

/**
* set innerHtml via javascript <b>arguments[0].innerHTML='%1$s' </b>.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"loc.combobox.select.by.text" : "Selecting value by text '%s'",
"loc.combobox.get.values" : "Getting values array",
"loc.el.getattr" : "Getting attribute '%1$s'",
"loc.el.cssvalue" : "Getting css value '%1$s'",
"loc.file.reading_exception" : "Exception while reading file: '%s'",
"loc.focusing" : "Focusing",
"loc.get.text" : "Getting text from element",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/localization/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"loc.combobox.select.by.text" : "Выбор значения с текстом '%s'",
"loc.combobox.get.values" : "Получение списка значений",
"loc.el.getattr" : "Получение аттрибута '%1$s'",
"loc.el.cssvalue" : "Получение значения css '%1$s'",
"loc.file.reading_exception" : "Исключение при чтении файла: '%s'%n",
"loc.focusing" : "Взятие элемента в фокус",
"loc.get.text" : "Получение текста элемента",
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/tests/integration/ElementTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import aquality.selenium.elements.ElementState;
import aquality.selenium.elements.ElementType;
import aquality.selenium.elements.ExpectedCount;
import aquality.selenium.elements.HighlightState;
import aquality.selenium.elements.interfaces.*;
import aquality.selenium.waitings.ConditionalWait;
import automationpractice.forms.DropDownForm;
Expand Down Expand Up @@ -182,6 +183,19 @@ public void testRightClick() {
Assert.assertTrue(present, "");
}

@Test
public void testShouldBePossibleToGetCssValue(){
navigate(TheInternetPage.LOGIN);
ITextBox txbUsername = elementFactory.getTextBox(By.id("username"), "username");

String propertyName = "font-family";
String expectedCssValue = "\"Helvetica Neue\", Helvetica, Helvetica, Arial, sans-serif";

Assert.assertEquals(txbUsername.getCssValue(propertyName), expectedCssValue);

Assert.assertEquals(txbUsername.getCssValue(propertyName, HighlightState.HIGHLIGHT), expectedCssValue);
}

private void navigate(TheInternetPage page) {
BrowserManager.getBrowser().navigate().to(page.getAddress());
}
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/tests/integration/WaitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ public void testWaitInvisibility() {

ILabel lblLoading = loadingForm.getLblLoading();
String id = lblLoading.getAttribute("id", HighlightState.HIGHLIGHT);
String id2 = lblLoading.getAttribute("id", HighlightState.HIGHLIGHT, loadingForm.getTimeout());
String id3 = lblLoading.getAttribute("id", loadingForm.getTimeout());

String loadingText = "loading";
Assert.assertEquals(id,loadingText);
Assert.assertEquals(id2,loadingText);
Assert.assertEquals(id3,loadingText);

lblLoading.waitForDisplayed(2L);

Expand Down