/
rise.go
37 lines (30 loc) · 1016 Bytes
/
rise.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package fenix
import (
"fmt"
"time"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/proto"
"github.com/go-rod/rod/lib/utils"
)
func (f *Fenix) TakeScreenShot(pageURL, testName string, w, h float64) {
page := rod.New().MustConnect().MustIgnoreCertErrors(true).MustPage(pageURL).MustWaitLoad()
img, _ := page.Screenshot(true, &proto.PageCaptureScreenshot{
Format: proto.PageCaptureScreenshotFormatPng,
Clip: &proto.PageViewport{
X: 0,
Y: 0,
Width: w,
Height: h,
Scale: 1,
},
FromSurface: true,
})
fileName := time.Now().Format("2006-01-02-15-04-05.000000")
_ = utils.OutputFile(fmt.Sprintf("%s/screenshots/%s-%s.png", f.RootPath, testName, fileName), img)
}
func (f *Fenix) FetchPage(pageURL string) *rod.Page {
return rod.New().MustConnect().MustIgnoreCertErrors(true).MustPage(pageURL).MustWaitLoad()
}
func (f *Fenix) SelectElementByID(page *rod.Page, id string) *rod.Element {
return page.MustElementByJS(fmt.Sprintf("document.getElementById('%s')", id))
}