package com.MainExecutionforWordpress;import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test;
import com.AD.Wordpress.Login.CallLoginPageElementsHere; import com.AddNewUser.AddNewUserLogic; import com.AddNewUser.RetrieveNewUserData;
public class TestWordpressHere {
CallLoginPageElementsHere login = new CallLoginPageElementsHere(); AddNewUserLogic addnew = new AddNewUserLogic();
@Test(dataProvider = "dprovider") public void Wordpress_Execution_starts_here(String username, String password ) { // try below approach also to open the browser login.callinsetupmethod(); login.Login(username,password); Assert.assertEquals(true, login.IsatHomepage());
}
@DataProvider public String[][] dprovider() { String [][] user = new String[1][2];
// i stands for number of times test case should run // j stands for number of parameters it should send at one go user[0][0] = "admin"; user[0][1] = "tarunkamina"; return user;
}
@Test(dataProvider = "userdataprovider") public void NewUserWillBeAddedFromHere(String newuser, String EmailId, String fname, String lname, String websitename) { AddNewUserLogic.AddNewUserHere(newuser, EmailId, fname, lname, websitename);
// Add New User Repository package com.AddNewUser;import org.openqa.selenium.By; import org.openqa.selenium.WebElement;
import com.SetUpMethodRepo.DriverMethod;
public class AddNewUserRepo { public static WebElement UsersObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='menu-users']/a/div[3]")); }
public static WebElement AddNewObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='menu-users']/ul/li[3]/a")); } public static WebElement UsernameFieldObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='user_login']")); } public static WebElement EmailFieldObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='email']")); } public static WebElement FirstNameObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='first_name']")); } public static WebElement LastNameObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='last_name']")); } public static WebElement WebSiteObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='url']")); } public static WebElement UncheckTheCheckBox() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='send_user_notification']")); } public static WebElement AddNewUserObjXpath() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='createusersub']")); } public static WebElement NewUserCreated() { return DriverMethod.driver.findElement(By.xpath(".//*[@id='message']/p")); }
}
// // Add New User Logic package com.AddNewUser;public class AddNewUserLogic { public static void AddNewUserHere(String newuser, String EmailId, String fname, String lname, String websitename) { AddNewUserRepo.UsersObjXpath().click(); AddNewUserRepo.AddNewObjXpath().click(); AddNewUserRepo.UsernameFieldObjXpath().sendKeys(newuser); AddNewUserRepo.EmailFieldObjXpath().sendKeys(EmailId); AddNewUserRepo.FirstNameObjXpath().sendKeys(fname); AddNewUserRepo.LastNameObjXpath().sendKeys(lname); AddNewUserRepo.WebSiteObjXpath().sendKeys(websitename); AddNewUserRepo.UncheckTheCheckBox().click(); AddNewUserRepo.AddNewUserObjXpath().click();
}
public static boolean Check_If_NewUser_Is_Created() // Validating new user { if(AddNewUserRepo.NewUserCreated().getText().contains("New user created")) { return true; } else { return false; } }
}
package com.AddNewUser;import java.util.Iterator;
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.openqa.jetty.start.Main;
public class RetrieveNewUserData { public static String [][] FetchUserDataFromHere() { String filepath = System.getProperty("user.dir")+ "\src\test\resources\NewUserData.properties"; System.out.println(filepath);
try { PropertiesConfiguration conf = new PropertiesConfiguration(filepath); Iterator<String> itr = conf.getKeys(); String [][] user = new String[1][5]; while(itr.hasNext()) { for(int i = 0; i < 1; i++) { for(int j = 0; j < 5; j++) { user[i][j]= conf.getString(itr.next()) ; } } System.out.println("Inside While loop...."); } return user; } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null;
}
public static void main(String[] args) { FetchUserDataFromHere(); System.out.println("user data"); } }
// Setup method package com.SetUpMethodRepo;import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;
public class DriverMethod { public static WebDriver driver = null;
public static void SetUp() { driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("http://abhidwi.byethost17.com/wp/wp-admin/");
// driver.get("http://abhidwi.byethost17.com/wp/wp-admin/");
} }