0
@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)。

谁能告诉我我在哪里错了。或任何其他更好的设计方式。或任何保留订单的替代品

4

2 回答 2

0

Consider using dependsOnMethods to make sure that one test that depends on another runs after it. You can also set a numeric priority, where the lower numbers run first. The default for priority is 0, so you would only need to set this for tests to run after those that do not have a priority set.

于 2012-03-15T18:20:29.170 回答
0

我认为这可能是 TestNG 中的问题,您可以向 TestNg 人员报告。但是要解决您的问题,您可以在 BeforeTest 中包含您的登录和登录方法,或者在这种情况下在您的测试方法中调用它 clickLinkA。希望这可以解决您的问题。

于 2011-08-09T07:10:38.620 回答