From 36716305faf929927c8a97e33a082195525b18ae Mon Sep 17 00:00:00 2001 From: Stefan Ludwig Date: Wed, 24 Aug 2016 09:59:25 +0200 Subject: [PATCH] Use performance enhanced implementation of Selenium's Select when creating events --- .../events/pagefragments/DeselectedByIndicesEvent.java | 6 +++--- .../events/pagefragments/DeselectedByTextsEvent.java | 6 +++--- .../events/pagefragments/DeselectedByValuesEvent.java | 6 +++--- .../events/pagefragments/SelectedByIndexEvent.java | 7 ++++--- .../events/pagefragments/SelectedByIndicesEvent.java | 6 +++--- .../events/pagefragments/SelectedByTextEvent.java | 4 ++-- .../events/pagefragments/SelectedByTextsEvent.java | 6 +++--- .../events/pagefragments/SelectedByValueEvent.java | 4 ++-- .../events/pagefragments/SelectedByValuesEvent.java | 6 +++--- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByIndicesEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByIndicesEvent.java index 6a81a400..4bcafa9c 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByIndicesEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByIndicesEvent.java @@ -8,7 +8,6 @@ import org.apache.commons.lang.StringUtils; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -18,6 +17,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.MultiSelect; import info.novatec.testit.webtester.pagefragments.PageFragment; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -58,7 +58,7 @@ public boolean needsBeforeData() { @Override public PageFragmentEventBuilder setBeforeData(WebElement webElement) { - before = new Select(webElement).getAllSelectedOptions() + before = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("index"))) .map(Integer::parseInt) @@ -73,7 +73,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - after = new Select(webElement).getAllSelectedOptions() + after = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("index"))) .map(Integer::parseInt) diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByTextsEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByTextsEvent.java index 0a569a22..50bdd065 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByTextsEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByTextsEvent.java @@ -8,7 +8,6 @@ import org.apache.commons.lang.StringUtils; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -18,6 +17,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.MultiSelect; import info.novatec.testit.webtester.pagefragments.PageFragment; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -58,7 +58,7 @@ public boolean needsBeforeData() { @Override public PageFragmentEventBuilder setBeforeData(WebElement webElement) { - before = new Select(webElement).getAllSelectedOptions() + before = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getText())) .collect(Collectors.toList()); @@ -72,7 +72,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - after = new Select(webElement).getAllSelectedOptions() + after = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getText())) .collect(Collectors.toList()); diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByValuesEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByValuesEvent.java index b55ce840..cc92163f 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByValuesEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/DeselectedByValuesEvent.java @@ -8,7 +8,6 @@ import org.apache.commons.lang.StringUtils; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -18,6 +17,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.MultiSelect; import info.novatec.testit.webtester.pagefragments.PageFragment; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -58,7 +58,7 @@ public boolean needsBeforeData() { @Override public PageFragmentEventBuilder setBeforeData(WebElement webElement) { - before = new Select(webElement).getAllSelectedOptions() + before = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("value"))) .collect(Collectors.toList()); @@ -72,7 +72,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - after = new Select(webElement).getAllSelectedOptions() + after = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("value"))) .collect(Collectors.toList()); diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndexEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndexEvent.java index 94fa0008..d0a29053 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndexEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndexEvent.java @@ -1,7 +1,6 @@ package info.novatec.testit.webtester.events.pagefragments; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -11,6 +10,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.PageFragment; import info.novatec.testit.webtester.pagefragments.SingleSelect; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -50,8 +50,9 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - Select select = new Select(webElement); - this.index = select.getOptions().indexOf(select.getFirstSelectedOption()); + EnhancedSelect select = new EnhancedSelect(webElement); + String indexAsString = select.getFirstSelectedOption().getAttribute("index"); + this.index = Integer.valueOf(indexAsString); return this; } diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndicesEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndicesEvent.java index af6401e9..25307462 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndicesEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByIndicesEvent.java @@ -8,7 +8,6 @@ import org.apache.commons.lang.StringUtils; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -18,6 +17,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.MultiSelect; import info.novatec.testit.webtester.pagefragments.PageFragment; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -58,7 +58,7 @@ public boolean needsBeforeData() { @Override public PageFragmentEventBuilder setBeforeData(WebElement webElement) { - before = new Select(webElement).getAllSelectedOptions() + before = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("index"))) .map(Integer::parseInt) @@ -73,7 +73,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - after = new Select(webElement).getAllSelectedOptions() + after = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("index"))) .map(Integer::parseInt) diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextEvent.java index 517b82dc..c3455674 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextEvent.java @@ -1,7 +1,6 @@ package info.novatec.testit.webtester.events.pagefragments; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -11,6 +10,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.PageFragment; import info.novatec.testit.webtester.pagefragments.SingleSelect; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -50,7 +50,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - this.text = new Select(webElement).getFirstSelectedOption().getText(); + this.text = new EnhancedSelect(webElement).getFirstSelectedOption().getText(); return this; } diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextsEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextsEvent.java index d5cda89a..178910ca 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextsEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByTextsEvent.java @@ -8,7 +8,6 @@ import org.apache.commons.lang.StringUtils; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -18,6 +17,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.MultiSelect; import info.novatec.testit.webtester.pagefragments.PageFragment; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -58,7 +58,7 @@ public boolean needsBeforeData() { @Override public PageFragmentEventBuilder setBeforeData(WebElement webElement) { - before = new Select(webElement).getAllSelectedOptions() + before = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getText())) .collect(Collectors.toList()); @@ -72,7 +72,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - after = new Select(webElement).getAllSelectedOptions() + after = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getText())) .collect(Collectors.toList()); diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValueEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValueEvent.java index f2da540d..a9b62ddf 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValueEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValueEvent.java @@ -1,7 +1,6 @@ package info.novatec.testit.webtester.events.pagefragments; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -11,6 +10,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.PageFragment; import info.novatec.testit.webtester.pagefragments.SingleSelect; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -50,7 +50,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - this.value = new Select(webElement).getFirstSelectedOption().getAttribute("value"); + this.value = new EnhancedSelect(webElement).getFirstSelectedOption().getAttribute("value"); return this; } diff --git a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValuesEvent.java b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValuesEvent.java index e3b78bd0..30c1fa0f 100644 --- a/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValuesEvent.java +++ b/webtester-core/src/main/java/info/novatec/testit/webtester/events/pagefragments/SelectedByValuesEvent.java @@ -8,7 +8,6 @@ import org.apache.commons.lang.StringUtils; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.Select; import lombok.Getter; @@ -18,6 +17,7 @@ import info.novatec.testit.webtester.events.PageFragmentEventBuilder; import info.novatec.testit.webtester.pagefragments.MultiSelect; import info.novatec.testit.webtester.pagefragments.PageFragment; +import info.novatec.testit.webtester.pagefragments.utils.EnhancedSelect; /** @@ -58,7 +58,7 @@ public boolean needsBeforeData() { @Override public PageFragmentEventBuilder setBeforeData(WebElement webElement) { - before = new Select(webElement).getAllSelectedOptions() + before = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("value"))) .collect(Collectors.toList()); @@ -72,7 +72,7 @@ public boolean needsAfterData() { @Override public PageFragmentEventBuilder setAfterData(WebElement webElement) { - after = new Select(webElement).getAllSelectedOptions() + after = new EnhancedSelect(webElement).getAllSelectedOptions() .stream() .map(element -> StringUtils.defaultString(element.getAttribute("value"))) .collect(Collectors.toList());