From cbfcfd17c73e2b915133145bb49768eb75e47e7d Mon Sep 17 00:00:00 2001 From: Stefan Ludwig Date: Wed, 24 Aug 2016 18:02:08 +0200 Subject: [PATCH 1/2] Added missing third party properties to marionette support module --- .../src/license/THIRD-PARTY.properties | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 webtester-support-marionette/src/license/THIRD-PARTY.properties diff --git a/webtester-support-marionette/src/license/THIRD-PARTY.properties b/webtester-support-marionette/src/license/THIRD-PARTY.properties new file mode 100644 index 0000000..9cde842 --- /dev/null +++ b/webtester-support-marionette/src/license/THIRD-PARTY.properties @@ -0,0 +1,15 @@ +# Generated by org.codehaus.mojo.license.AddThirdPartyMojo +#------------------------------------------------------------------------------- +# Already used licenses in project : +# - ASL, version 2 +# - Apache License, Version 2.0 +# - LGPL, version 2.1 +# - MIT License +# - The Apache License, Version 2.0 +# - The Apache Software License, Version 2.0 +#------------------------------------------------------------------------------- +# Please fill the missing licenses for dependencies : +# +# +#Fri Jul 29 18:18:37 CEST 2016 +cglib--cglib-nodep--2.1_3=The Apache Software License, Version 2.0 From 6ca4dbb0012568f6700fa7981a0ea53e09bc1684 Mon Sep 17 00:00:00 2001 From: Stefan Ludwig Date: Wed, 24 Aug 2016 18:02:26 +0200 Subject: [PATCH 2/2] Added performance enhanced implementation of Selenium's Select --- .../testit/webtester/pageobjects/Select.java | 30 +++++++------- .../pageobjects/utils/EnhancedSelect.java | 40 +++++++++++++++++++ 2 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/utils/EnhancedSelect.java diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/Select.java b/webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/Select.java index c0b0445..04befed 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/Select.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/Select.java @@ -15,6 +15,7 @@ import info.novatec.testit.webtester.eventsystem.events.pageobject.SelectedByTextEvent; import info.novatec.testit.webtester.eventsystem.events.pageobject.SelectedByValueEvent; import info.novatec.testit.webtester.utils.Asserts; +import info.novatec.testit.webtester.pageobjects.utils.EnhancedSelect; /** @@ -84,8 +85,9 @@ public void selectByValue(final String... values) { public void execute(PageObject pageObject) { Asserts.assertEnabledAndVisible(pageObject); deselectIfMultiple(); + EnhancedSelect select = getSelect(); for (String value : values) { - getSelect().selectByValue(value); + select.selectByValue(value); logger.debug(logMessage("selected option with value: {}"), value); fireEventAndMarkAsUsed(new SelectedByValueEvent(pageObject, value)); } @@ -112,8 +114,9 @@ public void selectByIndex(final int... indices) { public void execute(PageObject pageObject) { Asserts.assertEnabledAndVisible(pageObject); deselectIfMultiple(); + EnhancedSelect select = getSelect(); for (int index : indices) { - getSelect().selectByIndex(index); + select.selectByIndex(index); logger.debug(logMessage("selected option with index: {}"), index); fireEventAndMarkAsUsed(new SelectedByIndexEvent(pageObject, index)); } @@ -225,11 +228,8 @@ public Integer getFirstSelectedIndex() { @Override public Integer execute(PageObject pageObject) { try { - List allOptions = getAllOptions(); - if (allOptions.isEmpty()) { - return null; - } - return allOptions.indexOf(getFirstSelectedOption()); + String indexAsString = getFirstSelectedOption().getAttribute("index"); + return Integer.valueOf(indexAsString); } catch (NoSuchElementException e) { logger.warn(logMessage(NOTHING_SELECTED_INDEX)); return null; @@ -252,11 +252,9 @@ public List getAllSelectedIndices() { @Override public List execute(PageObject pageObject) { List selectedIndices = new LinkedList(); - List allOptions = getAllOptions(); - if (!allOptions.isEmpty()) { - for (WebElement option : getAllSelectedOptions()) { - selectedIndices.add(allOptions.indexOf(option)); - } + for (WebElement option : getAllSelectedOptions()) { + String indexAsString = option.getAttribute("index"); + selectedIndices.add(Integer.valueOf(indexAsString)); } return selectedIndices; } @@ -353,7 +351,7 @@ public Integer execute(PageObject pageObject) { * @return true if it is, false otherwise * @since 0.9.0 */ - public Boolean isMultselect() { + public Boolean isMultiSelect() { return executeAction(new PageObjectCallbackWithReturnValue() { @Override @@ -364,8 +362,8 @@ public Boolean execute(PageObject pageObject) { }); } - private org.openqa.selenium.support.ui.Select getSelect() { - return new org.openqa.selenium.support.ui.Select(getWebElement()); + private EnhancedSelect getSelect() { + return new EnhancedSelect(getWebElement()); } private List getAllOptions() { @@ -381,7 +379,7 @@ private WebElement getFirstSelectedOption() { } private void deselectIfMultiple() { - if (isMultselect()) { + if (isMultiSelect()) { getSelect().deselectAll(); } } diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/utils/EnhancedSelect.java b/webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/utils/EnhancedSelect.java new file mode 100644 index 0000000..395aaed --- /dev/null +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/pageobjects/utils/EnhancedSelect.java @@ -0,0 +1,40 @@ +package info.novatec.testit.webtester.pageobjects.utils; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + + +/** + * This implementation of Selenium's {@link Select} helper class fixes some issues with the original implementation. + *

+ * Fixed Issues: + *

    + *
  • {@link #getFirstSelectedOption()} has very bad performance in case of great number of options
  • + *
  • {@link #getAllSelectedOptions()} has very bad performance in case of great number of options
  • + *
+ * + * @since 1.2 + */ +public class EnhancedSelect extends Select { + + private final WebElement element; + + public EnhancedSelect(WebElement element) { + super(element); + this.element = element; + } + + @Override + public WebElement getFirstSelectedOption() { + return element.findElement(By.cssSelector("option:checked")); + } + + @Override + public List getAllSelectedOptions() { + return element.findElements(By.cssSelector("option:checked")); + } + +}