Created
April 14, 2021 18:06
-
-
Save Jaimin180296/a184391b4355eae2108a77660af44bb7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import com.browserstack.local.Local; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.openqa.selenium.remote.SessionId; | |
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.URL; | |
import java.util.HashMap; | |
public class LocalTestingLanguageBinding { | |
public WebDriver driver; | |
public WebDriverWait wait; | |
//add username and accessKey | |
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"; | |
static Local bsLocal; | |
@BeforeTest | |
public void setup() throws Exception { | |
bsLocal = new Local(); | |
HashMap<String, String> bsLocalArgs = new HashMap<String, String>(); | |
//change keys | |
bsLocalArgs.put("key", "<accesskey>"); | |
bsLocal.start(bsLocalArgs); | |
DesiredCapabilities caps = new DesiredCapabilities(); | |
caps.setCapability("os", "OS X"); | |
caps.setCapability("os_version", "Snow Leopard"); | |
caps.setCapability("browser", "Firefox"); | |
caps.setCapability("browser_version", "28.0"); | |
caps.setCapability("browserstack.local", "true"); | |
caps.setCapability("browserstack.debug", "true"); | |
caps.setCapability("browserstack.networkLogs", "true"); | |
caps.setCapability("browserstack.selenium_version", "2.45.0"); | |
caps.setCapability("browserstack.console", "verbose"); | |
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); | |
String baseUrl = "http://demo.guru99.com/test/login.html"; | |
driver.get(baseUrl); | |
WebElement email = driver.findElement(By.id("email")); | |
// Get the WebElement corresponding to the Password Field | |
WebElement password = driver.findElement(By.name("passwd")); | |
email.sendKeys("[email protected]"); | |
password.sendKeys("abcdefghlkjl"); | |
System.out.println("Text Field Set"); | |
// Deleting values in the text box | |
email.clear(); | |
password.clear(); | |
System.out.println("Text Field Cleared"); | |
Thread.sleep(5000); | |
} | |
@AfterTest | |
public void stop() throws Exception { | |
bsLocal.stop(); | |
driver.quit(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment