Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private String getDriverSettingsPath(BrowserName browserName, CapabilityType cap
return getDriverSettingsPath(browserName) + "/" + capabilityType.getKey();
}

private String getDriverSettingsPath(BrowserName browserName){
protected String getDriverSettingsPath(BrowserName browserName){
return String.format("/driverSettings/%1$s", browserName.toString().toLowerCase());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public SafariOptions getCapabilities() {

@Override
public String getDownloadDirCapabilityKey() {
return "safari.options.dataDir";
throw new IllegalArgumentException("Download directory for Safari profiles is not supported in capabilities. Please, use separate 'downloadDir' property");
}

@Override
String getDownloadDirectory(BrowserName browserName) {
return String.valueOf(getSettingsFile().getValue(getDriverSettingsPath(getBrowserName()) + "/downloadDir"));
}

@Override
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/aquality/selenium/elements/CheckBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public CheckBoxJsActions getJsActions() {
*/
private void setState(boolean state) {
getLogger().info(String.format("%1$s '%2$s'", getLocManager().getValue("loc.setting.value"), state));
if (state && !getState()) {
getLogger().info(getLocManager().getValue("loc.checkbox.check"), getName(), getElementType(), true);
click();
} else if (!state && getState()) {
getLogger().info(getLocManager().getValue("loc.checkbox.uncheck"), getName(), getElementType(), false);
if (state != getState()) {
click();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/aquality/selenium/elements/ComboBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected String getElementType() {
public void selectByIndex(int index) {
info(LOG_SELECTING_VALUE);
ConditionalWait.waitFor(y -> {
click();
new Select(getElement()).selectByIndex(index);
return true;
});
Expand All @@ -39,6 +40,7 @@ public void selectByIndex(int index) {
public void selectByText(String value) {
getLogger().info(getLocManager().getValue("loc.combobox.select.by.text"), value);
ConditionalWait.waitFor(y -> {
click();
new Select(getElement()).selectByVisibleText(value);
return true;
});
Expand All @@ -54,6 +56,7 @@ public void selectOptionThatContainsText(String text) {
String currentText = el.getText();
getLogger().debug(currentText);
if(currentText.toLowerCase().contains(text.toLowerCase())){
click();
select.selectByVisibleText(currentText);
return true;
}
Expand All @@ -72,6 +75,7 @@ public void selectOptionThatContainsValue(String value) {
String currentValue = el.getAttribute(Attributes.VALUE.toString());
getLogger().debug(currentValue);
if(currentValue.toLowerCase().contains(value.toLowerCase())){
click();
select.selectByValue(currentValue);
return true;
}
Expand All @@ -84,6 +88,7 @@ public void selectOptionThatContainsValue(String value) {
public void selectByValue(String value) {
info(LOG_SELECTING_VALUE);
ConditionalWait.waitFor(y -> {
click();
new Select(getElement()).selectByValue(value);
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,32 @@ public boolean getState() {
infoLoc("loc.checkbox.get.state");
return Boolean.valueOf(executeScript(JavaScript.GET_CHECKBOX_STATE, element).toString());
}

public void check() {
setState(true);
}

public void uncheck() {
setState(false);
}

public boolean isChecked() {
return getState();
}

public void toggle() {
setState(!isChecked());
}

/**
* Set value via JavaScript
*
* @param state value (true/false)
*/
private void setState(boolean state) {
infoLoc(String.format("%1$s '%2$s'", localizationManager.getValue("loc.setting.value"), state));
if (state != getState()) {
click();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public class JsActions {

private static final Configuration configuration = Configuration.getInstance();
private static final String LOG_DELIMITER = "::";
private final Logger logger = Logger.getInstance();
protected final Logger logger = Logger.getInstance();
protected final LocalizationManager localizationManager = LocalizationManager.getInstance();
protected IElement element;
private String type;
private String name;
protected String type;
protected String name;


public JsActions(IElement element, String type, String name) {
Expand Down Expand Up @@ -160,7 +161,7 @@ private String formatJsActionMessage(final String message) {
}

protected void infoLoc(String key) {
logger.info(formatJsActionMessage(LocalizationManager.getInstance().getValue(key)));
logger.info(formatJsActionMessage(localizationManager.getValue(key)));
}

private Browser getBrowser(){
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"loc.element.wasnotfoundinstate" : "Element '%1$s' was not found in state %2$s during %3$s seconds",
"loc.button" : "Button",
"loc.checkbox" : "CheckBox",
"loc.checkbox.check" : "Checking the '%s' %s with value: %s\"",
"loc.checkbox.get.state" : "Getting state",
"loc.checkbox.uncheck" : "Checking the '%s' %s with value: %s\"",
"loc.clicking" : "Clicking",
"loc.clicking.double" : "Clicking double",
"loc.clicking.js" : "Clicking via Javascript",
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/localization/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"loc.element.wasnotfoundinstate" : "Элемент '%1$s' в состоянии %2$s не найден в течении %3$s секунд",
"loc.button" : "Кнопка",
"loc.checkbox" : "Чекбокс",
"loc.checkbox.check" : "Отметка '%s' %s со значением: %s\"",
"loc.checkbox.get.state" : "Получение состояния",
"loc.checkbox.uncheck" : "Снятие отметки '%s' %s со значением: %s\"",
"loc.clicking" : "Клик",
"loc.clicking.double" : "Двойной Клик",
"loc.clicking.js" : "Клик через Javascript",
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@
"startArguments": []
},
"safari": {
"options": {
"safari.options.dataDir": "/Users/username/Downloads"
},
"startArguments": []
"downloadDir": "/Users/username/Downloads"
}
},
"timeouts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public boolean isNewsCheckboxChecked(){
}

public void setNewsChb(){
chbNews.check();
chbNews.getJsActions().check();
}
}
24 changes: 17 additions & 7 deletions src/test/java/tests/usecases/FileDownloadingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import aquality.selenium.elements.interfaces.ILabel;
import aquality.selenium.waitings.ConditionalWait;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.testng.Assert;
import org.testng.annotations.Test;
import tests.BaseTest;
Expand All @@ -12,6 +14,7 @@
import utils.FileUtil;

import java.io.File;
import java.util.ArrayList;

public class FileDownloadingTests extends BaseTest {
@Test
Expand All @@ -27,13 +30,20 @@ public void testDownloading() {
ILabel lblFileContent = elementFactory.getLabel(By.xpath("//pre"), "text file content");
Assert.assertFalse(FileUtil.isFileDownloaded(fileAddress, lblFileContent), "file should not exist before downloading");

BrowserManager.getBrowser().goTo(TheInternetPage.DOWNLOAD.getAddress());
downloaderForm.getLnkDownload(fileName).clickAndWait();

boolean isContentDisplayed = ConditionalWait.waitFor(webDriver -> FileUtil.isFileDownloaded(fileAddress, lblFileContent));
BrowserManager.getBrowser().executeScript(String.format("window.open('%s', '_blank')", TheInternetPage.DOWNLOAD.getAddress()));
ArrayList<String> tabs = new ArrayList<>(BrowserManager.getBrowser().getDriver().getWindowHandles());

Assert.assertTrue(isContentDisplayed, "file was not downloaded to correct directory. Element '" + lblFileContent.getLocator() + "' was not displayed");
BrowserManager.getBrowser().getDriver().switchTo().window(tabs.get(1));
BrowserManager.getBrowser().goTo(TheInternetPage.DOWNLOAD.getAddress());
downloaderForm.getLnkDownload(fileName).getJsActions().clickAndWait();

BrowserManager.getBrowser().getDriver().switchTo().window(tabs.get(0));
ExpectedCondition<Boolean> fileDownloadedExpectedCondition = webDriver -> FileUtil.isFileDownloaded(fileAddress, lblFileContent);
try {
ConditionalWait.waitFor(fileDownloadedExpectedCondition);
} catch (TimeoutException e) {
BrowserManager.getBrowser().quit();
ConditionalWait.waitFor(fileDownloadedExpectedCondition);
}
}


}
5 changes: 1 addition & 4 deletions src/test/resources/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@
"startArguments": []
},
"safari": {
"options": {
"safari.options.dataDir": "/Users/username/Downloads"
},
"startArguments": []
"downloadDir": "/Users/username/Downloads"
}
},
"timeouts": {
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
},
"options": {},
"startArguments": []
},
"safari": {
"downloadDir": "/Users/username/Downloads"
}
},
"timeouts": {
Expand Down