我试图使用我的单位测试来加载"加载"在我们的浏览器上测试由于各种原因,我们在浏览器端看到性能下降,因为我们严重依赖于打印对话框。
我通过ScalaTest进行了以下单元测试:
import re
r = re.compile(r"\s*PATH\s*=\s*(.+)")
with open('/root/TestConnect', "rt") as f:
for line in f.readlines():
m = r.match(line)
if m is not None:
print m.group(1)
然而,当我尝试使用foreach迭代元素列表并传入memberHelper时,在大约5个元素的列表之后,我得到以下堆栈跟踪:
class LoadPrePaidSpec extends FlatSpec with Matchers with Chrome with Eventually {
implicit override val patienceConfig =
PatienceConfig(timeout = scaled(Span(40, Seconds)), interval = scaled(Span(100, Millis)))
def build(csvLine:String):TestCSVHolder ={
val split = csvLine.split(",")
TestCSVHolder(memberId = split(0), preSaleCode = split(1),
prePaidCode = split(2), lastName = split(3), firstName = split(4), badgeName = split(5))
}
def memberHelper(member: TestCSVHolder): Unit = {
//insert member id via prepaid code
textField("member_id").value = member.prePaidCode
//fire keyup event
executeScript("var eventToFire=jQuery.Event(\"keyup\");eventToFire.keyCode=221;eventToFire.which=221;" +
"$(\"#member_id\").trigger(eventToFire)")
eventually {
val eles = webDriver.findElements(By.xpath(s"//*[contains(@id, '${member.memberId}')]"))
eles.get(0).getTagName
//We remove the head element because it just says Prep For Print
val tdEles = (eles.get(0).findElements(By.tagName("td")).toList.tail)
tdEles(0).getText() should be(member.lastName)
tdEles(1).getText() should be(member.firstName)
tdEles(2).getText() should be(member.badgeName)
}
}
"Scanning an ID" should "look up the member" in {
val member = new TestCSVHolder("100001", "ABCD", "[-100001-ABCD]", "John", "Doe", "JohnDoe")
go to (url)
//login
textField("user_name").value = "mrkaiser"
webDriver.findElementById("credentials").sendKeys("somepassword")
click on ("btnLogin")
//click to pre-paid
click on linkText("Pre-Paid")
memberHelper())
webDriver.quit()
}
}
我的最终目标是从文件中对20K范围内的元素进行实际测试,但直到我能得到一个像这样的小列表工作,我才能成为一条小溪。
我使用的是chromedriver,我使用的是Scala 2.11.6,scala test 2.2.0,selenium 2.35.0。