Documentation of Cherry Framework
Perform Java Swing App (FEST) Missions
'Let's have a cherry fest...', said the Agent.
Now that we are familiar with the concepts of Screens and ScreenElements and we've already seen examples of them used in the cherry-webdriver
module, let's see how these very concepts can also be applied in Java Swing applications using the cherry-fest
module.
If you use the cherry-fest
module your Screens could look like that:
import io.magentys.fest.locators.FindBy;
import io.magentys.fest.screens.SwingScreen;
import io.magentys.fest.screens.SwingScreenElement;
import io.magentys.fest.screens.SwingScreenFactory;
import io.magentys.screens.annotations.Alias;
import javax.swing.*;
public class LoginScreen extends SwingScreen {
@Alias("Username Field")
@FindBy(clazz = JTextField.class, attributes = "name=Username,visible=true", rememberAs = "username.field")
public SwingScreenElement usernameInput;
@Alias("Password Field")
@FindBy(clazz = JTextField.class, attributes = "name=Password", rememberAs = "password.field")
public SwingScreenElement passwordInput;
@Alias("Submit login button")
@FindBy(clazz = JButton.class, attributes = "name=submit")
public SwingScreenElement submitButton;
/*
more elements go here
*/
}
Then you can use the these screens as follows:
LoginScreen loginScreen = new SwingScreenFactory().init(new LoginScreen());
Agent swingAppUser = agent().obtains(SwingAppDriver.class);
swingAppUser.performs(
fillIn(loginScreen.usernameInput, "myusername"),
fillIn(loginScreen.passwordInput, "password123"),
clickOnButton(loginScreen.submitButton)
);
Readable, isn't it? The above can be wrapped up into a Login Mission
import io.magentys.Agent;
import io.magentys.Mission;
import io.magentys.fest.screens.SwingScreenFactory;
public class Login implements Mission<Agent> {
private final String username;
private final String password;
private final LoginScreen loginScreen = new SwingScreenFactory().init(new LoginScreen());
public Login(String username, String password) {
this.username = username;
this.password = password;
}
public static Login login(String username, String password){
new Login(username,password);
}
@Override
public Agent accomplishAs(Agent agent) {
agent.performs(
fillIn(loginScreen.usernameInput, username),
fillIn(loginScreen.passwordInput, password),
clickOnbutton(loginScreen.submitButton)
);
return agent;
}
}