Created
January 3, 2024 13:32
How to Use Selenium With Java: A Complete Tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.POMFramework.tests; | |
import java.awt.AWTException; | |
import java.net.URL; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.concurrent.TimeUnit; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.chrome.ChromeOptions; | |
import org.openqa.selenium.remote.LocalFileDetector; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
public class LamdaTestDownloadFileRemotely { | |
private RemoteWebDriver driver; | |
@BeforeClass | |
public void setUp() throws Exception { | |
ChromeOptions capabilities = new ChromeOptions(); | |
capabilities.setCapability("user","<userName>"); | |
capabilities.setCapability("accessKey","<Access key>"); | |
capabilities.setCapability("build", "Build 4"); | |
capabilities.setCapability("name", "Downloading File"); | |
capabilities.setCapability("platformName", "Windows 10"); | |
capabilities.setCapability("browserName", "Chrome"); | |
capabilities.setCapability("browserVersion","79.0"); | |
Map<String, Object> prefs = new HashMap<String, Object>(); | |
prefs.put("download.prompt_for_download", false); | |
capabilities.setExperimentalOption("prefs", prefs); | |
driver = new RemoteWebDriver(new URL("http://hub.lambdatest.com:80/wd/hub"), capabilities); | |
driver.setFileDetector(new LocalFileDetector()); | |
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); | |
} | |
@Test | |
public void fileDownload() throws AWTException, InterruptedException { | |
driver.get("https://chromedriver.storage.googleapis.com/index.html?path=79.0.3945.36/"); | |
Thread.sleep(2000); | |
WebElement btnDownload = driver.findElement(By.xpath(".//a[text()='chromedriver_win32.zip']")); | |
btnDownload.click(); | |
Thread.sleep(10000); | |
} | |
@AfterClass | |
public void tearDown() throws Exception { | |
driver.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment