提交 57a53f43 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

update test scripts

上级 1913efad
......@@ -6,23 +6,22 @@ pid=0
1. Load web page from url http://xxx
2. Retrieve img element zt-logo.png in html
3. Check img exist >> `.*.png`
3. Check img exist >> `必应`
*/
var http = require('http');
const https = require('https');
http.get('http://max.demo.zentao.net/user-login-Lw==.html', function(req) {
let html = '', image = '';
https.get('https://cn.bing.com', function(req) {
let html = ''
req.on('data', function(data) {
html += data;
});
req.on('end', () => {
var res = html.match(/<img\ssrc="(.*?)"/);
const res = html.match(/<title>(.*?)</);
if (res.length > 1) {
image = res[1]
console.log(image)
console.log(res[1])
}
});
});
......@@ -6,13 +6,13 @@ pid=0
1. Send a request to interface http://xxx
2. Retrieve sessionID field from response json
3. Validate its format >> `^[a-z0-9]{26}`
3. Validate its format >> `^[a-z0-9]{8}`
*/
var http = require('http');
const https = require('https');
http.get('http://max.demo.zentao.net/pms/?mode=getconfig', function(req) {
https.get('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1', function(req) {
let jsonStr = '';
req.on('data', function(data) {
......@@ -21,8 +21,8 @@ http.get('http://max.demo.zentao.net/pms/?mode=getconfig', function(req) {
req.on('end', () => {
if(req.statusCode === 200){
try{
var json = JSON.parse(jsonStr);
console.log(json.sessionID)
const json = JSON.parse(jsonStr);
console.log(json.images[0].startdate)
} catch(err){
console.log('ERR: ' + err);
}
......
......@@ -6,13 +6,13 @@ pid=0
1. Load web page from url http://xxx
2. Retrieve img element zt-logo.png in html
3. Check img exist >> `.*zt-logo.png`
3. Check img exist >> `必应`
=cut
use LWP::Simple; # need LWP::Simple module
$html = get('http://max.demo.zentao.net/user-login-Lw==.html');
$html = get('https://cn.bing.com');
if ( $html =~ /<img src="(.*?)" .*>/ ) {
if ( $html =~ /<title>(.*?)</ ) {
print "$1\n";
}
......@@ -7,13 +7,13 @@ pid=0
1. Send a request to interface http://xxx
2. Retrieve sessionID field from response json
3. Check its format >> `^[a-z0-9]{26}`
3. Check its format >> `^[a-z0-9]{8}`
=cut
use LWP::Simple; # need LWP::Simple module
$json = get('http://max.demo.zentao.net/pms/?mode=getconfig');
$json = get('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
if ( $json =~ /"sessionID":"([^"]*)"/ ) {
if ( $json =~ /"startdate":"([^"]*)"/ ) {
print "$1\n";
}
......@@ -8,10 +8,10 @@ pid=0
1. Load web page from url http://xxx
2. Retrieve img element zt-logo.png in html
3. Check img exist >> `.*zt-logo.png`
3. Check img exist >> `必应`
*/
$resp = file_get_contents('http://max.demo.zentao.net/user-login-Lw==.html');
preg_match_all("/<img src=\"(.*)\" .*>/U", $resp, $matches);
$resp = file_get_contents('https://cn.bing.com');
preg_match_all("/<title>(.*)</U", $resp, $matches);
echo $matches[1][0] . "\n";
......@@ -8,10 +8,10 @@ pid=0
1. Send a request to interface http://xxx
2. Retrieve sessionID field from response json
3. Check its format >> `^[a-z0-9]{26}`
3. Check its format >> `^[a-z0-9]{8}`
*/
$resp = file_get_contents('http://max.demo.zentao.net/pms/?mode=getconfig');
$resp = file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
$json = json_decode($resp);
echo $json->sessionID . "\n";
echo $json->images[0]->startdate . "\n";
......@@ -8,13 +8,13 @@ pid=0
1. Load web page from url http://xxx
2. Retrieve img element zt-logo.png in html
3. Check img exist >> `.*zt-logo.png`
3. Check img exist >> `必应`
'''
import requests
import re
html = requests.get('http://max.demo.zentao.net/user-login-Lw==.html').content #need requests library (pip/pip3 install requests)
elem = re.search(r"<img src=\"(.*?)\" .*>", html.decode("utf-8")).group(1)
html = requests.get('https://cn.bing.com').content #need requests library (pip/pip3 install requests)
elem = re.search(r"<title>(.*?)<", html.decode("utf-8")).group(1)
print(elem)
......@@ -8,13 +8,13 @@ pid=0
1. Send a request to interface http://xxx
2. Retrieve sessionID field from response json
3. Check its format >> `^[a-z0-9]{26}`
3. Check its format >> `^[a-z0-9]{8}`
'''
import requests
import json
jsonStr = requests.get('http://max.demo.zentao.net/pms/?mode=getconfig').content #need requests library (pip/pip3 install requests)
jsonStr = requests.get('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1').content
jsonObj = json.loads(jsonStr)
print(jsonObj['sessionID'])
print(jsonObj['images'][0]['startdate'])
......@@ -7,16 +7,19 @@ pid=0
1. Load web page from url http://xxx
2. Retrieve img element zt-logo.png in html
3. Check img exist >> `.*zt-logo.png`
3. Check img exist >> `必应`
}
package require http
package require tls
set url http://max.demo.zentao.net/user-login-Lw==.html
http::register https 443 tls::socket
set url https://cn.bing.com
set http [::http::geturl $url]
set html [::http::data $http]
regexp -- {<img src="(.*?)" .*>} $html match elem
regexp -- {<title>(.*?)<} $html match elem
puts "$elem"
......@@ -5,20 +5,26 @@ title=check remote interface response
cid=0
pid=0
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]{8}`
}
package require http
package require tls
package require json
set url http://max.demo.zentao.net/pms/?mode=getconfig
http::register https 443 tls::socket
set url https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1
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]"
regexp -- {"startdate":"(.*?)"} $jsonStr match date
puts "$date"
# set jsonObj [json::json2dict $jsonStr]
# set images [dict get $jsonObj images]
# puts [dict get $images startdate]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册