package gui.api.test.demo; import static org.junit.Assert.assertEquals; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import com.maveryx.bootstrap.Bootstrap; import com.maveryx.core.guiApi.GuiBrowser; import com.maveryx.core.guiApi.GuiButton; import com.maveryx.core.guiApi.GuiText; @RunWith(com.maveryx.test.junit.MaveryxTestRunner.class) public class CalculatorTestMaveryx { private static String chromeLauncher = "C:\\eclipse\\workspace\\API_Test_Suite_Web\\AUT\\Chrome.xml"; //The URL of the calculator to be opened in the browser private static String calculatorUrl = "https://specflowoss.github.io/Calculator-Demo/Calculator.html"; //The Selenium web driver to automate the browser private static GuiBrowser browser = new GuiBrowser(); //Test objects GuiText firstNumber = new GuiText("First Number"); GuiText secondNumber = new GuiText("Second Number"); GuiText result = new GuiText("result"); GuiButton add = new GuiButton("Add"); GuiButton reset = new GuiButton("Reset"); @BeforeClass public static void setUpBeforeClass() throws Exception { //Sets the ChromeDriver path Bootstrap.startApplication(chromeLauncher); //Open the calculator page in the browser browser.navigateTo(calculatorUrl); } @AfterClass public static void tearDownAfterClass() throws Exception { // Disposes the Selenium web driver (closing the browser) after the test class completed Bootstrap.stop(); } @Before public void setUp() throws Exception { //Click the reset button reset.click(); } @After public void tearDown() throws Exception { } public void enterFirstNumber(int number) { //Clear text box & Enter text firstNumber.setText(Integer.toString(number)); //Check if the text was entered assertEquals(Integer.toString(number), firstNumber.getText()); } public void enterSecondNumber(int number) { //Clear text box & Enter text secondNumber.setText(Integer.toString(number)); //Check if the text was entered assertEquals(Integer.toString(number), secondNumber.getText()); } public void clickAdd() { //Click the add button add.click(); } /** * The general procedure * @param firstNumber first addendum * @param secondNumber second addendum */ public void sumTestProcedure(int firstNumber, int secondNumber) { //Enter the first addendum enterFirstNumber(firstNumber); //Enter the first addendum enterSecondNumber(secondNumber); //Click the add button clickAdd(); //Check for the result assertEquals(Integer.toString(firstNumber + secondNumber), result.getText()); } /** * This tests sums two negative numbers */ @Test public void testNegativeNumbers() { sumTestProcedure(-1, -1); } /** * This tests sums two positive numbers */ @Test public void testPositiveNumbers() { sumTestProcedure(2, 2); } /** * This tests sums one negative and one positive numbers */ @Test public void testPositiveNegativeNumbers() { sumTestProcedure(-2, 3); } }