Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collections;
  6. import java.util.List;
  7. import java.util.concurrent.TimeUnit;
  8.  
  9. import org.apache.commons.io.FileUtils;
  10. import org.apache.commons.lang3.RandomStringUtils;
  11. import org.apache.log4j.Logger;
  12. import org.apache.log4j.PropertyConfigurator;
  13. import org.openqa.selenium.By;
  14. import org.openqa.selenium.JavascriptExecutor;
  15. import org.openqa.selenium.Keys;
  16. import org.openqa.selenium.OutputType;
  17. import org.openqa.selenium.TakesScreenshot;
  18. import org.openqa.selenium.WebDriver;
  19. import org.openqa.selenium.chrome.ChromeDriver;
  20. import org.openqa.selenium.firefox.FirefoxDriver;
  21. import org.openqa.selenium.ie.InternetExplorerDriver;
  22. import org.testng.annotations.AfterClass;
  23. import org.testng.annotations.BeforeClass;
  24. import org.testng.annotations.Parameters;
  25. import org.testng.annotations.Test;
  26.  
  27. import com.ABC.PageObjects.LoginPage;
  28. import com.ABC.Utilities.ReadConfig;
  29.  
  30. public class BaseClass {
  31.  
  32. ReadConfig readconfig = new ReadConfig();
  33. public String baseUrl = readconfig.getApplicationUrl();
  34. public String baseUrl1 = readconfig.getApplicationUrl1();
  35. public String username = readconfig.getUsername();
  36. public String password = readconfig.getPassword();
  37. public static WebDriver driver;
  38. public static Logger log;
  39.  
  40. @Parameters("browser")
  41. @BeforeClass
  42. public void SetUp(String br) throws IOException {
  43.  
  44. log = Logger.getLogger("ABC");
  45. PropertyConfigurator.configure("log4j.properties");
  46.  
  47. if(br.equals("chrome")) {
  48. System.setProperty("webdriver.chrome.driver",readconfig.getChropath());
  49. driver = new ChromeDriver();
  50. }
  51. else if(br.equals("firefox")) {
  52. System.setProperty("webdriver.gecko.driver",readconfig.getFirefoxpath());
  53. driver = new FirefoxDriver();
  54. }
  55. else if(br.equals("ie")) {
  56. //System.setProperty("webdriver.gecko.driver",readconfig.getFirefoxpath());
  57. driver = new InternetExplorerDriver();
  58. }
  59.  
  60. driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);// its waiting only 3-4 sec
  61. driver.manage().window().maximize();
  62.  
  63. driver.get(baseUrl);
  64.  
  65. }
  66.  
  67.  
  68.  
  69. @AfterClass(enabled = true)
  70. public void TearDown() {
  71. driver.quit();
  72. }
  73. public void captureScreen(WebDriver driver, String tname) throws IOException {
  74. TakesScreenshot ts = (TakesScreenshot) driver;
  75. File source = ts.getScreenshotAs(OutputType.FILE);
  76. File target = new File(System.getProperty("user.dir") + "/Screenshots/" + tname + ".png");
  77. FileUtils.copyFile(source, target);
  78. System.out.println("Screenshot taken");
  79. }
  80.  
  81. `public class TC_001_LoginTest extends BaseClass {
  82.  
  83. @Test
  84. public void Login() throws IOException {
  85. log.info("url is opened");
  86. LoginPage lp = new LoginPage(driver);
  87. lp.setUserName(username);
  88. log.info("Username entered");
  89. lp.setPassword(password);
  90. log.info("Password entered");
  91. lp.clickSubmit();
  92. log.info("clicked");`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement