From 7f15d46d00e6c2fb7c15b79a06b2da8505e46be9 Mon Sep 17 00:00:00 2001 From: Michael Olayemi Date: Mon, 8 May 2023 03:38:08 +0000 Subject: [PATCH] Uploading File using Selenium WebDriver in Java (#13947) * Uploading File using Selenium WebDriver in Java * Uploading File using Selenium WebDriver in Java * Uploading File using Selenium WebDriver in Java * Uploading File using Selenium WebDriver in Java --- testing-modules/pom.xml | 1 + .../selenium-webdriver/1688web.png | Bin 0 -> 14203 bytes testing-modules/selenium-webdriver/README.md | 1 + testing-modules/selenium-webdriver/pom.xml | 59 ++++++++++++++++++ .../FileUploadWebDriverUnitTest.java | 53 ++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 testing-modules/selenium-webdriver/1688web.png create mode 100644 testing-modules/selenium-webdriver/README.md create mode 100644 testing-modules/selenium-webdriver/pom.xml create mode 100644 testing-modules/selenium-webdriver/src/test/java/com/baeldung/selenium/webdriver/fileupload/FileUploadWebDriverUnitTest.java diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index 80e0c3bc29..8fb7a93a02 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -40,6 +40,7 @@ rest-assured rest-testing selenium-junit-testng + selenium-webdriver spring-mockito spring-testing-2 spring-testing diff --git a/testing-modules/selenium-webdriver/1688web.png b/testing-modules/selenium-webdriver/1688web.png new file mode 100644 index 0000000000000000000000000000000000000000..92ae7921fb89ac89c4ac399f07d60006bf89ad94 GIT binary patch literal 14203 zcmeIZ1yEdHqwRTs5D1U}2~N<2prLV>U?E5#xVviycS+FT1Pc~|2lpmO1Hs)JcWT1yEFGrO-;>IJ*t3B)#=^)^f`6*TEDgU@fm9O23)}kQ|xqJ8f z9ggs=G{5v0YUu)}4yE&r9?ulaaKrBc+SPAQ;sM~z5c-WOzlK#t%GZNF=9h6SRu=u2 z1ZSaJMXxv_SLui>LI{3u08g{TCgtIf!_%54~kwyU4<1#lJJM<;Nw+2p8ISY@YIG9O};5O)L!(bi;yee(e4Yj(^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E>KsPmKgq&tozvFm%Pg;+OoBF);B7;t-Vuv~b8ZfbKP@3y z2%OLm05HilA2oCvLZn}ix2^8p7WLJc=G|*631s(Cv^L%i%%0ChxI$w}hynkNpkD^E zYoIhjgRIb`oZ@QIrXA4;z7 ze(h4E<8za1p9q!!hAvmcZ4k#ys_(B5%%%R5`>9M+xL*F5Zas&ONB?6&p0eQJRPmoC zt$4LclrV615f`27-D>X$V9g;2p9 z=M{YV2U@7{17bVxr7*I!ruxrZ8Jw2gV-Sc(I5lT+CEgT&I!%T|$iRBXWBQ=p!y?9Ox{!Dr0&{l;+~6Q&ctr zD+_659K*&#_iice>*Q1KwvWM+D#tGB6IHrzo1HACjM`zKy(;|D&)H^3?*}qJC}=>o){G|aRzP + + 4.0.0 + selenium-webdriver + 0.0.1-SNAPSHOT + selenium-webdriver + + + com.baeldung + testing-modules + 1.0.0-SNAPSHOT + + + + + org.seleniumhq.selenium + selenium-java + ${selenium-java.version} + + + commons-logging + commons-logging + + + + + org.testng + testng + ${testng.version} + + + io.github.bonigarcia + webdrivermanager + ${webdrivermanager.version} + + + + + + + src/main/resources + true + + + src/test/resources + true + + + + + + 6.10 + 4.8.3 + 5.3.2 + + + \ No newline at end of file diff --git a/testing-modules/selenium-webdriver/src/test/java/com/baeldung/selenium/webdriver/fileupload/FileUploadWebDriverUnitTest.java b/testing-modules/selenium-webdriver/src/test/java/com/baeldung/selenium/webdriver/fileupload/FileUploadWebDriverUnitTest.java new file mode 100644 index 0000000000..18853ede56 --- /dev/null +++ b/testing-modules/selenium-webdriver/src/test/java/com/baeldung/selenium/webdriver/fileupload/FileUploadWebDriverUnitTest.java @@ -0,0 +1,53 @@ +package com.baeldung.selenium.webdriver.fileupload; + +import org.junit.Assert; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import org.openqa.selenium.firefox.FirefoxDriver; + +import io.github.bonigarcia.wdm.WebDriverManager; + +public class FileUploadWebDriverUnitTest { + + private WebDriver driver; + + private static final String URL = "http://www.csm-testcenter.org/test?do=show&subdo=common&test=file_upload"; + private static final String INPUT_NAME = "file_upload"; + + @BeforeEach + public void setUp() { + WebDriverManager.firefoxdriver() + .setup(); + driver = new FirefoxDriver(); + } + + @AfterEach + public void tearDown() { + driver.quit(); + } + + @Test + public void givenFileUploadPage_whenInputFilePath_thenFileUploadEndsWithFilename() { + driver.get(URL); + + String filePath = System.getProperty("user.dir") + "/1688web.png"; + WebElement inputElement = driver.findElement(By.name(INPUT_NAME)); + WebElement submitButton = driver.findElement(By.name("http_submit")); + + inputElement.sendKeys(filePath); + + String actualFilePath = inputElement.getAttribute("value"); + String fileName = filePath.substring(filePath.lastIndexOf("/") + 1); + + submitButton.click(); + + Assert.assertTrue(actualFilePath.endsWith(fileName)); + } + +} \ No newline at end of file