提交 2f2f6484 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

update demo scripts

上级 09f18ebe
#!/usr/bin/env ruby #!/usr/bin/env ruby
=begin =begin
[case]
title=check string matches pattern title=check string matches pattern
cid=0 cid=0
pid=0 pid=0
[group] 1. exactly match >> hello
1. exactly match >> hello 2. regular expression match >> `1\d{10}`
2. regular expression match >> `1\d{10}` 3. format string match >> `%s%d`
3. format string match >> `%s%d`
[esac]
=end =end
print(">> hello\n"); print("hello\n");
print(">> 13905120512\n"); print("13905120512\n");
print(">> abc123\n"); print("abc123\n");
\ No newline at end of file
#!/usr/bin/env ruby #!/usr/bin/env ruby
=begin =begin
[case]
title=extract content from webpage title=extract content from webpage
cid=0 cid=0
pid=0 pid=0
[group] 1. Load web page from url http://xxx
1. Load web page from url http://xxx 2. Retrieve img element zt-logo.png in html
2. Retrieve img element zt-logo.png in html 3. Check img exist >> `.*zt-logo.png`
3. Check img exist >> `.*zt-logo.png`
[esac] =end
=enddf
require "open-uri" require "open-uri"
uri = 'http://pms.zentao.net/user-login.html' uri = 'http://max.demo.zentao.net/user-login-Lw==.html'
html = nil html = nil
open(uri) do |http| open(uri) do |http|
html = http.read html = http.read
end end
elem = html.match(/<img src='(.*?)' .*>/).captures elem = html.match(/<img src="(.*?)" .*>/).captures
puts '>> ' + elem[0] puts ""+elem[0]
#!/usr/bin/env ruby #!/usr/bin/env ruby
=begin =begin
[case]
title=check remote interface response title=check remote interface response
cid=0 cid=0
pid=0 pid=0
[group] 1. Send a request to interface http://xxx
1. Send a request to interface http://xxx 2. Retrieve sessionID field from response json
2. Retrieve sessionID field from response json 3. Check its format >> `^[a-z0-9]{26}`
3. Check its format >> `^[a-z0-9]{26}`
[esac]
=end =end
require "open-uri" require "open-uri"
require "json" require "json"
uri = 'http://pms.zentao.net/?mode=getconfig' uri = 'http://max.demo.zentao.net/pms/?mode=getconfig'
html = nil html = nil
open(uri) do |http| open(uri) do |http|
html = http.read html = http.read
end end
json = JSON.parse(html) # need json library (gem install json) json = JSON.parse(html) # need json library (gem install json)
puts '>> ' + json['sessionID'] puts json['sessionID']
\ No newline at end of file
#!/usr/bin/env bash #!/usr/bin/env bash
:<<! :<<!
[case]
title=check string matches pattern title=check string matches pattern
cid=0 cid=0
pid=0 pid=0
[group]
1. exactly match >> hello 1. exactly match >> hello
2. regular expression match >> `1[0-9]{10}` 2. regular expression match >> `1[0-9]{10}`
3. format string match >> `%s%d` 3. format string match >> `%s%d`
[esac]
! !
str="abc123" str="abc123"
echo ">> hello" echo "hello"
echo ">> 13905120512" echo "13905120512"
echo ">> abc123" echo "abc123"
#!/usr/bin/env bash #!/usr/bin/env bash
:<<! :<<!
[case]
title=extract content from webpage title=extract content from webpage
cid=0 cid=0
pid=0 pid=0
[group]
1. Load web page from url http://xxx 1. Load web page from url http://xxx
2. Retrieve img element zt-logo.png in html 2. Retrieve img element zt-logo.png in html
3. Check img exist >> `.*zt-logo.png` 3. Check img exist >> `.*zt-logo.png`
[esac]
! !
resp=$(curl -s http://pms.zentao.net/user-login.html) # apt-get install curl if needed resp=$(curl -s http://max.demo.zentao.net/user-login-Lw==.html) # apt-get install curl if needed
elem=`echo $resp | grep -o "<img[^>]*src='[^']*'" | grep -o "[^']*.png"` elem=`echo $resp | grep -o '<img[^>]*src="[^"]*"'`
echo ">> $elem" echo "$elem"
#!/usr/bin/env bash #!/usr/bin/env bash
:<<! :<<!
[case]
title=check remote interface response title=check remote interface response
cid=0 cid=0
pid=0 pid=0
[group]
1. Send a request to interface http://xxx 1. Send a request to interface http://xxx
2. Retrieve sessionID field from response json 2. Retrieve sessionID field from response json
3. Validate its format >> `^[a-z0-9]{26}` 3. Validate its format >> `^[a-z0-9]{26}`
[esac]
! !
resp=$(curl -s 'http://pms.zentao.net/?mode=getconfig') # apt-get install curl if needed resp=$(curl -s 'http://max.demo.zentao.net/pms/?mode=getconfig') # apt-get install curl if needed
elem=`echo $resp | grep -o '"sessionID":"[^"]*"' | sed 's/^.*:"//g' | sed 's/"//g'` elem=`echo $resp | grep -o '"sessionID":"[^"]*"' | sed 's/^.*:"//g' | sed 's/"//g'`
echo ">> $elem" echo "$elem"
#!/usr/bin/env tclsh #!/usr/bin/env tclsh
set case { set case {
[case]
title=check string matches pattern title=check string matches pattern
cid=0 cid=0
pid=0 pid=0
[group]
1. exactly match >> hello 1. exactly match >> hello
2. regular expression match >> `1\d{10}` 2. regular expression match >> `1\d{10}`
3. format string match >> `%s%d` 3. format string match >> `%s%d`
[esac]
} }
puts ">> hello" puts "hello"
puts ">> 13905120512" puts "13905120512"
puts ">> abc123" puts "abc123"
\ No newline at end of file
#!/usr/bin/env tclsh #!/usr/bin/env tclsh
set case { set case {
[case]
title=extract content from webpage title=extract content from webpage
cid=0 cid=0
pid=0 pid=0
[group] 1. Load web page from url http://xxx
1. Load web page from url http://xxx 2. Retrieve img element zt-logo.png in html
2. Retrieve img element zt-logo.png in html 3. Check img exist >> `.*zt-logo.png`
3. Check img exist >> `.*zt-logo.png`
[esac]
} }
package require http package require http
set url http://pms.zentao.net/user-login.html set url http://max.demo.zentao.net/user-login-Lw==.html
set http [::http::geturl $url] set http [::http::geturl $url]
set html [::http::data $http] set html [::http::data $http]
regexp -- {<img src='(.*?)' .*>} $html match elem regexp -- {<img src="(.*?)" .*>} $html match elem
puts ">> $elem" puts "$elem"
\ No newline at end of file
#!/usr/bin/env tclsh #!/usr/bin/env tclsh
set case { set case {
[case]
title=check remote interface response title=check remote interface response
cid=0 cid=0
pid=0 pid=0
[group] 1. Send a request to interface http://xxx
1. Send a request to interface http://xxx 2. Retrieve sessionID field from response json
2. Retrieve sessionID field from response json
3. Check its format >> `^[a-z0-9]{26}` 3. Check its format >> `^[a-z0-9]{26}`
[esac]
} }
package require http package require http
package require json package require json
set url http://pms.zentao.net/?mode=getconfig set url http://max.demo.zentao.net/pms/?mode=getconfig
set http [::http::geturl $url] set http [::http::geturl $url]
set jsonStr [::http::data $http] set jsonStr [::http::data $http]
# need json library, you may use ActiveTcl # need json library, you may use ActiveTcl
set jsonObj [json::json2dict $jsonStr] set jsonObj [json::json2dict $jsonStr]
puts ">> [dict get $jsonObj sessionID]" puts "[dict get $jsonObj sessionID]"
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册