From 689636df20e809bb506a8f36b8f57024d84da0d9 Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Thu, 20 Aug 2020 15:24:23 +0200 Subject: [PATCH] #133: open a HTML snippet with WebDriver --- .../neodymium/util/SelenideAddons.java | 33 ++++++++++++++++++- .../neodymium/util/SelenideAddonsTest.java | 10 ++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java b/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java index ea52c8bd5..fea8893e9 100644 --- a/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java +++ b/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java @@ -1,7 +1,12 @@ package com.xceptance.neodymium.util; import static com.codeborne.selenide.Selenide.$$; +import static com.codeborne.selenide.Selenide.open; +import static com.codeborne.selenide.Selenide.sleep; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -440,8 +445,34 @@ public static void dragAndDropUntilCondition(SelenideElement elementToMove, Sele }); } dragAndDrop(elementToMove, horizontalMovement, verticalMovement); - Selenide.sleep(pauseBetweenMovements); + sleep(pauseBetweenMovements); counter++; } } + + /** + * Open the supplied HTML content with the current web driver. + * + * @param htmlContent + * a String containing the HTML that should be opened in the current web driver + */ + public static void openHtmlContentWithCurrentWebDriver(String htmlContent) + { + File tempHtmlContentFile = null; + try + { + tempHtmlContentFile = File.createTempFile("htmlContent", ".html", new File("./target/")); + tempHtmlContentFile.deleteOnExit(); + + FileWriter fileWriter; + fileWriter = new FileWriter(tempHtmlContentFile); + fileWriter.append(htmlContent); + fileWriter.close(); + } + catch (final IOException e) + { + e.printStackTrace(); + } + open("file://" + tempHtmlContentFile.getAbsolutePath()); + } } \ No newline at end of file diff --git a/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java b/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java index 7f3dfc61d..50ecee06d 100644 --- a/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java +++ b/src/test/java/com/xceptance/neodymium/util/SelenideAddonsTest.java @@ -537,4 +537,14 @@ private void leftHorizontalDragAndDropUntilAttribute(SelenideElement elementToMo SelenideAddons.dragAndDropUntilCondition(elementToMove, elementToCheck, horizontalMovement, 0, 3000, 10, Condition.attribute(sliderValueAttributeName, moveUntil)); } + + @Test + public void testOpenHtmlContentWithCurrentWebDriver() + { + final String text = "Hi\n\nHow are you?)\n\nBye"; + final String textHtml = "
Hi

How are you?)

Bye
"; + + SelenideAddons.openHtmlContentWithCurrentWebDriver(textHtml); + Assert.assertEquals(text, $("body").getText()); + } } \ No newline at end of file