Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package click2test;
- import org.openqa.selenium.WebDriver;
- public class AbstractPage {
- protected WebDriver selenium;
- public AbstractPage(WebDriver selenium) {
- this.selenium = selenium;
- }
- public WebDriver getDriver() {
- return selenium;
- }
- public LoginPageObject navigateToLoginPage() {
- selenium.navigate().to("https://urlofsite/");
- return new LoginPageObject(selenium);
- }
- }
- package click2test;
- import java.net.URL;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.chrome.ChromeOptions;
- import org.openqa.selenium.phantomjs.PhantomJSDriverService;
- import org.openqa.selenium.remote.DesiredCapabilities;
- import org.openqa.selenium.remote.RemoteWebDriver;
- import org.testng.Assert;
- import org.testng.annotations.AfterMethod;
- import org.testng.annotations.BeforeMethod;
- import org.testng.annotations.Parameters;
- public class SelTestCase extends AbstractPage{
- protected WebDriver selenium;
- public SelTestCase(WebDriver selenium) {
- super(selenium);
- this.selenium = selenium;
- }
- @BeforeMethod()
- @Parameters({"browser","port"})
- public void launchBrowsers(String browser, String port) throws Exception {
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setBrowserName(browser);
- // To remove message "You are using an unsupported command-line
- // flag: --ignore-certificate-errors.
- // Stability and security will suffer."
- // Add an argument 'test-type'
- selenium = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
- selenium.manage().window().maximize();
- selenium.manage().deleteAllCookies();
- Assert.assertEquals(true, selenium.getCurrentUrl().contains("login"));
- }
- @AfterMethod
- public void tearDown() throws Exception {
- //finally close down browser window
- if (selenium != null) {
- try {
- selenium.close();
- selenium.quit();
- } catch (Throwable e) {
- }
- }
- }
- }
- package click2test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- public class LoginPageObject extends SelTestCase{
- WebDriver selenium;
- public LoginPageObject(WebDriver selenium) {
- super(selenium);
- this.selenium = selenium;
- // TODO Auto-generated constructor stub
- }
- public LoginPageObject loginWithCorrectUsernameAndPassword(String username, String password) {
- selenium.findElement(By.cssSelector("[class~='absoluteCentre'] [name=UserName]"))
- .sendKeys(username);
- selenium.findElement(By.cssSelector("[class~='absoluteCentre'] [name=password]"))
- .sendKeys(password);
- //delay(3000);
- return this;
- }
- }
- package click2test;
- import org.openqa.selenium.WebDriver;
- import org.testng.Assert;
- import org.testng.annotations.Test;
- public class LoginPage{
- WebDriver selenium;
- LoginPageObject loginpageobject = new LoginPageObject(selenium);
- public LoginPage(WebDriver selenium) {
- this.selenium = selenium;
- // TODO Auto-generated constructor stub
- }
- @Test
- public void loginWithCorrectUsernameAndPasswordTest() {
- String username = "username@gmail.com";
- String password = "password";
- // enter correct username and password then submit
- loginpageobject.navigateToLoginPage()
- .loginWithCorrectUsernameAndPassword(username, password);
- Assert
- .assertEquals(true, selenium
- .getCurrentUrl().contains("home"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement