testing - Selenium 多次运行相同的方法

标签 testing selenium automated-tests selenium-rc

几周前我开始使用 Selenium 。我是这样设计我的测试的

  1. 我正在使用@BeforeClass 创建一个对象并调用一个打开浏览器并执行登录操作的类方法。
  2. 我有另一种方法,它具有我要执行的测试操作的 Selenium 代码,在我的例子中是边界值分析
  3. 现在我已经创建了一个 @Test 方法,它调用之前的方法并将测试所需的值传递给它

我面临的问题是 1. 启动浏览器并开始登录操作,此后浏览器再次尝试打开主页。 2. 我想知道这是否是编写 selenium 测试脚本的正确方法

另外,如果我删除第 1 步并在第 2 步中包含登录方法,我的测试运行正常 我在 grails 上的 groovy 上使用 selenium-rc 和 STS

一个类中的代码

void candidatelogin() {
        selenium.open("/jeepnee/")
        selenium.click("link=Login")
        selenium.type("id=username", "csv_candidate4@trashmail.net")
        selenium.type("id=j_password", "kanishka1")
        selenium.click("id=submit")
        selenium.waitForPageToLoad("60000")
    }

我从下面的代码调用上面的部分

class CandidateEditProfileInfoFunctionalTests extends GroovyTestCase{

public String addressone="nejshdgfbvxczaqwer1y2io3lkjh7dg*lakiqwerjshag"
    @BeforeClass
    static void setUp() {
        GeneralTests candidate= new GeneralTests()
        candidate.candidatelogin()
    }


void EditProfileInfoFail(String streeta, String streetb, String city, String state, String zip, String mobilecountry, String mobilearea, String mobilephone, String landlinecountry, String landlinearea, String landlinenumber) {
        selenium.waitForPageToLoad("60000")
        selenium.click("link=My Profile")
        selenium.waitForPageToLoad("80000")
        selenium.click("id=editProfile")
        selenium.waitForPageToLoad("80000")
        selenium.type("id=street1", streeta)
        selenium.type("id=street2", streetb)
        selenium.type("id=city", city)
        selenium.type("id=state", state)
        selenium.type("id=zip", zip)
        selenium.select("id=country", "label=Philippines")
        selenium.type("id=mobileCountryCode", mobilecountry)
        selenium.type("id=mobileAreaCode", mobilearea)
        selenium.type("id=mobilePhoneNumber", mobilephone)
        selenium.type("id=landlineCountryCode", landlinecountry)
        selenium.type("id=landlineAreaCode", landlinearea)
        selenium.type("id=landlinePhoneNumber", landlinenumber)
        selenium.click("id=submit")
        selenium.waitForPageToLoad("80000")
        assertTrue(selenium.isTextPresent("Please complete the required fields"))
        assertEquals("Candidate Creation - Step 2", selenium.getTitle())
    }
    @Test
    void homeCountryOnFailureShowsErrorMessage(){
        EditProfileInfoFail(addressone, "aaa", "bangalote", "karnataka", "1234", "11", "222", "12345", "11", "22", "5432")

    }
}

最佳答案

@BeforeClass 方法中是否有重复的逻辑?该方法运行一次以设置所有测试方法所需的任何依赖项。听起来此方法中的逻辑在步骤 2 中有些重复。似乎可以删除步骤 2 中打开主页的代码,因为它发生在您的 @BeforeClass 方法内部。如果您的后续测试需要返回到主页,最好更改为 @Before 注释,然后它将在每次测试运行之前运行该代码。

关于testing - Selenium 多次运行相同的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10383847/

相关文章:

安卓测试。使用 Espresso 的一系列点击

java - Selenium - 如何在页面中以多种形式查找相同的元素

selenium - 获取 Selenium 中的下一个元素

unit-testing - 自动化测试 : Tool for Visualizing and archiving test results

c# - Application.ExecutablePath 是否会根据测试运行程序返回不同的值?

testing - 通用(非特定于服务器的)HTTP 服务器测试套件?

php - 单元测试 Controller Phalcon

c++ - Git 将更新的 master merge 到一个分支

在 Haskell 中测试执行 IO 的函数

haskell - 使用 Haskell webdriver 包查找网页上的所有文本输入