Documentation of Cherry Framework
Integrate with WebDriver
'Let me google that for you', said The Agent...
Another concept Cherry Framework introduces is the Screen. A Screen is the Graphical Interface of your system or part of it (e.g. web component, widget etc). A ScreenElement is a particular element (selection box, input box or button etc.) that can be located using a specific tool (e.g. WebDriver By locators, Fest TypeMatchers etc.). ScreenFactory is a factory which can help you instantiate a class implementing the Screen interface, and enrich it with the data it requires to function properly by means of specific annotations.
[Note:] Screens do not contain any functionality. They are just containers of ScreenElements or other Screens.
Things can become clearer using some examples from the cherry-webdriver module:
import io.magentys.webdriver.WebScreen;
import io.magentys.webdriver.WebScreenFactory;
import io.magentys.webdriver.annotations.Url;
@Url("https://magentys.gitbooks.io/cherry/content/")
public class CherryFrameworkDocumentation extends WebScreen {
public TableOfContents toc = new WebScreenFactory().init(new TableOfContents());
public MainChapterContent mainChapterContent = new WebScreenFactory().init(new MainChapterContent());
}
TableOfContents and MainChapterContents are equally screens but comprising of WebScreenElements & looking like this:
import io.magentys.screens.annotations.Alias;
import io.magentys.webdriver.WebScreen;
import io.magentys.webdriver.WebScreenElement;
import io.magentys.webdriver.annotations.LocateBy;
public class TableOfContents extends WebScreen {
@Alias("Introduction Link")
@LocateBy(css = "li[data-level='0'] a")
public WebScreenElement introductionLink;
@Alias("First Chapter")
@LocateBy(css = "li[data-level='1'] a")
public WebScreenElement firstChapter;
/*
more elements go here
*/
}
You can now use all of the screens as follows:
- Make sure you assign an instance of WebDriver to the agent (e.g. ChromeDriver)
- Create a Mission to use the screen
- Get the locator of the element and use it to find and use the element you're interested in.
So your Mission could look like this:
import io.magentys.Agent;
import io.magentys.Mission;
import io.magentys.webdriver.WebScreenFactory;
import org.openqa.selenium.WebElement;
import static io.magentys.webdriver.missions.WebDriverMissions.*;
public class GoToIntroduction implements Mission<Agent> {
CherryFrameworkDocs cherryFrameworkDocs = new WebScreenFactory().init(new CherryFrameworkDocs());
@Override
public Agent accomplishAs(Agent agent) {
navigateTo(cherryFrameworkDocs).accomplishAs(agent);
WebElement webElement = locate(cherryFrameworkDocs.toc.introductionLink).accomplishAs(agent);
webElement.click();
return agent;
}
}