Abigail and Mommy sat side by side on the stairs in the living room. It was a sunny afternoon. Looking through the big glass window of the room, they were staring at a rabbit sitting and chewing grasses in their neighbor's front lawn. Abigail asked Mommy, "Where is Daddy?" then said to herself, "I love him so much!"
Agile Eyes
by Christina Zhong
Thursday, June 16, 2011
Saturday, May 28, 2011
I Am The Best
Abigail likes to do things by herself. One day she decided to help Mommy connect a cable to a laptop. After a few failed attempts, she became frustrated and cried for a few seconds. Then she managed to do it. Mommy was happy and said: "You did a good job." Abigail responded: "I am the best."
Friday, April 22, 2011
Talking Fish
Daddy was holding Abigail in front of the fish tank at a grocery store. Fish kept opening and closing their mouths as fish do. Daddy asked Abigail what the fish were doing. Abigail said: "They are all talking." "Who are they talking to?" "They are all talking to me."
Monday, May 24, 2010
Integrate JBehave, Selenium and Page Object Pattern
I recently finished setting up automated test framework using JBehave, Selenium and Page Object Pattern. In the process, I came cross several posts that helped me along the way. However, I was not able to find any implementation of class Page or how to use SeleniumSteps. This post is here to close the gap.
The scenario I am going to cover is a user logging in to mytest.com.
The first step is to write the file named user_login_successfully.txt to describe the scenario in plain English.
"Given the user is on the login page
When the user enters username me
And the user enters password password
And the user submits their login
Then the user is on the home page"
The next step is to create a UserLoginSuccessfully.java to represent the scenario.
"public class UserLoginSuccessfully extends org.jbehave.scenario.Scenario{
public UserLoginSuccessfully() {
super(new LoginSteps());
}
}"
Next is LoginSteps.java which executes the scenario step by step.
"public class LoginSteps extends org.jbehave.web.selenium.SeleniumSteps {
private Page currentPage;
protected Selenium createSelenium() {
return new DefaultSelenium("localhost", 4444, "*firefox",
"http://mytest.com");
}
@Given("that the user is on the login page")
public void notLogin() throws Exception {
currentPage = new LoginPage(selenium);
currentPage.open();
assertTrue(currentPage.verifyTitle());
}
@When("the user enters username $username")
public void setUserName(String username) {
loginPage().setUserName(username);
}
@When("the user enters password $password")
public void setPassword(String password) {
loginPage().setPassword(password);
}
@When("the user submits their login")
public void submitLogin() {
loginPage().login();
}
@Then("the user is on the homepage")
public void homePage() {
currentPage = new HomePage(selenium);
assertTrue(currentPage.verifyTitle());
}
private LoginPage loginPage() {
return (LoginPage) currentPage;
}
}"
Now is the time to implement Page Object Pattern. Page is a POJO.
"public abstract class Page {
protected Selenium selenium;
public Page(Selenium selenium) {
this.selenium = selenium;
}
public void open() {
selenium.open(getUrl());
}
public abstract String getUrl();
public abstract String getTitle();
public boolean verifyTitle() {
return getTitle().equals(selenium.getTitle());
}
}"
LoginPage.java and HomePage.java extend Page.java. If the id of the text field of username in the login page changes, you only need to modify one place in LoginPage.java. This is the reason that Page Object Pattern is so powerful.
"public class LoginPage extends Page {
public LoginPage(Selenium selenium) {
super(selenium);
}
public String getUrl() {
return "/login/login.html";
}
public String getTitle() {
return "Login - MyTest";
}
public void setUserName(String username) {
selenium.typeKeys("j_username", username);
}
public void setPassword(String password) {
selenium.typeKeys("j_password", password);
}
public void login() {
selenium.click("j_submit");
}
}"
"public class HomePage extends Page {
public HomePage(Selenium selenium) {
super(selenium);
}
public String getUrl() {
return "/home/index.html";
}
public String getTitle() {
return "Welcome - Test";
}
}"
You are done. Just start the Selenium server, you can run the test as a junit test in your choice of IDE and it should work like a charm.
Here are the links to the posts that helped me along the way.
http://blog.m.artins.net/acceptance-tests-with-jbehave-selenium-page-objects/
http://www.bitmotif.com/java/jbehaveselenium-example/
http://code.google.com/p/selenium/wiki/PageObjects
The scenario I am going to cover is a user logging in to mytest.com.
The first step is to write the file named user_login_successfully.txt to describe the scenario in plain English.
"Given the user is on the login page
When the user enters username me
And the user enters password password
And the user submits their login
Then the user is on the home page"
The next step is to create a UserLoginSuccessfully.java to represent the scenario.
"public class UserLoginSuccessfully extends org.jbehave.scenario.Scenario{
public UserLoginSuccessfully() {
super(new LoginSteps());
}
}"
Next is LoginSteps.java which executes the scenario step by step.
"public class LoginSteps extends org.jbehave.web.selenium.SeleniumSteps {
private Page currentPage;
protected Selenium createSelenium() {
return new DefaultSelenium("localhost", 4444, "*firefox",
"http://mytest.com");
}
@Given("that the user is on the login page")
public void notLogin() throws Exception {
currentPage = new LoginPage(selenium);
currentPage.open();
assertTrue(currentPage.verifyTitle());
}
@When("the user enters username $username")
public void setUserName(String username) {
loginPage().setUserName(username);
}
@When("the user enters password $password")
public void setPassword(String password) {
loginPage().setPassword(password);
}
@When("the user submits their login")
public void submitLogin() {
loginPage().login();
}
@Then("the user is on the homepage")
public void homePage() {
currentPage = new HomePage(selenium);
assertTrue(currentPage.verifyTitle());
}
private LoginPage loginPage() {
return (LoginPage) currentPage;
}
}"
Now is the time to implement Page Object Pattern. Page is a POJO.
"public abstract class Page {
protected Selenium selenium;
public Page(Selenium selenium) {
this.selenium = selenium;
}
public void open() {
selenium.open(getUrl());
}
public abstract String getUrl();
public abstract String getTitle();
public boolean verifyTitle() {
return getTitle().equals(selenium.getTitle());
}
}"
LoginPage.java and HomePage.java extend Page.java. If the id of the text field of username in the login page changes, you only need to modify one place in LoginPage.java. This is the reason that Page Object Pattern is so powerful.
"public class LoginPage extends Page {
public LoginPage(Selenium selenium) {
super(selenium);
}
public String getUrl() {
return "/login/login.html";
}
public String getTitle() {
return "Login - MyTest";
}
public void setUserName(String username) {
selenium.typeKeys("j_username", username);
}
public void setPassword(String password) {
selenium.typeKeys("j_password", password);
}
public void login() {
selenium.click("j_submit");
}
}"
"public class HomePage extends Page {
public HomePage(Selenium selenium) {
super(selenium);
}
public String getUrl() {
return "/home/index.html";
}
public String getTitle() {
return "Welcome - Test";
}
}"
You are done. Just start the Selenium server, you can run the test as a junit test in your choice of IDE and it should work like a charm.
Here are the links to the posts that helped me along the way.
http://blog.m.artins.net/acceptance-tests-with-jbehave-selenium-page-objects/
http://www.bitmotif.com/java/jbehaveselenium-example/
http://code.google.com/p/selenium/wiki/PageObjects
Tuesday, February 12, 2008
Production Support
I was doing production support for a project for about 4 months which changed my view about interaction between consultants and clients.
Because the time I spent with different client groups, I finally realize a good consultant means to treat your clients with respect; just as naturally you would respect your colleagues.
Because the time I spent with different client groups, I finally realize a good consultant means to treat your clients with respect; just as naturally you would respect your colleagues.
Monday, October 30, 2006
My cats
I love cats and have two. They are Brooklyn Wooly which is a pretty new breed. One is taller and the other is smaller. Taller is absolutely brave and basically tries anything. And Smaller is sort of shy and will run away any time you just to reach him. Oddly, if you just sit there in the coach, the one that will come around first is usually Smaller. Unfortunately, Smaller never learns to hold his claws and will get caught on your cloth easily. My favor is to see them fighting. For they are so close that you can’t tell which one is which, but two wool balls on the ground.
Subscribe to:
Comments (Atom)