Created
November 16, 2021 05:45
-
-
Save RDayal11/54c4be7634c9c29cf69a7639d7e586d1 to your computer and use it in GitHub Desktop.
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 LambdaTest; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.annotations.AfterTest; | |
import org.testng.annotations.BeforeTest; | |
import org.testng.annotations.Listeners; | |
import org.testng.annotations.Test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
@Listeners({util.Listener.class}) | |
class FirstTestScriptUsingSeleniumGrid { | |
public String username = "YOUR USERNAME"; | |
public String accesskey = "YOUR ACCESSKEY"; | |
public static RemoteWebDriver driver = null; | |
public String gridURL = "@hub.lambdatest.com/wd/hub"; | |
@BeforeTest | |
public void setUp() throws Exception { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "chrome"); | |
capabilities.setCapability("version", "95.0"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "FirstTestScript"); | |
capabilities.setCapability("name", "FirstTestScriptSample"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
@Test | |
public void firstTestCase() { | |
try { | |
System.out.println("Logging into Lambda Test Sign Up Page"); | |
driver.get("https://accounts.lambdatest.com/register"); | |
WebElement pageHeader= driver.findElement(By.xpath("//a[text()='Sign In']")); | |
pageHeader.click(); | |
System.out.println("Clicked on the Sign In Button."); | |
} catch (Exception e) { | |
} | |
} | |
@AfterTest | |
public void closeBrowser() { | |
driver.close(); | |
System.out.println("The driver has been closed."); | |
} | |
} | |
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 LambdaTest; | |
import io.github.bonigarcia.wdm.WebDriverManager; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.testng.annotations.AfterTest; | |
import org.testng.annotations.BeforeTest; | |
import org.testng.annotations.Listeners; | |
import org.testng.annotations.Test; | |
@Listeners({util.Listener.class}) | |
class FirstTestScriptUsingWebDriver { | |
public static WebDriver driver = null; | |
@BeforeTest | |
public void setUp() throws Exception { | |
WebDriverManager.chromedriver().setup(); | |
driver=new ChromeDriver(); | |
} | |
@Test | |
public void firstTestCase() { | |
try { | |
System.out.println("Logging into Lambda Test Sign Up Page"); | |
driver.get("https://accounts.lambdatest.com/register"); | |
WebElement pageHeader= driver.findElement(By.xpath("//a[text()='Sign In']")); | |
pageHeader.click(); | |
System.out.println("Clicked on the Sign In Button."); | |
} catch (Exception e) { | |
} | |
} | |
@AfterTest | |
public void closeBrowser() { | |
driver.close(); | |
System.out.println("The driver has been closed."); | |
} | |
} | |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.example</groupId> | |
<artifactId>LambdaTest</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-api</artifactId> | |
<version>4.0.0-alpha-7</version> | |
</dependency> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-remote-driver</artifactId> | |
<version>4.0.0-alpha-7</version> | |
</dependency> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-chrome-driver</artifactId> | |
<version>4.0.0-alpha-7</version> | |
</dependency> | |
<dependency> | |
<groupId>org.testng</groupId> | |
<artifactId>testng</artifactId> | |
<version>6.14.3</version> | |
</dependency> | |
<dependency> | |
<groupId>io.github.bonigarcia</groupId> | |
<artifactId>webdrivermanager</artifactId> | |
<version>4.4.3</version> | |
</dependency> | |
</dependencies> | |
<properties> | |
<maven.compiler.source>8</maven.compiler.source> | |
<maven.compiler.target>8</maven.compiler.target> | |
</properties> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> | |
<suite name="FirstTestScriptUsingWebDriverSuite"> | |
<test name="FirstTestScriptUsingWebDriver" > | |
<classes> | |
<class name="LambdaTest.FirstTestScriptUsingWebDriver" > | |
</class> | |
</classes> | |
</test> | |
</suite> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment