Created
July 8, 2022 18:05
How to get response status code with Selenium WebDriver Java?
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 test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.annotations.AfterMethod; | |
import org.testng.annotations.BeforeMethod; | |
public class BaseClass { | |
public RemoteWebDriver driver = null; | |
String username = "<lamdbatest_username>"; | |
String accessKey = "<lamdbatest_accessKey>"; | |
@BeforeMethod | |
public void setUp() { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "Chrome"); | |
capabilities.setCapability("version", "103.0"); | |
capabilities.setCapability("platform", "Windows 11"); | |
capabilities.setCapability("resolution", "1024x768"); | |
capabilities.setCapability("build", "Http Response Status Codes Using Selenium WebDriver"); | |
capabilities.setCapability("name", "Http Response Status Codes"); | |
try { | |
driver = new RemoteWebDriver( | |
new URL("https://" + username + ":" + accessKey | |
+ "@hub.lambdatest.com/wd/hub"), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} | |
} | |
@AfterMethod | |
public void closeDriver() { | |
driver.quit(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment