@BeforeTest
@Parameters({"selenium.host", "selenium.port", "selenium.browser", "selenium.url" })
public void startServer(String host, String port, String browser, String url) throws Exception {
selenium = new DefaultSelenium(host, Integer.parseInt(port), browser, url);
selenium.start();
}
testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SL-Grid" parallel="false">
<parameter name="username" value="test" />
<parameter name="password" value="test1" />
<test name="SL-Chrome" preserve-order="true">
<parameter name="selenium.host" value="localhost"></parameter>
<parameter name="selenium.port" value="5555"></parameter>
<parameter name="selenium.browser" value="*googlechrome"></parameter>
<parameter name="selenium.url" value="http://properurl:8080/"></parameter>
<classes>
<class name="com.TestBase" /> // Base class where all generic methods, setUp and tearDown methods present
<class name="com.Login"> // Login related methods and inherit TestBase
<methods>
<include name="loginPage" />
<include name="signIn" />
</methods>
</class>
<class name="com.Page1">
<methods>
<include name="clickLinkA" />
<include name="isTextBoxXXXPresent" />
</methods> </class></classes></test>
<test name="SL-Firefox" preserve-order="true">
<parameter name="selenium.host" value="172.16.4.21"></parameter>
<parameter name="selenium.port" value="5556"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.url" value="http://properurl:8080/"></parameter>
<classes>
<class name="com.TestBase" /> // Base class where all generic methods, setUp and tearDown methods present
<class name="com.Login"> // Login related methods and inherit TestBase
<methods>
<include name="loginPage" />
<include name="signIn" />
</methods>
</class>
<class name="com.Page2">
<methods>
<include name="clickLinkB" />
<include name="isListBoxXXXPresent" />
</methods> </class></classes></test>
</suite>
当我运行该套件时,它应该从 TestBase 调用 startServer() -> loginPage() 和从 Login -> clickLinkA() 调用 SignIn() 并从 Page1 调用 isTextBoxXXXPresent()。但很多时候系统首先从 Page1 类调用数学,因此失败(因为没有调用 signIn)。
谁能告诉我我在哪里错了。或任何其他更好的设计方式。或任何保留订单的替代品