Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ForSe_TestCases
- public WebDriver driver;
- @BeforeTest
- public void setup ()
- {
- System.setProperty("webdriver.chrome.driver", "path");
- WebDriver driver =new ChromeDriver();
- driver.manage().deleteAllCookies();
- }
- @Test(priority = 0)
- public void Validlogin_IO () throws InterruptedException {
- driver.navigate().to("http://**URL**");
- driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com");
- driver.findElement(By.xpath("//*[@id='password']")).sendKeys("Pass12345");
- driver.findElement(By.xpath("//*[@id='login-form']/div[4]/button")).click();
- System.out.println("Login button pressed");
- }
- public static void main(String[] args) {
- TestListenerAdapter tla = new TestListenerAdapter();
- TestNG testng = new TestNG();
- testng.setTestClasses(new Class[] { YOURCLASSNAME.class });
- testng.addListener(tla);
- testng.run();
- }
- public boolean waitForElement(String elementXpath, int timeOut) {
- try{
- WebDriverWait wait = new WebDriverWait(driver, timeOut);
- boolean elementPresent=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXpath)).isDisplayed());
- System.out.printf("%nElement is present [T/F]..? ")+elementPresent;
- }
- catch(TimeoutException e1){e1.printStackTrace();elementPresent=false;}
- return elementPresent;
- }
- driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com"); //this is official email
- waitForElement ("//*[@id='email_address']", 10);
- if(elementPresent==true){
- driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com");
- }
- else{
- System.out.println("FATAL! Couldn't locate email address field!");
- }
- package demo;
- import java.util.concurrent.TimeUnit;
- 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.chrome.ChromeOptions;
- import org.openqa.selenium.interactions.Actions;
- import org.testng.annotations.BeforeTest;
- import org.testng.annotations.Test;
- public class TestAnyURL_TestNG
- {
- WebDriver driver;
- @BeforeTest
- public void setup ()
- {
- System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
- ChromeOptions options = new ChromeOptions();
- options.addArguments("test-type");
- options.addArguments("start-maximized");
- options.addArguments("--js-flags=--expose-gc");
- options.addArguments("--enable-precise-memory-info");
- options.addArguments("--disable-popup-blocking");
- options.addArguments("--disable-default-apps");
- options.addArguments("test-type=browser");
- options.addArguments("disable-infobars");
- driver = new ChromeDriver(options);
- driver.manage().deleteAllCookies();
- }
- @Test(priority = 0)
- public void Validlogin_IO () throws InterruptedException
- {
- driver.navigate().to("http://google.com"); //ForSe test environment URL
- driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
- driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com"); //this is official email
- driver.findElement(By.xpath("//*[@id='password']")).sendKeys("Pass12345"); //this is password
- driver.findElement(By.xpath("//*[@id='login-form']/div[4]/button")).click(); //click on submit button to login
- System.out.println("Login button pressed"); } //This code is to add new case
- @Test (priority = 1)
- public void AddCase() throws InterruptedException
- {
- WebElement element = driver.findElement(By.partialLinkText("Add Case")); //To find 'Add Case' button on dashboard
- Actions action = new Actions (driver); action.moveToElement(element); //Move mouse and hover to 'Add Case' button
- action.click().build().perform(); //Click on 'Add Case' button
- driver.findElement(By.id("name")).sendKeys("Perak Murder Case -53311");//Provide Case Name
- driver.findElement(By.id("fileupload")).sendKeys("C:\Users\sanchit.IGENEDC\Desktop\iCSIImages\FisheyeImages\IMG_1187.JPG"+"n"+"C:\Users\sanchit.IGENEDC\Desktop\iCSIImages\FisheyeImages\IMG_1188.JPG"+"n"+"C:\Users\sanchit.IGENEDC\Desktop\iCSIImages\FisheyeImages\IMG_1189.JPG"+"n"+"C:\Users\sanchit.IGENEDC\Desktop\iCSIImages\Fisheye Images\IMG_1190.JPG"); //Upload files
- driver.findElement(By.id("fileupload1")).sendKeys("C:\Users\sanchit.IGENEDC\Desktop\iCSIImages\EvidenceImages\_DSC0970.JPG"+"n"+"C:\Users\sanchit.IGENEDC\Desktop\iCSI>Images\EvidenceImages\_DSC0971.JPG"+"n"+"C:\Users\sanchit.IGENEDC\Desktop\iCSIImages\Evidence Images\_DSC0972.JPG");
- Thread.sleep(6000); //wait for files to load
- driver.findElement(By.id("btnSubmit")).click();//click on submit button
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement