Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. public class ForSe_TestCases
  2. public WebDriver driver;
  3.  
  4. @BeforeTest
  5. public void setup ()
  6. {
  7. System.setProperty("webdriver.chrome.driver", "path");
  8. WebDriver driver =new ChromeDriver();
  9. driver.manage().deleteAllCookies();
  10. }
  11.  
  12. @Test(priority = 0)
  13. public void Validlogin_IO () throws InterruptedException {
  14. driver.navigate().to("http://**URL**");
  15. driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com");
  16. driver.findElement(By.xpath("//*[@id='password']")).sendKeys("Pass12345");
  17. driver.findElement(By.xpath("//*[@id='login-form']/div[4]/button")).click();
  18. System.out.println("Login button pressed");
  19. }
  20.  
  21. public static void main(String[] args) {
  22. TestListenerAdapter tla = new TestListenerAdapter();
  23. TestNG testng = new TestNG();
  24. testng.setTestClasses(new Class[] { YOURCLASSNAME.class });
  25. testng.addListener(tla);
  26. testng.run();
  27. }
  28.  
  29. public boolean waitForElement(String elementXpath, int timeOut) {
  30.  
  31. try{
  32. WebDriverWait wait = new WebDriverWait(driver, timeOut);
  33. boolean elementPresent=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXpath)).isDisplayed());
  34.  
  35. System.out.printf("%nElement is present [T/F]..? ")+elementPresent;
  36. }
  37. catch(TimeoutException e1){e1.printStackTrace();elementPresent=false;}
  38.  
  39. return elementPresent;
  40. }
  41.  
  42. driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com"); //this is official email
  43.  
  44. waitForElement ("//*[@id='email_address']", 10);
  45. if(elementPresent==true){
  46. driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com");
  47. }
  48. else{
  49. System.out.println("FATAL! Couldn't locate email address field!");
  50. }
  51.  
  52. package demo;
  53.  
  54.  
  55. import java.util.concurrent.TimeUnit;
  56.  
  57. import org.openqa.selenium.By;
  58. import org.openqa.selenium.WebDriver;
  59. import org.openqa.selenium.WebElement;
  60. import org.openqa.selenium.chrome.ChromeDriver;
  61. import org.openqa.selenium.chrome.ChromeOptions;
  62. import org.openqa.selenium.interactions.Actions;
  63. import org.testng.annotations.BeforeTest;
  64. import org.testng.annotations.Test;
  65.  
  66. public class TestAnyURL_TestNG
  67. {
  68.  
  69. WebDriver driver;
  70.  
  71. @BeforeTest
  72. public void setup ()
  73. {
  74. System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
  75. ChromeOptions options = new ChromeOptions();
  76. options.addArguments("test-type");
  77. options.addArguments("start-maximized");
  78. options.addArguments("--js-flags=--expose-gc");
  79. options.addArguments("--enable-precise-memory-info");
  80. options.addArguments("--disable-popup-blocking");
  81. options.addArguments("--disable-default-apps");
  82. options.addArguments("test-type=browser");
  83. options.addArguments("disable-infobars");
  84. driver = new ChromeDriver(options);
  85. driver.manage().deleteAllCookies();
  86. }
  87.  
  88.  
  89. @Test(priority = 0)
  90. public void Validlogin_IO () throws InterruptedException
  91. {
  92. driver.navigate().to("http://google.com"); //ForSe test environment URL
  93. driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  94. driver.findElement(By.xpath("//*[@id='email_address']")).sendKeys("tengku.forse@gmail.com"); //this is official email
  95. driver.findElement(By.xpath("//*[@id='password']")).sendKeys("Pass12345"); //this is password
  96. driver.findElement(By.xpath("//*[@id='login-form']/div[4]/button")).click(); //click on submit button to login
  97. System.out.println("Login button pressed"); } //This code is to add new case
  98.  
  99. @Test (priority = 1)
  100. public void AddCase() throws InterruptedException
  101. {
  102. WebElement element = driver.findElement(By.partialLinkText("Add Case")); //To find 'Add Case' button on dashboard
  103. Actions action = new Actions (driver); action.moveToElement(element); //Move mouse and hover to 'Add Case' button
  104. action.click().build().perform(); //Click on 'Add Case' button
  105. driver.findElement(By.id("name")).sendKeys("Perak Murder Case -53311");//Provide Case Name
  106. 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
  107. 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");
  108. Thread.sleep(6000); //wait for files to load
  109. driver.findElement(By.id("btnSubmit")).click();//click on submit button
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement