繁体   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