Skip to content

Instantly share code, notes, and snippets.

@Jaimin180296
Created April 6, 2021 17:41
Show Gist options
  • Select an option

  • Save Jaimin180296/1f3bfbc25f9edafe7696c8658ea048c2 to your computer and use it in GitHub Desktop.

Select an option

Save Jaimin180296/1f3bfbc25f9edafe7696c8658ea048c2 to your computer and use it in GitHub Desktop.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
public class Desktop {
public WebDriver driver;
public WebDriverWait wait;
public final String AUTOMATE_USERNAME = "<userName>";
public final String AUTOMATE_ACCESS_KEY = "<accessKey>";
public final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_ACCESS_KEY + "@hub-cloud.browserstack.com/wd/hub";
@BeforeTest
public void setup() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
WebDriverWait wait;
caps.setCapability("os", "OS X");
caps.setCapability("os_version", "Catalina");
caps.setCapability("browser", "Safari");
caps.setCapability("browser_version", "13.0");
caps.setCapability("browserstack.local", "false");
caps.setCapability("browserstack.selenium_version", "3.14.0");
caps.setCapability("build", "Ticketnumber#414148");
caps.setCapability("resolution", "1280x960");
driver = new RemoteWebDriver(new URL(URL), caps);
SessionId session = ((RemoteWebDriver) driver).getSessionId();
System.out.println("Session id: " + session.toString());
}
@Test()
public void test() throws InterruptedException {
wait = new WebDriverWait(driver, 30);
driver.get("https://qasite.s3.eu-central-1.amazonaws.com/qa/qasite/Login.html");
driver.findElement(By.xpath("//input[@id='login-username']")).sendKeys("demo");
driver.findElement(By.xpath("//input[@id='login-password']")).sendKeys("demo");
driver.findElement(By.xpath("//input[@id='SubmitLogin']")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@value='Open PaymentScreen page']"))).click();
wait.until(ExpectedConditions.urlContains("PaymentScreen.html"));
System.out.println(driver.getCurrentUrl());
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='amount']"))).sendKeys("100");
Thread.sleep(5000);
}
@AfterTest
public void stop() {
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment