Advertisement
Guest User

Untitled

a guest
May 21st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. package click2test;
  2.  
  3. import org.openqa.selenium.WebDriver;
  4.  
  5. public class AbstractPage {
  6.  
  7. protected WebDriver selenium;
  8.  
  9. public AbstractPage(WebDriver selenium) {
  10. this.selenium = selenium;
  11. }
  12.  
  13. public WebDriver getDriver() {
  14. return selenium;
  15. }
  16.  
  17. public LoginPageObject navigateToLoginPage() {
  18. selenium.navigate().to("https://urlofsite/");
  19. return new LoginPageObject(selenium);
  20. }
  21. }
  22.  
  23. package click2test;
  24.  
  25. import java.net.URL;
  26.  
  27. import org.openqa.selenium.WebDriver;
  28. import org.openqa.selenium.chrome.ChromeOptions;
  29. import org.openqa.selenium.phantomjs.PhantomJSDriverService;
  30. import org.openqa.selenium.remote.DesiredCapabilities;
  31. import org.openqa.selenium.remote.RemoteWebDriver;
  32. import org.testng.Assert;
  33. import org.testng.annotations.AfterMethod;
  34. import org.testng.annotations.BeforeMethod;
  35. import org.testng.annotations.Parameters;
  36.  
  37. public class SelTestCase extends AbstractPage{
  38. protected WebDriver selenium;
  39.  
  40. public SelTestCase(WebDriver selenium) {
  41. super(selenium);
  42. this.selenium = selenium;
  43. }
  44.  
  45. @BeforeMethod()
  46. @Parameters({"browser","port"})
  47. public void launchBrowsers(String browser, String port) throws Exception {
  48.  
  49. DesiredCapabilities capabilities = new DesiredCapabilities();
  50. capabilities.setBrowserName(browser);
  51.  
  52. // To remove message "You are using an unsupported command-line
  53. // flag: --ignore-certificate-errors.
  54. // Stability and security will suffer."
  55. // Add an argument 'test-type'
  56.  
  57. selenium = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
  58.  
  59. selenium.manage().window().maximize();
  60. selenium.manage().deleteAllCookies();
  61.  
  62. Assert.assertEquals(true, selenium.getCurrentUrl().contains("login"));
  63.  
  64. }
  65.  
  66. @AfterMethod
  67. public void tearDown() throws Exception {
  68. //finally close down browser window
  69. if (selenium != null) {
  70. try {
  71. selenium.close();
  72. selenium.quit();
  73. } catch (Throwable e) {
  74.  
  75. }
  76. }
  77. }
  78. }
  79.  
  80. package click2test;
  81.  
  82. import org.openqa.selenium.By;
  83. import org.openqa.selenium.WebDriver;
  84.  
  85. public class LoginPageObject extends SelTestCase{
  86. WebDriver selenium;
  87.  
  88. public LoginPageObject(WebDriver selenium) {
  89. super(selenium);
  90. this.selenium = selenium;
  91. // TODO Auto-generated constructor stub
  92. }
  93.  
  94. public LoginPageObject loginWithCorrectUsernameAndPassword(String username, String password) {
  95. selenium.findElement(By.cssSelector("[class~='absoluteCentre'] [name=UserName]"))
  96. .sendKeys(username);
  97. selenium.findElement(By.cssSelector("[class~='absoluteCentre'] [name=password]"))
  98. .sendKeys(password);
  99. //delay(3000);
  100. return this;
  101. }
  102. }
  103.  
  104. package click2test;
  105.  
  106. import org.openqa.selenium.WebDriver;
  107. import org.testng.Assert;
  108. import org.testng.annotations.Test;
  109.  
  110. public class LoginPage{
  111. WebDriver selenium;
  112.  
  113. LoginPageObject loginpageobject = new LoginPageObject(selenium);
  114.  
  115. public LoginPage(WebDriver selenium) {
  116. this.selenium = selenium;
  117. // TODO Auto-generated constructor stub
  118. }
  119.  
  120. @Test
  121. public void loginWithCorrectUsernameAndPasswordTest() {
  122.  
  123. String username = "username@gmail.com";
  124. String password = "password";
  125.  
  126.  
  127. // enter correct username and password then submit
  128. loginpageobject.navigateToLoginPage()
  129. .loginWithCorrectUsernameAndPassword(username, password);
  130. Assert
  131. .assertEquals(true, selenium
  132. .getCurrentUrl().contains("home"));
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement