Skip to content

Instantly share code, notes, and snippets.

@marcodejongh
Created November 26, 2013 10:38
Show Gist options
  • Save marcodejongh/7656366 to your computer and use it in GitHub Desktop.
Save marcodejongh/7656366 to your computer and use it in GitHub Desktop.
Example for using senbot pagerepresentation classes
package com.gfk.echo.senbot.cucumber.views;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
public class MyView {
@FindBy(how = How.ID, using = "WhateverID")
public WebElement someElement;
}
package com.gfk.echo.senbot;
import org.openqa.selenium.By;
import com.gfk.echo.senbot.cucumber.views.*;
import com.gfk.senbot.drive.common.model.DriveUser;
import com.gfk.senbot.framework.data.ReferenceServicePopulator;
import com.gfk.senbot.framework.data.SenBotReferenceService;
public class SenBotReferenceDataPopulator implements ReferenceServicePopulator {
public void populate(SenBotReferenceService referenceService) {
referenceService.addPageRepresentationReference("MyView", MyView.class);
}
}
package com.gfk.echo.senbot.cucumber.stepdefinitions;
import static org.junit.Assert.fail;
import java.util.List;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.MoveToOffsetAction;
import org.openqa.selenium.support.FindBy;
import com.gfk.echo.senbot.ScenarioCreationHook;
import com.gfk.senbot.framework.BaseServiceHub;
import com.gfk.senbot.framework.services.selenium.ElementService;
import com.gfk.senbot.framework.services.selenium.NavigationService;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.runtime.java.StepDefAnnotation;
@StepDefAnnotation
public class EditModeSteps extends BaseServiceHub {
private static Logger log = Logger.getLogger(EditModeSteps.class);
@Resource
private ElementService seleniumElementService;
@Resource
private NavigationService seleniumNavigationService;
@Then("^I expect the \"([^\"]*)\" to not be in the \"([^\"]*)\" on the \"([^\"]*)\" view$")
public void I_expect_the_to_not_be_in_the_on_the_view(String source, String parent, String view) throws Throwable {
WebElement parentElement = seleniumElementService.viewShouldShowElement(view, parent);
FindBy sourceSelector = seleniumElementService.getFindByDescriptor(view, source);
String id = sourceSelector.using();
try{
parentElement.findElement(By.id(id));
fail("The element " + source + " with id: " + id + " is not a child of " + parent);
}
catch (NoSuchElementException nsee){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment