Как сделать тест JUnit только с одним графическим интерфейсом? - PullRequest
0 голосов
/ 15 мая 2019

Я написал несколько тестовых примеров JUnit в Winium, которые почти совпадают с Selenium for Calculator.Моя проблема заключается в том, что при каждом тесте запускается новый calculator.exe, но я хочу выполнить все тесты для того же calculator.exe, но я также хочу разделить тест JUnit.Ниже вы можете увидеть мой код:

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

    }

1 Ответ

0 голосов
/ 15 мая 2019

Вы можете добавить метод конфигурации в свой тестовый класс, который является частью 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);
}
...