【问题标题】:The method verifyTrue(boolean) is undefined for type方法 verifyTrue(boolean) 未定义类型
【发布时间】:2011-09-20 15:44:04
【问题描述】:

章节,

这里是新手,所以请温柔!

我有一门课,我首先尝试确定“如果”文本 页面上任何地方都存在“虚构的测试公司”,然后我想 单击并删除该公司“其他”我想添加一个新测试 公司..

我遇到的问题是以下行:

            if(verifyTrue(selenium.isTextPresent("Fictitious Test Company"))){;

编译器不断抱怨“verifyTrue(boolean) 方法是 未定义类型 Delete_old_Or_Add_New_Company' */

你能告诉我哪里出错了吗?请具体说明我需要做什么来纠正问题。

这是我班级的全部代码: - 我正在使用 xml 在 Eclipse 中运行我的测试套件

package Realtime;
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;

public class Delete_old_Or_Add_New_Company {

        private Selenium selenium;
        public static SeleneseTestBase SV = new
                        SeleneseTestBase();

        @BeforeClass

        @Parameters ({"url","browser","speed"})
        public void startSelenium(String Site_URL, String Browser, String
Speed) {
        selenium = new DefaultSelenium("localhost", 4444, Browser, Site_URL);
        selenium.start();
        selenium.setSpeed(Speed);
        }
        @AfterClass(alwaysRun=true)
                public void stopSelenium() {
                this.selenium.stop();
                }

        @Test
        public void DeletOldOrAddNewCompany() throws Exception {
                Login_Logout NewObject=new Login_Logout();

selenium.getEval("selenium.browserbot.setShouldHighlightElement(true)");

                NewObject.Login(selenium);
                selenium.waitForPageToLoad("5000");

                selenium.click("//table[@id='maincontent']/tbody/tr/td[3]/table[2]/
 tbody/tr[3]/td[5]/strong");
                selenium.waitForPageToLoad("5000");
                selenium.click("link=Companies");
                selenium.waitForPageToLoad("5000");
                selenium.click("//input[@value='Search for Companies']");
                selenium.waitForPageToLoad("5000");
                selenium.type("//input[@name=\"companyname\"]", "Fictitious Test
Company");
                selenium.click("//input[@name=\"submitbutton\"]");

                if(verifyTrue(selenium.isTextPresent("Fictitious Test Company"))){; /
* It is at this line the compiler complains that the  'The method
verifyTrue(boolean) is undefined for the type
Delete_old_Or_Add_New_Company' */
                selenium.waitForPageToLoad("5000");
                selenium.click("css=td.tablelastrownew");
                selenium.waitForPageToLoad("5000");
                selenium.click("//input[@value='Delete Company']");
                assertTrue(selenium.getConfirmation().matches("^Note: This action
will delete all the companies accounts, branches, users and their
accounts\n\nAre you sure you wish to delete this company[\\s\\S]$"));

                }

                else {

                        selenium.click("//input[@value='Companies Admin Home']");
                        selenium.waitForPageToLoad("5000");
                        selenium.click("//input[@value='New Company']");
                        selenium.waitForPageToLoad("5000");
                        selenium.type("name=companyname", "Fictitious Test Company");
                        selenium.type("name=postcode", "SW17 8DY");
                        selenium.type("name=expirepasswordsindays", "1000");
                        selenium.click("css=input[name=\"submitbutton\"]");
                        selenium.waitForPageToLoad("5000");
                        SV.verifyTrue(selenium.isTextPresent("Fictitious Test Company"));

                }

                NewObject.Logout(selenium);

        } 

【问题讨论】:

  • 也许我只是疯了,但是为什么开头的花括号后面有一个分号?
  • 欢迎您!尽管非常欢迎您在这里发帖,但我一直在将我们的 QA 人员(也在学习 selenium)转发到 sqa.stackexchange.com——但是 Selenium 是如此基于编程,我认为它在任何一个地方都有效..跨度>
  • 考虑到他遇到的错误,我认为分号是他在将其格式化以发布到此处时发生的剪切和粘贴事故。
  • @Bill 感谢您的帮助!正如你所建议的,我已经省略了“verifyTrue”部分,错误似乎已经消失了。然而,在运行时,即使页面上存在文本“Fictitious Test company”,if 语句之后的部分也不会执行,而是直接进入 Else部分代码。你能解释一下为什么会这样吗?顺便说一句 - 感谢您将我指向 sqa.stackexchange.com。 :)

标签: java testing selenium testng


【解决方案1】:

编译器是正确的。 verifyTrue 方法在您的课程中确实不存在。您的类应该扩展 SeleneseTestCase,该方法在其中定义。

【讨论】:

    【解决方案2】:

    Java 告诉您 verifyTrue 是独立存在的,它不返回值,因此不需要围绕它的 if 语句。

    如果参数为假,测试将失败,测试将停在那里。

    我认为在这种情况下你想要的是省略“verifyTrue”部分,只将其中的内容传递给 if。

    【讨论】:

    • 这不是错误消息所说的。不过,这可能是在解决当前错误后会发生的错误。
    • @Rob 好点,Delete_old_Or_Add_New_Company 让我失望了——我只是认为这是一种内省的诡计,但当你仔细想想时,很明显你是对的——我会留下这个答案虽然因为你是对的,他也会遇到它。
    【解决方案3】:

    您已经创建了 SeleneseTestBase 实例“SV”。

    您应该调用“SV.verifyTrue”。或者,扩展 SeleneseTestBase。

    *你已经用过这种方式了。(else语句最后一行。)

    SV.verifyTrue(selenium.isTextPresent("Fictitious Test Company")); 
    

    *在 Selenium 2.0 中,SeleneseTestCase 是不推荐使用的类。 http://selenium.googlecode.com/svn/trunk/docs/api/java/com/thoughtworks/selenium/package-summary.html

    【讨论】:

      猜你喜欢
      • 2012-08-07
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      相关资源
      最近更新 更多