change: replace ioutil

This commit is contained in:
lilong.129
2024-01-16 21:53:01 +08:00
parent 6c49ce7e3c
commit dce414e892
6 changed files with 93 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ package adb
import (
"fmt"
"io/ioutil"
"os"
"strings"
"time"
@@ -36,7 +36,7 @@ var screencapAndroidDevicesCmd = &cobra.Command{
}
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
}
fmt.Println("screencap saved to", filepath)

View File

@@ -3,7 +3,7 @@
package gadb
import (
"io/ioutil"
"os"
"testing"
)
@@ -116,6 +116,6 @@ func TestScreenCap(t *testing.T) {
t.Error(err)
}
t.Log(len(res))
ioutil.WriteFile("/tmp/1.png", res, 0o644)
os.WriteFile("/tmp/1.png", res, 0o644)
}
}

View File

@@ -4,7 +4,6 @@ package gadb
import (
"bytes"
"io/ioutil"
"os"
"reflect"
"strings"
@@ -244,7 +243,7 @@ func TestDevice_Pull(t *testing.T) {
}
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)
}
}

View File

@@ -5,7 +5,7 @@ package uixt
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
)
@@ -87,7 +87,7 @@ func TestDriver_Screenshot(t *testing.T) {
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) {
@@ -346,7 +346,7 @@ func TestDriver_AppLaunch(t *testing.T) {
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) {
@@ -428,3 +428,85 @@ func TestConvertPoints(t *testing.T) {
jsons, _ := json.Marshal(eps)
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)
}
}

View File

@@ -298,7 +298,7 @@ func Test_remoteWD_GetPasteboard(t *testing.T) {
// t.Fatal(err)
// }
// 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)
// }
}

View File

@@ -1,7 +1,6 @@
package hrp
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -31,8 +30,8 @@ func removeHashicorpGoPlugin() {
func buildHashicorpPyPlugin() {
log.Info().Msg("[init] prepare hashicorp python plugin")
src, _ := ioutil.ReadFile(tmpl("plugin/debugtalk.py"))
err := ioutil.WriteFile(tmpl("debugtalk.py"), src, 0o644)
src, _ := os.ReadFile(tmpl("plugin/debugtalk.py"))
err := os.WriteFile(tmpl("debugtalk.py"), src, 0o644)
if err != nil {
log.Error().Err(err).Msg("copy hashicorp python plugin failed")
os.Exit(code.GetErrorCode(err))