簡體   English   中英

如何只從一個GUI進行JUnit測試?

[英]How to do JUnit test from only one GUI?

我在Winium上寫了一些JUnit測試用例,它與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);

    }

您可以將配置方法添加到測試類中,該測試類是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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM