Created
March 1, 2011 19:13
-
-
Save ck1125/849685 to your computer and use it in GitHub Desktop.
Step definitions used by features
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import com.thoughtworks.selenium.DefaultSelenium; | |
import com.thoughtworks.selenium.Selenium; | |
import cuke4duke.annotation.Before; | |
import cuke4duke.annotation.I18n.EN.Then; | |
import cuke4duke.annotation.I18n.EN.When; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertTrue; | |
public class BrandHubSteps { | |
private static Selenium selenium; | |
public void init(String browser, String browserURL) { | |
int seleniumPort = 4444; | |
selenium = new DefaultSelenium("localhost", seleniumPort, browser, browserURL); | |
selenium.start(); | |
if (browser.contains("firefox")) { | |
selenium.setTimeout("75000"); | |
} else { | |
selenium.setTimeout("30000"); | |
} | |
} | |
@Before | |
public void startUpBrowser() { | |
if (selenium == null) { | |
init("*firefox3", "http://www.channel4.com"); | |
} | |
} | |
@When("^I open '(.*)'$") | |
public void openWebPage(String url) { | |
selenium.open(url); | |
} | |
@Then("^the title should be '(.*)'$") | |
public void checkTitleOfPage(String title) { | |
String actualPageTitle = selenium.getTitle(); | |
assertEquals("Expected page title note returned ", title, actualPageTitle); | |
} | |
@Then("^click an item with xpath '(.*)'$") | |
public void clickAnItemWithXPath(String xpath) { | |
selenium.click(xpath); | |
selenium.waitForPageToLoad("30000"); | |
} | |
@Then("^element with id '(.*)' should be present$") | |
public void elementWithIdShouldBePresent(String id) { | |
assertTrue(String.format("Element with %s should be present", id), selenium.isElementPresent(id)); | |
} | |
@Then("^browser location should be '(.*)'$") | |
public void locationShouldMatchSuppliedLocationString(String locationString) { | |
String currentLocation = selenium.getLocation(); | |
assertEquals(String.format("Location should be %s", locationString), locationString, currentLocation); | |
} | |
@Then("^fill form field with id '(.*)' using value '(.*)'$") | |
public void fillFormField(String fieldId, String value) { | |
selenium.type(fieldId, value); | |
} | |
@Then("^submit form with id '(.*)'$") | |
public void submitForm(String formId) { | |
selenium.submit(formId); | |
selenium.waitForPageToLoad("30000"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment