Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
2.2 kB
0
Indexable
Never
package common;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class TestCaseExample {
WebDriver driver;
WebDriverWait explicitWait;
String username, password, name, phone, email;
@BeforeClass
public void beforeClass() {
	 WebDriverManager.firefoxdriver().setup();
	 driver = new FirefoxDriver();
	 
	 explicitWait = new WebDriverWait(driver, 15); 
	 
	 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
	 
	 driver.manage().window().maximize();
	 username= "user@stringee.com";
	 
	 password = "12341234";
	 
	 name = "Test 001";
	 
	 phone = "0987436475";
	 
	 email="test01@gmail.com";
}
@Test
public void TC_DemoLogin() throws InterruptedException {
	 driver.get("https://automation-str.stringeex.com");
	 
	 driver.findElement(By.name("email")).sendKeys(username);
	 
	 driver.findElement(By.name("password")).sendKeys(password);
	 
	 driver.findElement(By.xpath("//button[contains(text(),'Log in')]")).click();
	 
	 Thread.sleep(10000);
	 
	 String urlexpected = driver.getCurrentUrl();

	 Assert.assertEquals(urlexpected, "https://automation-str.stringeex.com/dashboard/callin");

	 driver.findElement(By.xpath("//a[@href='/contact']")).click();
	 
	 driver.findElement(By.xpath("//a[contains(string(),'Add a contact')]")).click();
	 
	 driver.findElement(By.name("name")).sendKeys(name);

	 driver.findElement(By.name("email")).sendKeys(email);

	 driver.findElement(By.name("phone")).sendKeys(phone);
	 
	 driver.findElement(By.xpath("//button[@type='submit']")).click();
	 
	 Thread.sleep(5);
	 Assert.assertEquals(driver.findElement(By.xpath("//th[contains(text(),'Name')]//ancestor::thead/following-sibling::tbody//b[text()='Test 001']")).getText(), name);
	 
}
@AfterTest
public void afterTest() {
	driver.quit();
}
}
Leave a Comment