Simply Selenium!!

Run in Chrome browser:

Step 1: Create new java class:

DriverFactory.java:

package com.data;

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.firefox.FirefoxDriver;

//import static com.data.DriverFactory.BrowseType.*;

public class DriverFactory {

public enum BrowserType{

FIREFOX,

CHROME,

IE,

SAFARI

}

public static WebDriver getDriver(BrowserType type){

WebDriver driver=null;

switch(type){

case FIREFOX:

driver=new FirefoxDriver();

break;

case CHROME:

//System.setProperty(“webdriver.chrome.driver”, “src/main/resources/drivers/chrome.exe”);

System.setProperty(“webdriver.chrome.driver”, “C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe”);

driver=new ChromeDriver();

break;

default:

driver=new FirefoxDriver();

break;

}

return driver;

}

}

Step 2: Changes in Login_test.java

package com.facebook.tests;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.assertTrue;

import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert;
import org.testng.annotations.*;

import com.data.FacebookLoginPage;
import com.data.FacebookMainFeed;
import com.data.FacebookMainPage;
import com.data.Facebookdata;
import com.data.DriverFactory;

public class Login_test{

public WebDriver driver;
 DriverFactory.BrowserType type=DriverFactory.BrowserType.CHROME;
 FacebookMainPage fbMainPage;
 FacebookMainFeed fbMainFeed;
 FacebookLoginPage fbLoginPage;

@BeforeClass(alwaysRun=true)
 public void setUp()
 {
 //this.driver=new FirefoxDriver();
 this.driver=DriverFactory.getDriver(type);
 fbMainPage=PageFactory.initElements(driver, FacebookMainPage.class);
 fbLoginPage=PageFactory.initElements(driver, FacebookLoginPage.class);
 fbMainFeed=PageFactory.initElements(driver, FacebookMainFeed.class);
 }
 @AfterClass(alwaysRun=true)
 public void tearDown()
 {//Close Driver
 this.driver.quit();
 }
 
 @BeforeMethod
 public void beforeMethod(){
 System.out.println(“Before method”);
 }

@Parameters({“browserType”})
 @Test(groups={“p1”, “pageLoads”})
 public void loadPage(@Optional(“Chrome”) String browserType){
 System.out.println(“browserType — “+browserType);
 fbMainPage.loadpage();
 }

@Test(groups={“p2”, “field”}, dependsOnMethods=”loadPage”)
 public void filloutEmailFld(){
 fbMainPage.setText_EmailLogin(“sha@gmail.com”);
 }
 @Test(groups={“p2”, “field”}, dependsOnMethods=”filloutEmailFld”)
 public void filloutPassFld(){
 fbMainPage.setText_EmailLogin(“*****”);
 }

@Test(groups={“p2”},dataProviderClass=Facebookdata.class,dataProvider=”login”)
 public void testLoginPage(String email, String password, String errorType){
 driver.manage().deleteAllCookies();
 driver.get(fbMainPage.PAGE_URL);
 Assert.assertEquals(driver.getTitle(),fbMainPage.PAGE_TITLE);
 fbMainPage.setText_EmailLogin(email);
 fbMainPage.setText_passwordLogin(password);
 fbMainPage.clickLoginMain();

if(!StringUtils.isBlank(errorType))
 {
 boolean result = fbLoginPage.checkErrorHeader(errorType);
 Assert.assertTrue(result,”Expected result:-”+errorType);
 }
 /*else
 {
 assertTrue(!fbMainFeed.getUsernameText().isEmpty());
 }*/
 }
}

Result: Test will run in chrome browser

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.