我有五个文件如下所述:
package require tcltest
namespace import ::tcltest::*
if {$argc!=0} {
foreach {flag param} $::argv {
if {[string match -* $flag]} {
configure $flag $param
}\
else {
$flag $param
}
}
}
runAllTests
package require tcltest
namespace import ::tcltest::*
source add.tcl
test add1 {} -body {
add 1 1
} -result 2
cleanupTests
proc add {a b} {
return [expr $a+$b]
}
package require tcltest
namespace import ::tcltest::*
source sample.tcl
test google_search {} -body {
search
} -result 1
cleanupTests
package require selenium::chrome
proc search {} {
set driver [::selenium::ChromeDriver new]
$driver get "https://google.com"
set query [$driver find_element_by_name "q"]
$driver send_keys $query "selenium and Tcl"
$driver send_keys $query $selenium::Key(RETURN)
after 5000
$driver close
return 1
}
现在,如果我尝试通过从终端运行命令add.test
来执行测试文件tclsh run_tests.tcl -file add.test
,它会生成以下输出:
Tests running in interp: /usr/bin/tclsh
Tests located in: /home/snehasish/tcl_test/tests
Tests running in: /home/snehasish/tcl_test/tests
Temporary files stored in /home/snehasish/tcl_test/tests
Test files run in separate interpreters
Running tests that match: *
Skipping test files that match: l.*.test
Only running test files that match: add.test
Tests began at Thu Jul 20 12:49:22 UTC 2017
add.test
Tests ended at Thu Jul 20 12:49:22 UTC 2017
run_tests.tcl: Total 1 Passed 1 Skipped 0 Failed 0
Sourced 1 Test Files.
这是完全正常的,应该是它。
然而,如果我尝试以类似的方式执行测试文件sample.test
,则测试不会结束:
$ tclsh run_tests.tcl -file sample.test
Tests running in interp: /usr/bin/tclsh
Tests located in: /home/snehasish/tcl_test/tests
Tests running in: /home/snehasish/tcl_test/tests
Temporary files stored in /home/snehasish/tcl_test/tests
Test files run in separate interpreters
Running tests that match: *
Skipping test files that match: l.*.test
Only running test files that match: sample.test
Tests began at Thu Jul 20 12:27:38 UTC 2017
sample.test
Starting ChromeDriver 2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57) on port 42433
Only local connections are allowed.
它就在那里停下来,仿佛在等待一些事情发生。浏览器关闭,表明网络驱动程序确实已关闭。
有趣的是,当我直接运行sample.test
时,它会提供预期的输出并正常结束:
$ tclsh sample.test
Starting ChromeDriver 2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57) on port 37381
Only local connections are allowed.
sample.test: Total 1 Passed 1 Skipped 0 Failed 0
我正在使用的Selenium Web驱动程序实现包here。
有人可以澄清为什么tcltest
在组合使用runAllTests
和网络驱动程序脚本时没有按预期工作?这将非常有帮助。提前谢谢。
PS:很抱歉,由于包含了大量文件的内容,问题变得太长了,但我认为这是我在解释时更加清晰的方式我的问题。