-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestng.java
More file actions
31 lines (23 loc) · 1.15 KB
/
Copy pathtestng.java
File metadata and controls
31 lines (23 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.browserstack;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;
public class SingleTest extends BrowserStackTestNGTest {
@Test
public void test() throws Exception {
// navigate to bstackdemo
driver.get("https://www.bstackdemo.com");
// Check the title
Assert.assertTrue(driver.getTitle().matches("StackDemo"));
// Save the text of the product for later verify
String productOnScreenText = driver.findElement(By.xpath("//*[@id=\"1\"]/p")).getText();
// Click on add to cart button
driver.findElement(By.xpath("//*[@id=\"1\"]/div[4]")).click();
// See if the cart is opened or not
Assert.assertTrue(driver.findElement(By.className("float-cart__content")).isDisplayed());
// Check the product inside the cart is same as of the main page
String productOnCartText = driver.findElement(By.xpath("//*[@id=\"__next\"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]")).getText();
Assert.assertEquals(productOnScreenText, productOnCartText);
}
}