Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created November 23, 2021 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save muditlambda/087bbf3f15425205119b0543c082141a to your computer and use it in GitHub Desktop.
Save muditlambda/087bbf3f15425205119b0543c082141a to your computer and use it in GitHub Desktop.
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", "94.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.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment