mercredi 15 mai 2019

How to do JUnit test from only one GUI?

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);

    }

Aucun commentaire:

Enregistrer un commentaire