【问题标题】:Please let me know whether my java code is right or not?请让我知道我的java代码是否正确?
【发布时间】:2011-03-14 06:55:50
【问题描述】:

当我运行 java 代码时,出现以下错误.. 下面我给出了我的 Java 代码...如果我出错了请纠正我...

junit.framework.AssertionFailedError: No tests found in pass
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.TestSuite$1.runTest(TestSuite.java:90)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

import com.thoughtworks.selenium.*;
public class pass extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("https://secure02.monilink.co.uk/", "*chrome");
    }
    public pass() throws Exception {
/******** Below I am using my test environment URL **************/
        selenium.open("http:www.xxxxxxxxxxxxxx.com")
        selenium.type("username", "RSRK1");
        selenium.type("password", "");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.type("username", "S10");
        selenium.type("password", "56454");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Payments");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Pay Credit Card");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Select Card");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=exact:DEF Credit Card ************2016 Due Date: 19/09/10");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Select Account");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Current Account Created for Testing Purpose 11111111114 Balance: INR 6000.00");
        selenium.waitForPageToLoad("30000");
        selenium.type("amount", "20.00");
        selenium.type("transferDate", "190211");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Confirm");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Main menu");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Payments");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=View and Pay Bills");
        selenium.waitForPageToLoad("30000");
        selenium.click("_Select+bill1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=B.S.N.L, PUNJAB INR 135.00 due by 27/09/10");
        selenium.waitForPageToLoad("30000");
        selenium.click("_Select+account+or+card2_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Testing Account 11111111120 Balance: INR 1358.32");
        selenium.waitForPageToLoad("30000");
        selenium.type("paymentDateString", "190211");
        selenium.click("_Continue3_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Edit");
        selenium.waitForPageToLoad("30000");
        selenium.type("paymentDateString", "200211");
        selenium.click("_Continue3_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Confirm");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Main menu");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Logout");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Yes");
        selenium.waitForPageToLoad("30000");
    }
}

谢谢

【问题讨论】:

    标签: java junit selenium selenium-rc


    【解决方案1】:

    pass() 方法更改为testSomething() 之类的方法。如果要运行 JUnit,则需要在方法名称前加上 test。或者你可以用@Test注释你的测试方法。

    例如:

    import com.thoughtworks.selenium.*;
    
    public class pass extends SeleneseTestCase {
        public void setUp() throws Exception {
            setUp("https://secure02.monilink.co.uk/", "*chrome");
        }
    
        public testMePlease() throws Exception {
    
        }
    }
    

    【讨论】:

    • 你要说下面我需要更改...请让我知道一点,我是 java 新手,selenium public pass() throws Exception { selenium.open("http:www .xxxxxxxxxxxxxx.com")
    • 此外,传统的 Java 类是NamedLikeThis(“驼峰式”,第一个字母大写)。
    【解决方案2】:

    JUnit 抱怨,因为它找不到任何测试。您所有的测试代码都在您的构造函数中。创建一个带有@Test 属性的void 方法。把你的硒步骤放进去。然后 JUnit 会找到它并将其作为测试运行。

    【讨论】:

    • public pass() throws Exception { /******** 下面我使用的是我的测试环境 URL **************/selenium.open ("http:www.xxxxxxxxxxxxxx.com")
    • 你说上面我需要改变......请让我知道一点,我是java和selenium的新手......
    【解决方案3】:

    用这个替换你的代码:

        import com.thoughtworks.selenium.*;
    public class pass extends SeleneseTestCase {
        public void setUp() throws Exception {
            setUp("https://secure02.monilink.co.uk/", "*chrome");
        }
        public testPass() throws Exception {
    /******** Below I am using my test environment URL **************/
            selenium.open("http:www.xxxxxxxxxxxxxx.com")
            selenium.type("username", "RSRK1");
            selenium.type("password", "");
            selenium.click("_Continue1_button");
            selenium.waitForPageToLoad("30000");
            selenium.type("username", "S10");
            selenium.type("password", "56454");
            selenium.click("_Continue1_button");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Payments");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Pay Credit Card");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Select Card");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=exact:DEF Credit Card ************2016 Due Date: 19/09/10");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Select Account");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Current Account Created for Testing Purpose 11111111114 Balance: INR 6000.00");
            selenium.waitForPageToLoad("30000");
            selenium.type("amount", "20.00");
            selenium.type("transferDate", "190211");
            selenium.click("_Continue1_button");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Confirm");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Main menu");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Payments");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=View and Pay Bills");
            selenium.waitForPageToLoad("30000");
            selenium.click("_Select+bill1_button");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=B.S.N.L, PUNJAB INR 135.00 due by 27/09/10");
            selenium.waitForPageToLoad("30000");
            selenium.click("_Select+account+or+card2_button");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Testing Account 11111111120 Balance: INR 1358.32");
            selenium.waitForPageToLoad("30000");
            selenium.type("paymentDateString", "190211");
            selenium.click("_Continue3_button");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Edit");
            selenium.waitForPageToLoad("30000");
            selenium.type("paymentDateString", "200211");
            selenium.click("_Continue3_button");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Confirm");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Main menu");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Logout");
            selenium.waitForPageToLoad("30000");
            selenium.click("link=Yes");
            selenium.waitForPageToLoad("30000");
        }
    }
    

    【讨论】:

    • 运行脚本 java.lang.RuntimeException 时出现以下错误:无法启动 Selenium 会话:无法启动新的浏览器会话:无法删除文件 C:\DOCUME~1\SN2002 ~1.CAM\LOCALS~1\Temp\customProfileDird955037e3a5843a8a6b701c01f1ac5bb\parent.lock at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:89) at com.example.tests.flight.setUp(flight.java:11)在 junit.framework.TestCase.runBare(TestCase.java:132) 在 com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212) 在 junit.framework.TestResult$1.protect(TestResult.java:110)跨度>
    • 你能看看上面的错误....为什么会出现?任何人请澄清我..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多