mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 06:51:44 +08:00
change: replace ioutil
This commit is contained in:
@@ -2,7 +2,7 @@ package adb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ var screencapAndroidDevicesCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
filepath := fmt.Sprintf("%s.png", builtin.GenNameWithTimestamp("screencap_%d"))
|
filepath := fmt.Sprintf("%s.png", builtin.GenNameWithTimestamp("screencap_%d"))
|
||||||
if err = ioutil.WriteFile(filepath, res, 0o644); err != nil {
|
if err = os.WriteFile(filepath, res, 0o644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("screencap saved to", filepath)
|
fmt.Println("screencap saved to", filepath)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
package gadb
|
package gadb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -116,6 +116,6 @@ func TestScreenCap(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
t.Log(len(res))
|
t.Log(len(res))
|
||||||
ioutil.WriteFile("/tmp/1.png", res, 0o644)
|
os.WriteFile("/tmp/1.png", res, 0o644)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ package gadb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -244,7 +243,7 @@ func TestDevice_Pull(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userHomeDir, _ := os.UserHomeDir()
|
userHomeDir, _ := os.UserHomeDir()
|
||||||
if err = ioutil.WriteFile(userHomeDir+"/Desktop/hello.txt", buffer.Bytes(), DefaultFileMode); err != nil {
|
if err = os.WriteFile(userHomeDir+"/Desktop/hello.txt", buffer.Bytes(), DefaultFileMode); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package uixt
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -87,7 +87,7 @@ func TestDriver_Screenshot(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log(ioutil.WriteFile("/Users/hero/Desktop/s1.png", screenshot.Bytes(), 0o600))
|
t.Log(os.WriteFile("/Users/hero/Desktop/s1.png", screenshot.Bytes(), 0o600))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDriver_Rotation(t *testing.T) {
|
func TestDriver_Rotation(t *testing.T) {
|
||||||
@@ -346,7 +346,7 @@ func TestDriver_AppLaunch(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log(ioutil.WriteFile("s1.png", raw.Bytes(), 0o600))
|
t.Log(os.WriteFile("s1.png", raw.Bytes(), 0o600))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDriver_IsAppInForeground(t *testing.T) {
|
func TestDriver_IsAppInForeground(t *testing.T) {
|
||||||
@@ -428,3 +428,85 @@ func TestConvertPoints(t *testing.T) {
|
|||||||
jsons, _ := json.Marshal(eps)
|
jsons, _ := json.Marshal(eps)
|
||||||
println(fmt.Sprintf("%v", string(jsons)))
|
println(fmt.Sprintf("%v", string(jsons)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDebugDualFeed(t *testing.T) {
|
||||||
|
device, _ := NewAndroidDevice()
|
||||||
|
driver, err := device.NewDriver()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = driver.Driver.AppTerminate("tv.danmaku.bili")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = driver.Driver.AppLaunch("tv.danmaku.bili")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
|
// 处理弹窗
|
||||||
|
err = driver.ClosePopupsHandler()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 进入推荐页
|
||||||
|
err = driver.TapByOCR("推荐", WithScope(0, 0, 1, 0.3))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重复采集 10 次
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
err = driver.SwipeUp()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
// 点击进入某视频
|
||||||
|
err = driver.TapXY(0.3, 0.5)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
|
// 点击播放区域,展现横屏图标
|
||||||
|
err = driver.TapXY(0.5, 0.1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
|
// 切换横屏
|
||||||
|
err = driver.TapByUIDetection(
|
||||||
|
WithScreenShotUITypes("fullScreen"))
|
||||||
|
if err != nil {
|
||||||
|
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
||||||
|
// 退出回到推荐页
|
||||||
|
driver.Driver.PressBack()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 观播 10s
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
|
// 返回视频页面
|
||||||
|
err = driver.Driver.PressBack()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回推荐页
|
||||||
|
err = driver.Driver.PressBack()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ func Test_remoteWD_GetPasteboard(t *testing.T) {
|
|||||||
// t.Fatal(err)
|
// t.Fatal(err)
|
||||||
// }
|
// }
|
||||||
// userHomeDir, _ := os.UserHomeDir()
|
// userHomeDir, _ := os.UserHomeDir()
|
||||||
// if err = ioutil.WriteFile(userHomeDir+"/Desktop/p1.png", buffer.Bytes(), 0600); err != nil {
|
// if err = os.WriteFile(userHomeDir+"/Desktop/p1.png", buffer.Bytes(), 0600); err != nil {
|
||||||
// t.Error(err)
|
// t.Error(err)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package hrp
|
package hrp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -31,8 +30,8 @@ func removeHashicorpGoPlugin() {
|
|||||||
|
|
||||||
func buildHashicorpPyPlugin() {
|
func buildHashicorpPyPlugin() {
|
||||||
log.Info().Msg("[init] prepare hashicorp python plugin")
|
log.Info().Msg("[init] prepare hashicorp python plugin")
|
||||||
src, _ := ioutil.ReadFile(tmpl("plugin/debugtalk.py"))
|
src, _ := os.ReadFile(tmpl("plugin/debugtalk.py"))
|
||||||
err := ioutil.WriteFile(tmpl("debugtalk.py"), src, 0o644)
|
err := os.WriteFile(tmpl("debugtalk.py"), src, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("copy hashicorp python plugin failed")
|
log.Error().Err(err).Msg("copy hashicorp python plugin failed")
|
||||||
os.Exit(code.GetErrorCode(err))
|
os.Exit(code.GetErrorCode(err))
|
||||||
|
|||||||
Reference in New Issue
Block a user