From 2236065c03495765100b923f1daffef5766c72fe Mon Sep 17 00:00:00 2001 From: iamalittletester Date: Sun, 3 Feb 2019 12:44:08 +0200 Subject: [PATCH 01/24] Iframes tests. --- .../tutorialSolution/pages/BasicPage.java | 10 +++ src/main/resources/forFrameAsWebElement.html | 10 +++ src/main/resources/forFrameWithId.html | 11 ++++ src/main/resources/forFrameWithIndex.html | 8 +++ src/main/resources/fullPage.html | 7 --- src/main/resources/withIframes.html | 7 +++ .../iframesSolution/IframesTest.java | 63 +++++++++++++++++++ 7 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/forFrameAsWebElement.html create mode 100644 src/main/resources/forFrameWithId.html create mode 100644 src/main/resources/forFrameWithIndex.html create mode 100644 src/main/resources/withIframes.html create mode 100644 src/test/java/tutorialSolution/iframesSolution/IframesTest.java diff --git a/src/main/java/tutorialSolution/pages/BasicPage.java b/src/main/java/tutorialSolution/pages/BasicPage.java index ddbb1bb..0809f6f 100644 --- a/src/main/java/tutorialSolution/pages/BasicPage.java +++ b/src/main/java/tutorialSolution/pages/BasicPage.java @@ -64,4 +64,14 @@ public class BasicPage { @FindBy(css = "#level3BravoIdenticalSiblings h3") public List level3BravoIdenticalSiblings; @FindBy(css = "#level3AllIdenticalSiblings div div") public List level3AllIdentical; @FindBy(css = "#level3OneBravoSeveralAlphas h3") public List level3OneBravoSeveralAlphas; + + //iframes page + //button found inside the frame identified by id + @FindBy(css = "#btnForFrameWithId") public WebElement buttonForFrameWithId; + //button found inside the frame identified by index + @FindBy(css = "#btnForFrameWithIndex") public WebElement buttonForFrameWithIndex; + //button found inside the frame identified as a WebElement + @FindBy(css = "#btnForFrameAsWebElement") public WebElement buttonForFrameWithName; + //selector for identifying frame as WebElement (when frame has no id, name and will not be identified by index) + @FindBy(css = "[src*='FrameAsWebElement']") public WebElement frameAsWebElement; } diff --git a/src/main/resources/forFrameAsWebElement.html b/src/main/resources/forFrameAsWebElement.html new file mode 100644 index 0000000..2dc6bfa --- /dev/null +++ b/src/main/resources/forFrameAsWebElement.html @@ -0,0 +1,10 @@ + + + +
+ +
+ \ No newline at end of file diff --git a/src/main/resources/forFrameWithId.html b/src/main/resources/forFrameWithId.html new file mode 100644 index 0000000..2d1fa79 --- /dev/null +++ b/src/main/resources/forFrameWithId.html @@ -0,0 +1,11 @@ + + + +
+ +
+ \ No newline at end of file diff --git a/src/main/resources/forFrameWithIndex.html b/src/main/resources/forFrameWithIndex.html new file mode 100644 index 0000000..b0969ed --- /dev/null +++ b/src/main/resources/forFrameWithIndex.html @@ -0,0 +1,8 @@ + + + +
+ +
\ No newline at end of file diff --git a/src/main/resources/fullPage.html b/src/main/resources/fullPage.html index 58694cc..fa1f99b 100644 --- a/src/main/resources/fullPage.html +++ b/src/main/resources/fullPage.html @@ -6,13 +6,6 @@ diff --git a/src/main/resources/withIframes.html b/src/main/resources/withIframes.html new file mode 100644 index 0000000..dfa9541 --- /dev/null +++ b/src/main/resources/withIframes.html @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/src/test/java/tutorialSolution/iframesSolution/IframesTest.java b/src/test/java/tutorialSolution/iframesSolution/IframesTest.java new file mode 100644 index 0000000..587544b --- /dev/null +++ b/src/test/java/tutorialSolution/iframesSolution/IframesTest.java @@ -0,0 +1,63 @@ +package tutorialSolution.iframesSolution; + +import browser.BrowserGetter; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; +import tutorialSolution.pages.BasicPage; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; + +@TestInstance(PER_CLASS) +public class IframesTest { + private final BrowserGetter browserGetter = new BrowserGetter(); + private BasicPage page; + private WebDriver driver; + + @BeforeAll + public void beforeAll() { + //initialize the Chrome browser here + driver = browserGetter.getChromeDriver(); + //initialize page object class + page = PageFactory.initElements(driver, BasicPage.class); + driver.get(new File("src/main/resources/withIframes.html").getAbsolutePath()); + } + + @AfterAll + public void afterAll() { + driver.quit(); + } + + @Test + public void frameById() { + //switch to frame identified by id, then interact with button from inside frame, and switch back to default + // content + driver.switchTo().frame("frameWithId"); + assertEquals("Inside frame with id", page.buttonForFrameWithId.getText()); + driver.switchTo().defaultContent(); + } + + @Test + public void frameByIndex() { + //switch to frame identified by index, then interact with button from inside frame, and switch back to + // default content + driver.switchTo().frame(1); + assertEquals("Inside frame with index", page.buttonForFrameWithIndex.getText()); + driver.switchTo().defaultContent(); + } + + @Test + public void frameAsWebElement() { + //switch to frame identified by selector as WebElement, then interact with button from inside frame, and + // switch back to default content + driver.switchTo().frame(page.frameAsWebElement); + assertEquals("Inside frame as WebElement", page.buttonForFrameWithName.getText()); + driver.switchTo().defaultContent(); + } +} From 6c352e17889b11e62c616b5a18cd46ecad15344b Mon Sep 17 00:00:00 2001 From: iamalittletester Date: Wed, 13 Feb 2019 21:04:58 +0200 Subject: [PATCH 02/24] getAttribute() --- .../pages/WebElementInteractionPage.java | 18 +++ src/main/resources/interactions.html | 35 ++++++ .../cssSelectors/CSSSelectorsTest.java | 40 +++++++ .../ElementInteractionTest.java | 40 +++++++ .../tutorialExercise/iframes/IframesTest.java | 37 +++++++ .../ElementInteractionTest.java | 104 ++++++++++++++++++ 6 files changed, 274 insertions(+) create mode 100644 src/main/java/tutorialSolution/pages/WebElementInteractionPage.java create mode 100644 src/main/resources/interactions.html create mode 100644 src/test/java/tutorialExercise/cssSelectors/CSSSelectorsTest.java create mode 100644 src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java create mode 100644 src/test/java/tutorialExercise/iframes/IframesTest.java create mode 100644 src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java diff --git a/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java new file mode 100644 index 0000000..160739d --- /dev/null +++ b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java @@ -0,0 +1,18 @@ +package tutorialSolution.pages; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +public class WebElementInteractionPage { + //WebElement with ID + @FindBy(css = "#idModuleImage") + public WebElement elementWithId; + + //inputs section + @FindBy(css = "[name='checkedCheckbox']") public WebElement checkedCheckbox; + @FindBy(css = "[name='uncheckedCheckbox']") public WebElement uncheckedCheckbox; + @FindBy(css = "#myRadio") public WebElement radioButton; + + //disabled button + @FindBy(css = "[type='button']") public WebElement disabledButton; +} diff --git a/src/main/resources/interactions.html b/src/main/resources/interactions.html new file mode 100644 index 0000000..d59a779 --- /dev/null +++ b/src/main/resources/interactions.html @@ -0,0 +1,35 @@ + + + + + + + + +
+
+
Using IDs
+ This is the module with id +
+
+

assignment Welcome to the interactions pagebuild

+
+
+
+ The checked checkbox
+ The unchecked checkbox
+ The radio button +
+
+ +
+ + diff --git a/src/test/java/tutorialExercise/cssSelectors/CSSSelectorsTest.java b/src/test/java/tutorialExercise/cssSelectors/CSSSelectorsTest.java new file mode 100644 index 0000000..b467cc8 --- /dev/null +++ b/src/test/java/tutorialExercise/cssSelectors/CSSSelectorsTest.java @@ -0,0 +1,40 @@ +package tutorialExercise.cssSelectors; + +import browser.BrowserGetter; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; +import tutorialSolution.pages.BasicPage; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; + +@TestInstance(PER_CLASS) +public class CSSSelectorsTest { + private final BrowserGetter browserGetter = new BrowserGetter(); + private BasicPage page; + private WebDriver driver; + + @BeforeAll + public void beforeAll() { + //initialize the Chrome browser here + driver = browserGetter.getChromeDriver(); + //initialize page object class + page = PageFactory.initElements(driver, BasicPage.class); + driver.get(new File("src/main/resources/fullPage.html").getAbsolutePath()); + } + + @AfterAll + public void afterAll() { + driver.quit(); + } + + + +} diff --git a/src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java b/src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java new file mode 100644 index 0000000..d73b31e --- /dev/null +++ b/src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java @@ -0,0 +1,40 @@ +package tutorialExercise.elementInteraction; + +import browser.BrowserGetter; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; +import tutorialSolution.pages.WebElementInteractionPage; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; + +@TestInstance(PER_CLASS) +public class ElementInteractionTest { + private final BrowserGetter browserGetter = new BrowserGetter(); + private WebElementInteractionPage page; + private WebDriver driver; + + @BeforeAll + public void beforeAll() { + //initialize the Chrome browser here + driver = browserGetter.getChromeDriver(); + //initialize page object class + page = PageFactory.initElements(driver, WebElementInteractionPage.class); + driver.get(new File("src/main/resources/interactions.html").getAbsolutePath()); + } + + @AfterAll + public void afterAll() { + driver.quit(); + } + + +} + diff --git a/src/test/java/tutorialExercise/iframes/IframesTest.java b/src/test/java/tutorialExercise/iframes/IframesTest.java new file mode 100644 index 0000000..9356a56 --- /dev/null +++ b/src/test/java/tutorialExercise/iframes/IframesTest.java @@ -0,0 +1,37 @@ +package tutorialExercise.iframes; + +import browser.BrowserGetter; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; +import tutorialSolution.pages.BasicPage; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; + +@TestInstance(PER_CLASS) +public class IframesTest { + private final BrowserGetter browserGetter = new BrowserGetter(); + private BasicPage page; + private WebDriver driver; + + @BeforeAll + public void beforeAll() { + //initialize the Chrome browser here + driver = browserGetter.getChromeDriver(); + //initialize page object class + page = PageFactory.initElements(driver, BasicPage.class); + driver.get(new File("src/main/resources/withIframes.html").getAbsolutePath()); + } + + @AfterAll + public void afterAll() { + driver.quit(); + } + +} diff --git a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java new file mode 100644 index 0000000..fed92ac --- /dev/null +++ b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java @@ -0,0 +1,104 @@ +package tutorialSolution.elementInteractionSolution; + +import browser.BrowserGetter; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; +import tutorialSolution.pages.WebElementInteractionPage; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; + +@TestInstance(PER_CLASS) +public class ElementInteractionTest { + private final BrowserGetter browserGetter = new BrowserGetter(); + private WebElementInteractionPage page; + private WebDriver driver; + + @BeforeAll + public void beforeAll() { + //initialize the Chrome browser here + driver = browserGetter.getChromeDriver(); + //initialize page object class + page = PageFactory.initElements(driver, WebElementInteractionPage.class); + driver.get(new File("src/main/resources/interactions.html").getAbsolutePath()); + } + + @AfterAll + public void afterAll() { + driver.quit(); + } + + @Test + public void click() { + + } + + @Test + public void sendKeys() { + + } + + @Test + public void clear() { + + } + + @Test + public void getText() { + + } + + @Test + public void getAttribute() throws InterruptedException { + //an attribute that is assigned to the WebElement + System.out.println("Existing attribute: " + page.elementWithId.getAttribute("height")); + assertEquals("100", page.elementWithId.getAttribute("height")); + //an attribute that could be assigned to the WebElement (is it allowed on the WebElement as per the HTML + // definition) but is not currently assigned + System.out.println("Non-assigned attribute: " + page.elementWithId.getAttribute("class")); + assertEquals("", page.elementWithId.getAttribute("class")); + //an attribute that could never be assigned to the WebElement as it is not allowed by the HTML definition + System.out.println("Non-existent attribute: " + page.elementWithId.getAttribute("nonExistentAttribute")); + assertNull(page.elementWithId.getAttribute("nonExistentAttribute")); + //attributes that appear to have multiple values + //value of 'class' attribute is composed of multiple 'words' + System.out.println("The value of the class attribute: " + page.disabledButton.getAttribute("class")); + assertEquals("w3-btn w3-padding w3-border w3-purple", page.disabledButton.getAttribute("class")); + //value of 'style' attribute refers to several properties: font size, font family + System.out.println("The value of the style attribute: " + page.disabledButton.getAttribute("style")); + assertEquals("font-size: 24px; font-family: verdana;", page.disabledButton.getAttribute("style")); + assertEquals("font-size: 24px; font-family: verdana;".replaceAll("\\s", ""), + page.disabledButton.getAttribute("style").replaceAll("\\s", "")); + //'boolean' attributes + //the 'checked' attribute value of a checked checkbox + System.out.println("Checked checkbox state: " + page.checkedCheckbox.getAttribute("checked")); + assertEquals("true", page.checkedCheckbox.getAttribute("checked")); + //the 'checked' attribute value of an unchecked checkbox + System.out.println("Unchecked checkbox state: " + page.uncheckedCheckbox.getAttribute("checked")); + assertNull(page.uncheckedCheckbox.getAttribute("checked")); + //the 'checked' attribute value of an unchecked radio button + System.out.println("Radio button state before checking: " + page.radioButton.getAttribute("checked")); + assertNull(page.radioButton.getAttribute("checked")); + page.radioButton.click(); + //the 'checked' attribute value of a checked radio button + System.out.println("Radio button state after checking: " + page.radioButton.getAttribute("checked")); + assertEquals("true", page.radioButton.getAttribute("checked")); + //the value of the 'disabled' attribute of the disabled button + System.out.println("Disabled attribute of the disabled button: " + page.disabledButton.getAttribute("disabled" + )); + assertEquals("true", page.disabledButton.getAttribute("disabled")); + } + + @Test + public void getCSSValue() { + + } +} + From b29210ef0777f60245b5448a5b2f86a096fe4f7f Mon Sep 17 00:00:00 2001 From: iamalittletester Date: Tue, 26 Feb 2019 13:06:03 +0200 Subject: [PATCH 03/24] Dropdown/select tests. --- .../pages/WebElementInteractionPage.java | 6 ++ src/main/resources/interactions.html | 55 +++++++++--- .../ElementInteractionTest.java | 85 ++++++++++++++++++- 3 files changed, 133 insertions(+), 13 deletions(-) diff --git a/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java index 160739d..655c70c 100644 --- a/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java +++ b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java @@ -15,4 +15,10 @@ public class WebElementInteractionPage { //disabled button @FindBy(css = "[type='button']") public WebElement disabledButton; + + //dropdowns + @FindBy(css = "[name='coffee']") public WebElement coffeeSelect; + @FindBy(css = "[name='tea']") public WebElement teaSelect; + @FindBy(css = "[name='refreshment']") public WebElement refreshmentSelect; + } diff --git a/src/main/resources/interactions.html b/src/main/resources/interactions.html index d59a779..ea2722b 100644 --- a/src/main/resources/interactions.html +++ b/src/main/resources/interactions.html @@ -5,10 +5,19 @@
+
+

assignment Welcome to the interactions pagebuild

+
+
+
+

getAttribute()

Using IDs
Using IDs height="100" alt="This is the module with id">
-
-

assignment Welcome to the interactions pagebuild

+ +
+ The checked checkbox
+ The unchecked checkbox
+ The radio button +
+
+
- -
- The checked checkbox
- The unchecked checkbox
- The radio button
-
- +
+

Select

+ + +
diff --git a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java index fed92ac..cb32e9e 100644 --- a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java +++ b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java @@ -6,10 +6,15 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.Select; import tutorialSolution.pages.WebElementInteractionPage; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -56,7 +61,7 @@ public void getText() { } @Test - public void getAttribute() throws InterruptedException { + public void getAttribute() { //an attribute that is assigned to the WebElement System.out.println("Existing attribute: " + page.elementWithId.getAttribute("height")); assertEquals("100", page.elementWithId.getAttribute("height")); @@ -96,6 +101,84 @@ public void getAttribute() throws InterruptedException { assertEquals("true", page.disabledButton.getAttribute("disabled")); } + @Test + public void select() { + //declaring the Select objects based on the WebEelements corresponding to the 'select' tags + Select coffeeSelect = new Select(page.coffeeSelect); + Select teaSelect = new Select(page.teaSelect); + Select refreshmentSelect = new Select(page.refreshmentSelect); + + // 1. checking that the available options of the coffee dropdown are the expected ones + //getOptions will return the list of WebElements corresponding to each option + //to retrieve the option text (which you can see on the webpage) you need to apply getText() on the option + List actualCoffeeOptions = new ArrayList<>(); + for (WebElement element : coffeeSelect.getOptions()) { + actualCoffeeOptions.add(element.getText()); + } + assertEquals(Arrays.asList("Espresso", "Doppio", "Cappuccino", "Latte Machiato", "Americano"), actualCoffeeOptions); + + // 1.Bonus. same for the teaSelect, which also has an empty text option tag + List actualTeaOptions = new ArrayList<>(); + for (WebElement element : teaSelect.getOptions()) { + actualTeaOptions.add(element.getText()); + } + assertEquals(Arrays.asList("", "Assam", "Ceylon", "Earl Grey", "Pu Erh", "Lady Grey"), + actualTeaOptions); + + // 2. select from the coffee dropdown based on the index and check that the selection worked by using + // 'getFirstSelectedOption()' + //index here is the Java index. Index 0 is the first element in the list + coffeeSelect.selectByIndex(1); + assertEquals("Doppio", coffeeSelect.getFirstSelectedOption().getText()); + + // 3. select from the tea dropdown based on the value attribute and check that the selection worked + assertEquals("", teaSelect.getFirstSelectedOption().getText()); + teaSelect.selectByValue("Ceylon"); + assertEquals("Ceylon", teaSelect.getFirstSelectedOption().getText()); + // you can also select the item whose value is an empty String + teaSelect.selectByValue(""); + // 4. selecting several options from a multiple type dropdown and check that all the selected options were + // correctly selected + List actualRefreshmentOptions = new ArrayList<>(); + refreshmentSelect.selectByVisibleText("Still Water"); + refreshmentSelect.selectByVisibleText("Sparkling Water"); + for (WebElement element : refreshmentSelect.getAllSelectedOptions()) { + actualRefreshmentOptions.add(element.getText()); + } + assertEquals(Arrays.asList("Still Water", "Sparkling Water"), actualRefreshmentOptions); + + // 5. deselect all options from the multiple type dropdown and check that there are no selected items, by + // checking the size of the List returned by 'getAllSelectedOptions' + refreshmentSelect.deselectAll(); + assertEquals(0, refreshmentSelect.getAllSelectedOptions().size()); + + // 6. select some options, then deselect one by index and check that selected options do not include the one + // that was deselected + refreshmentSelect.selectByVisibleText("Still Water"); + refreshmentSelect.selectByVisibleText("Sparkling Water"); + refreshmentSelect.selectByVisibleText("Rose Lemonade"); + refreshmentSelect.deselectByIndex(0); + actualRefreshmentOptions = new ArrayList<>(); + + for (WebElement element : refreshmentSelect.getAllSelectedOptions()) { + actualRefreshmentOptions.add(element.getText()); + } + assertEquals(Arrays.asList("Still Water", "Sparkling Water"), actualRefreshmentOptions); + + // 7. deselect an option by value and check that it was deselected successfully + refreshmentSelect.deselectByValue("5"); + actualRefreshmentOptions = new ArrayList<>(); + for (WebElement element : refreshmentSelect.getAllSelectedOptions()) { + actualRefreshmentOptions.add(element.getText()); + } + assertEquals(Arrays.asList("Still Water"), actualRefreshmentOptions); + + // 8. deselect last remaining selected option by visible text and check that there are no more selected options + refreshmentSelect.deselectByVisibleText("Still Water"); + assertEquals(0, refreshmentSelect.getAllSelectedOptions().size()); + + } + @Test public void getCSSValue() { From 28efedf6b8a57c4dd69e31f2c8a8320cc7c69dd1 Mon Sep 17 00:00:00 2001 From: iamalittletester Date: Wed, 27 Feb 2019 18:17:25 +0200 Subject: [PATCH 04/24] Click tests. --- .../pages/WebElementInteractionPage.java | 6 +++++ src/main/resources/interactions.html | 24 +++++++++++++++++++ .../ElementInteractionTest.java | 20 ++++++++++++---- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java index 655c70c..d7db118 100644 --- a/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java +++ b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java @@ -13,6 +13,12 @@ public class WebElementInteractionPage { @FindBy(css = "[name='uncheckedCheckbox']") public WebElement uncheckedCheckbox; @FindBy(css = "#myRadio") public WebElement radioButton; + //elements for clicking + @FindBy(css = "[name='checkboxToClick']") public WebElement checkboxToClick; + @FindBy(css = "#radioButtonToClick") public WebElement radioButtonToClick; + @FindBy(css = "#buttonToClick") public WebElement buttonToClick; + @FindBy(css = "#linkToClick") public WebElement linkToClick; + //disabled button @FindBy(css = "[type='button']") public WebElement disabledButton; diff --git a/src/main/resources/interactions.html b/src/main/resources/interactions.html index ea2722b..39c0b22 100644 --- a/src/main/resources/interactions.html +++ b/src/main/resources/interactions.html @@ -1,12 +1,27 @@ + + @@ -16,6 +31,15 @@

assignment Welcome to the interactions pagebuild

+
+

click()

+ A checkbox
+ The radio button + +

{{successtext}}

+ Link +
+

getAttribute()

diff --git a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java index cb32e9e..acdb853 100644 --- a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java +++ b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java @@ -1,10 +1,7 @@ package tutorialSolution.elementInteractionSolution; import browser.BrowserGetter; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.PageFactory; @@ -32,6 +29,10 @@ public void beforeAll() { driver = browserGetter.getChromeDriver(); //initialize page object class page = PageFactory.initElements(driver, WebElementInteractionPage.class); + } + + @BeforeEach + public void beforeEach() { driver.get(new File("src/main/resources/interactions.html").getAbsolutePath()); } @@ -42,7 +43,16 @@ public void afterAll() { @Test public void click() { - + //checking a checkbox + page.checkboxToClick.click(); + //unchecking the checkbox + page.checkboxToClick.click(); + //checking a radio button + page.radioButtonToClick.click(); + //clicking a button which triggers the display of a message + page.buttonToClick.click(); + //clicking on a link which causes a redirect to another page + page.linkToClick.click(); } @Test From 4613b460f8a06a5c0fb54f79e94c4dc0b0fd71ef Mon Sep 17 00:00:00 2001 From: iamalittletester Date: Thu, 28 Feb 2019 19:38:33 +0200 Subject: [PATCH 05/24] SendKeys tests. --- .../pages/WebElementInteractionPage.java | 4 +++ src/main/resources/interactions.html | 6 +++- .../ElementInteractionTest.java | 29 +++++++++++++++---- .../ElementInteractionTest.java | 14 ++++++++- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java index d7db118..93013a4 100644 --- a/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java +++ b/src/main/java/tutorialSolution/pages/WebElementInteractionPage.java @@ -19,6 +19,10 @@ public class WebElementInteractionPage { @FindBy(css = "#buttonToClick") public WebElement buttonToClick; @FindBy(css = "#linkToClick") public WebElement linkToClick; + //elements for typing + @FindBy(css = "[type='text']") public WebElement textInput; + @FindBy(css = "textarea") public WebElement textarea; + //disabled button @FindBy(css = "[type='button']") public WebElement disabledButton; diff --git a/src/main/resources/interactions.html b/src/main/resources/interactions.html index 39c0b22..98bfee4 100644 --- a/src/main/resources/interactions.html +++ b/src/main/resources/interactions.html @@ -26,7 +26,7 @@
-
+

assignment Welcome to the interactions pagebuild

@@ -39,6 +39,10 @@

click()

{{successtext}}

Link
+
+

sendKeys()

+ +

getAttribute()

diff --git a/src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java b/src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java index d73b31e..ef2f9f8 100644 --- a/src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java +++ b/src/test/java/tutorialExercise/elementInteraction/ElementInteractionTest.java @@ -1,18 +1,13 @@ package tutorialExercise.elementInteraction; import browser.BrowserGetter; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.PageFactory; import tutorialSolution.pages.WebElementInteractionPage; import java.io.File; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @TestInstance(PER_CLASS) @@ -27,6 +22,10 @@ public void beforeAll() { driver = browserGetter.getChromeDriver(); //initialize page object class page = PageFactory.initElements(driver, WebElementInteractionPage.class); + } + + @BeforeEach + public void beforeEach() { driver.get(new File("src/main/resources/interactions.html").getAbsolutePath()); } @@ -35,6 +34,24 @@ public void afterAll() { driver.quit(); } + @Test + public void click() { + + } + + @Test + public void sendKeys() { + + } + + @Test + public void getAttribute() { + + } + + @Test + public void select() { + } } diff --git a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java index acdb853..ae86ca6 100644 --- a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java +++ b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java @@ -57,7 +57,19 @@ public void click() { @Test public void sendKeys() { - + //type into an HTML element whose 'type' attribute is 'text' + page.textInput.sendKeys("coffee"); + assertEquals("coffee", page.textInput.getAttribute("value")); + //type into a
+
+
+

getText()

+
+ This is the module with id +
+
H5 text
+ Link text + + +
+
+
+ +
+

getAttribute()

Using IDs
- This is the module with id diff --git a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java index 599cfcd..ed04680 100644 --- a/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java +++ b/src/test/java/tutorialSolution/elementInteractionSolution/ElementInteractionTest.java @@ -61,7 +61,7 @@ public void sendKeys() { page.textInput.sendKeys("coffee"); assertEquals("coffee", page.textInput.getAttribute("value")); //type into a