Error is throwin hen calling dopasswordchange() method without arguments, if use arguments , there is no error and runs sucessfully
===============================================
dopasswordchange Func:
public void doPasswordChange(String oPassword, String nPassword) {
// TODO Auto-generated method stub
oldPassword.sendKeys(oPassword);
test.log(Status.INFO,"Current Password Entered" + oPassword );
System.out.println ("Current Password Entered" +nPassword);
newPassword.sendKeys(nPassword);
test.log(Status.INFO,"NEW Password Entered" + nPassword);
System.out.println ("NEW Password Entered" +nPassword);
confirmPassword.sendKeys(nPassword);
test.log(Status.INFO,"NEW Password confirmed" + nPassword);
System.out.println ("NEW Password confirmed" +nPassword);
loginSubmit.click();
test.log(Status.INFO,"NEW Password Confirmed");
System.out.println ("NEW Password Confirmed");
if(!isElementPresent(FBConstants.PASSWORD_CHANGE))
reportFailure("PASS WORD DID NOT CHANGE ");
RevDevice.click();
test.log(Status.INFO,"Review device selected");
System.out.println ("Review device selected");
}
======================================================
Gensetpage CLASS
package com.ktest.FaceBook.pom.session.settings;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.ktest.FaceBook.pom.base.BasePage;
import com.ktest.FaceBook.pom.util.FBConstants;
public class GensetPage extends BasePage {
@FindBy(xpath=FBConstants.SECURITYNLOGIN_LINK)
public WebElement secLogin;
@FindBy(xpath=FBConstants.PASSWORD_CHANGE)
public WebElement editPassword;
@FindBy(xpath=FBConstants.OLD_PASSWORD)
public WebElement oldPassword;
@FindBy(xpath=FBConstants.NEW_PASSWORD)
public WebElement newPassword;
@FindBy(xpath=FBConstants.CONF_PASSWORD)
public WebElement confirmPassword;
//@FindBy(xpath="//*[@id='loginbutton']")
//public WebElement loginSubmit;
@FindBy(xpath= FBConstants.Submit_PASSWORD )
public WebElement loginSubmit;
@FindBy(xpath= FBConstants.ReviewDevice_Button )
public WebElement RevDevice;
public void gotoPasswordChange()
{
test.log(Status.INFO,"Acessing GOTO Password Change");
System.out.println ("Acessing GOTO Password Change");
secLogin.click();
test.log(Status.INFO,"Security and login SUB MENU OPEN");
System.out.println ("Security and login SUB MENU OPEN");
if (!isElementPresent(FBConstants.PASSWORD_CHANGE))
{
takeScreenshot();
test.log(Status.FAIL,"Clicking on Password Change FAIL");
Assert.fail("Element NOT Found"+(FBConstants.PASSWORD_CHANGE));
}
editPassword.click();
test.log(Status.INFO,"General Account Setting: Change Password Opened");
System.out.println ("General Account Setting: Change Password Opened");
}
public void doPasswordChange(String oPassword, String nPassword) {
// TODO Auto-generated method stub
oldPassword.sendKeys(oPassword);
test.log(Status.INFO,"Current Password Entered" + oPassword );
System.out.println ("Current Password Entered" +nPassword);
newPassword.sendKeys(nPassword);
test.log(Status.INFO,"NEW Password Entered" + nPassword);
System.out.println ("NEW Password Entered" +nPassword);
confirmPassword.sendKeys(nPassword);
test.log(Status.INFO,"NEW Password confirmed" + nPassword);
System.out.println ("NEW Password confirmed" +nPassword);
loginSubmit.click();
test.log(Status.INFO,"NEW Password Confirmed");
System.out.println ("NEW Password Confirmed");
if(!isElementPresent(FBConstants.PASSWORD_CHANGE))
reportFailure("PASS WORD DID NOT CHANGE ");
RevDevice.click();
test.log(Status.INFO,"Review device selected");
System.out.println ("Review device selected");
}
public GensetPage(WebDriver driver, ExtentTest test) {
//this.driver = driver;
//this.test=test;
super(driver, test);
// TODO Auto-generated constructor stub
}
}
==========================================================================
Change Password CLASS"
package com.ktest.FaceBook.pom.testcases;
import java.lang.reflect.Method;
import java.util.Hashtable;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.support.PageFactory;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.ktest.FaceBook.pom.pages.LaunchPage;
import com.ktest.FaceBook.pom.pages.LoginPage;
import com.ktest.FaceBook.pom.session.LandingPage;
import com.ktest.FaceBook.pom.session.settings.GensetPage;
import com.ktest.FaceBook.pom.testcases.Base.BaseTest;
import com.ktest.FaceBook.pom.util.DataUtil;
import com.ktest.FaceBook.pom.util.ExtentManager;
import com.ktest.FaceBook.pom.util.FBConstants;
//===Module 25 Part 5===Extent Report Log================
public class ChangePasswordTest extends BaseTest {
String testCaseName = "ChangePasswordTest";
@Test(dataProvider = "getData")
public void changePasswordTest(Hashtable<String, String> data) throws Exception {
//====== //ExtentTest test =
test = extent.createTest(testCaseName);
test.log(Status.INFO,"Starting CHANGE PASS WORD TEST");
System.out.println("********Starting CHANGE PASS WORD TEST*******");
if (DataUtil.isSkip(testCaseName, xls)
|| data.get(FBConstants.RUNMODE_COL).equals(FBConstants.RUNMODE_NO)) {
test.log(Status.SKIP, "Run Mode is set to NO ");
throw new SkipException("Runmode is set to N");
}
System.out.println(testCaseName + "reunning for Face Book on POM");
init(data.get("Browser"));
//Create Object pass DRIVER and test
LaunchPage launchPage = new LaunchPage (driver,test);
//Initiate ELEMENTS on page
PageFactory.initElements(driver, launchPage);
LoginPage loginPage = launchPage.gotoLoginPage();
loginPage.takeScreenshot();
test.log(Status.INFO,"Logging in ");
Object page = loginPage.doLogin(data.get("Username"), data.get("OldPassword"));
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
if (page instanceof LoginPage)
reportFailure("failuremessage");
LandingPage landingPage = (LandingPage)page;
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
GensetPage settings = landingPage.getMenu().gotoSetting();
test.log(Status.INFO,"General Setting Page Opened");
System.out.println("********General Setting Page Opened*******");
// test.log(Status.PASS,"Change Password test PASS");
settings.gotoPasswordChange();
test.log(Status.INFO,"***********NOW WILL CHANGE PASS WORD**************");
System.out.println("***********NOW WILL CHANGE PASS WORD**************");
settings.doPasswordChange("password1", "Password2");
test.log(Status.INFO,"***********PASS WORD IS CHANGED **************");
System.out.println("***********PASS WORD IS CHANGED **************");
}
@AfterMethod
public void quit()
{
if (extent !=null)
extent.flush();
}
//=====================================================================
@DataProvider
// public Object [][] getData ()
// ==========Get Method Name call Java Reflaction Method
public Object[][] getData(Method method) {
return DataUtil.getTestData(xls, testCaseName);
}
//======================================================================================================
}
Instructor
Ashish Thakur Replied on 28/10/2019
Make sure that all code is saved. This happens sometimes.
For Passparameter when we call a function do we need to put arguments all time
dopasswordchange(password1,password2)
and when declare function should have variables declared
public void doPasswordChange(String oPassword, String nPassword) {
Instructor
Ashish Thakur Replied on 29/10/2019
Yes, we need to provide both parameters at the time of calling the method.