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/");

} }

closed as unclear what you're asking by dzieciou, Milin Patel, Kate Paulk, Bharat Mane, ECiurleo Jul 7 '16 at 10:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I tell you what I am trying to do. I have created a class for setup() method in a package. Then I created a different package and created two classes, 1 for objectrepo and 2. to call those objectrepo methods. I kept the logic for login() in a different package so there are three packages. 1-> for setup() 2-> for login() and 3-> to add new user. Now I am trying to use @Test annotation for login() and addnewuser(). When I run the script, I am able to login but then script stops and gives an error message java.lang.nullpointer exception. – tarun bajpai Jun 28 '16 at 6:26
  • @dzieciou I am sure that there is a problem with driver, perhaps it find it null. Could you please help me out figuring out the solution. I am new to programming and hence finding it difficult. – tarun bajpai Jun 28 '16 at 6:27
  • Is there any question? Did you provide the exception? I see only some code – kotoj Jun 28 '16 at 7:57
  • of course I have a question. I am not able to add new user using below approach – tarun bajpai Jun 28 '16 at 8:00
  • @Test(dataProvider = "userdataprovider") public void NewUserWillBeAddedFromHere(String newuser, String EmailId, String fname, String lname, String websitename) { AddNewUserLogic.AddNewUserHere(newuser, EmailId, fname, lname, websitename); Assert.assertEquals(true, AddNewUserLogic.Check_If_NewUser_Is_Created()); } – tarun bajpai Jun 28 '16 at 8:00
up vote 4 down vote accepted

Welcome to SQA.

Instead of me investigating what happens in this particular case, I think it will be more helpful for this and similar questions to understand how to

That will be useful to you not only in this particular case but also in your further adventure with test automation and generally programming.

Another option is to pair with a programmer in your company or your city and learn from him or her. My experience is that watching how someone else investigating a problem is much better way to learn things than explaining that here. This is a classical example of tacit knowledge.

  • If it's more helpful, but not an answer to the question, then this should be a comment. Stack Exchange avoids boilerplate answers. Boilerplate comments, those are a little more okay. (I see the irony here. I do.) – corsiKa Jul 13 '16 at 17:35
  • @corsiKa I agree it does not answer the question directly. But decision whether something is an answer is subjective here, and up to the OP. And in this question s/he accepted it as an answer. If I had answered directly what the OP had asked for that would have been boilerplate answer: repeating what NullPointerException is. Every week I see an instance of the same problem on this forum: why do I have NullPointerException here. Marking them as off-topic (they are about programming) or duplicate (same class of NPE problems) does not seem to prevent those questions from coming. – dzieciou Jul 13 '16 at 18:01
  • Keep voting to close as off-topic or duplicate. That's the model. – corsiKa Jul 13 '16 at 18:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.