[英]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. 我在Winium上写了一些JUnit测试用例,它与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.
我的问题是每个测试都启动了一个新的calculator.exe,但我想对同一个calculator.exe进行所有测试,但我也想分开JUnit测试。 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);
}
You can add a configuration method to your test class, which is a part of JUnit 您可以将配置方法添加到测试类中,该测试类是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.