Created
October 23, 2019 14:45
-
-
Save muditlambda/3ae4238c3d2904fd1517e29a66dd425f 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
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.openqa.selenium.firefox.FirefoxDriver; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import static org.openqa.selenium.support.locators.RelativeLocator.withTagName; | |
import static org.testng.Assert.assertEquals; | |
import org.testng.annotations.Test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.concurrent.TimeUnit; | |
public class MavenRelocators { | |
private WebDriver driver; | |
boolean status = false; | |
@BeforeClass | |
public void setUp(){ | |
System.setProperty("webdriver.chrome.driver","C:\\location-of-chromedriver.exe"); | |
driver = new ChromeDriver(); | |
driver.get("https://accounts.lambdatest.com/login"); | |
driver.manage().window().maximize(); | |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | |
} | |
@AfterClass | |
public void tearDown() throws Exception { | |
if (driver != null) { | |
driver.quit(); | |
} | |
} | |
@Test | |
public void test_login_using_relative_locators_1(){ | |
// Find the label element above the login text box | |
WebElement heightLabel = driver.findElement(By.xpath("//*[@id='app']/section/form/div/div/h1")); | |
// Locate the textbox where username should be inputted | |
WebElement heightUserBox = driver.findElement(withTagName("input") | |
.below(heightLabel)); | |
heightUserBox.sendKeys("user-name"); | |
// Locate the textbox where password should be inputted | |
WebElement heightPasswordBox = driver.findElement(withTagName("input") | |
.below(heightUserBox)); | |
heightPasswordBox.sendKeys("password"); | |
// Locate the submit button | |
WebElement submitbutton = driver.findElement(By.xpath("//*[@id=\'app\']/section/form/div/div/button")); | |
submitbutton.click(); | |
//Wait for 10 seconds to observe the output | |
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment