mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
fix: replace with session ID
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2503051147
|
v5.0.0+2503051452
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func TestDriverExt_Seek(t *testing.T) {
|
|||||||
err := driver.Swipe(0.5, 0.8, 0.5, 0.2)
|
err := driver.Swipe(0.5, 0.8, 0.5, 0.2)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
err = driver.Drag(20, y, float64(width)*0.75, y)
|
err = driver.Swipe(20, y, float64(width)*0.6, y)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,15 +38,11 @@ type DriverRequests struct {
|
|||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
emptySessionID = "<SessionNotInit>"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewDriverSession() *DriverSession {
|
func NewDriverSession() *DriverSession {
|
||||||
timeout := 30 * time.Second
|
timeout := 30 * time.Second
|
||||||
session := &DriverSession{
|
session := &DriverSession{
|
||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
ID: emptySessionID,
|
ID: "",
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
client: &http.Client{
|
client: &http.Client{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
@@ -101,8 +97,11 @@ func (s *DriverSession) concatURL(urlStr string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace with session ID
|
// replace with session ID
|
||||||
if s.ID != emptySessionID {
|
if s.ID != "" && !strings.Contains(urlStr, s.ID) {
|
||||||
urlStr = strings.Replace(urlStr, emptySessionID, s.ID, 1)
|
sessionPattern := regexp.MustCompile(`/session/([^/]+)/`)
|
||||||
|
if matches := sessionPattern.FindStringSubmatch(urlStr); len(matches) != 0 {
|
||||||
|
urlStr = strings.Replace(urlStr, matches[1], s.ID, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理完整 URL
|
// 处理完整 URL
|
||||||
|
|||||||
Reference in New Issue
Block a user