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

update demo scripts

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