0

I wrote some JUnit test cases at Winium which is nearly same as Selenium for Calculator. My problem is with every test a new calculator.exe is started but I want to do all the test for the same calculator.exe but I also want to seperate the JUnit test. Below you can see my code:

public class calculatorTest {

    @Test
    public void additionTest() throws MalformedURLException, InterruptedException {


        DesktopOptions option = new DesktopOptions();

        option.setApplicationPath("C:\\Windows\\System32\\calc.exe");

        WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999") , option);

        Thread.sleep(2000);

        driver.findElement(By.name("Seven")).click();
        driver.findElement(By.name("Plus")).click();
        driver.findElement(By.name("Eight")).click();
        driver.findElement(By.name("Equals")).click();
        String output =  driver.findElement(By.id("CalculatorResults")).getAttribute("Name");

        System.out.println("Result is " + output);
        assertEquals("Display is 15", output);

    }

    @Test
    public void subtractionTest() throws MalformedURLException, InterruptedException {


        DesktopOptions option = new DesktopOptions();

        option.setApplicationPath("C:\\Windows\\System32\\calc.exe");

        WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999") , option);

        Thread.sleep(2000);

        driver.findElement(By.name("Nine")).click();
        driver.findElement(By.name("Minus")).click();
        driver.findElement(By.name("Eight")).click();
        driver.findElement(By.name("Equals")).click();
        String output =  driver.findElement(By.id("CalculatorResults")).getAttribute("Name");

        System.out.println("Result is " + output);

    }
erkevarol
  • 57
  • 2
  • 11

1 Answers1

0

You can add a configuration method to your test class, which is a part of JUnit

@BeforeClass
public void openCalculator() {
        DesktopOptions option = new DesktopOptions();

        option.setApplicationPath("C:\\Windows\\System32\\calc.exe");

        WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999") , option);

        Thread.sleep(2000);
}
Aviqz
  • 1
  • 2