2

Here is my code for client registration page.

package Pages;
import org.apache.bcel.generic.Select;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class ClientPage 
{

@FindBy(linkText="Admin")
WebElement admin;
@FindBy(linkText="Clients")
WebElement clients;
@FindBy(xpath="//*[@id='search-container']/a/i")
WebElement search;
@FindBy(id="name")
WebElement name;

@FindBy(name="address")
WebElement address;

@FindBy(id="status")
WebElement select;

//constructor
public ClientPage(WebDriver driver)
{
    //initialize elements
      PageFactory.initElements(driver,this);

}
public void clickOnadmin()
{
    admin.click();
}
public void clickonclient()
{
    clients.click();
}

public void clickonsearch()
{
    search.click();
}
public void set_clientname(String na)
{
    name.clear();
    name.sendKeys(na);

}

public void set_address(String add)
{
    address.clear();
    address.sendKeys("add");
}
public void select_list()
{
     Select stat=new Select(driver.findElement(By.id("status")));
     stat.selectByVisibleText("active");
}


}

Here is the test page.

package Test;
import org.testng.annotations.Test;
import Pages.ClientPage;
import Pages.HomePage;
import org.testng.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;



public class ClientTest
{
WebDriver driver;
@BeforeTest
public void setup()
{
    System.setProperty("webdriver.firefox.marionette","pathToGeckodriver");
    driver=new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("http://54.68.159.204/qmsadm");
}
@Test
public void verify()
{
    HomePage home=new HomePage(driver);
    home.set_username("");
    home.set_password("");
    home.click_button();
    Assert.assertTrue(driver.getPageSource().contains("Hello Sony George"));
}
@Test(priority=1)
public void verify1()
{
    ClientPage client=new ClientPage(driver);
    client.clickOnadmin();
    client.clickonclient();
    Assert.assertTrue(driver.getPageSource().contains("Hello Sony George"));
}
@Test(priority=2)
public void verify2()
{
    ClientPage client=new ClientPage(driver);
    client.clickOnadmin();
    client.clickonclient();
    client.clickonsearch();
    client.set_clientname("Ajmal police");
    client.set_address("dubai");
    }

}
1

First of all, select a value from drop down list is not unique to page object model. Even there was no page object model, you could still do it.

Your question is not clear on which the drop down list is, so here it is: From your ClientPage, you have the following elements Admin, Clients, search, name, address, status; the actions you can perform is clickOnadmin(), clickonclient(), clickonsearch(), set_clientname(String na), set_address(String add), select_list(), verify(), verify1() and verify2().

It seems the coding style is not the best it can be, can I please suggest you go through your code and make sure that all functions have the same naming convention and all arguments make sense? Below is one way to do it

  • clickOnadmin() should be clickOnAdmin()
  • clickonclient() should be clickOnClient()
  • clickonsearch() should be clickOnSearch()
  • set_clientname(String na) should be setClientName(String clientName)
  • set_address(String add) should be setAddress(String address)
  • select_list() should be selectList(), this function should have an input argument I think, otherwise, which one do you select from a list?
  • verify(), should change its name to indicate its purpose. What does it verify? It verifies if you have navigated to the right page.
  • verify1(), it is not clear what you are verifying
  • verify2(), it is not clear what you are verifying

In your function verify(), can I please suggest you add a bit more to it? What happens if the page source does not contain "Hello Sony George"? Your code should navigate to the page you intended to navigate OR display a meaningful message, warning the user this is NOT the page you want to navigate to.

If the drop down list you want to select from is the Status, which has None, Inactive, Active and Archived items, you could add

public  void statusDropDownList(int index) {
      Select drop = new Select(status);
      drop.selectByIndex(index);  
}

Please do not include your login credentials in a question, you could simply provide us with HTML code.

2

Try this,

public class ClientPage{
   @FindBy(id="status")
   WebElement status_dropdown;
   ----------------------------------
   ----------------------------------   
   ----------------------------------
   ----------------------------------
   public void select_list(String status){
     Select statusDropdown=new Select(status_dropdown);
     statusDropdown.selectByVisibleText(status);
  }
}


public class ClientTest{
   ----------------------------------
   ----------------------------------   
   ----------------------------------
   ----------------------------------
   @Test(priority=2)
   public void verify2(){
     ClientPage client=new ClientPage(driver);
     ----------------------------------
     ----------------------------------   
     ----------------------------------
     ----------------------------------
     client.select_list("active");
   }
}
  • i'm new in testing feild. I like to be perfectionist toward my work. thats why i am asking. could you tell me about my work. What improvment that I have to made...thank you – user21268 Oct 10 '16 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy