blob: 6339b2da948ee5306e88d48ba5001df44c9c8665 (
plain)
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
|
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package integrations
import (
"bytes"
"testing"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)
type HtmlDoc struct {
doc *goquery.Document
}
func NewHtmlParser(t testing.TB, content []byte) *HtmlDoc {
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
assert.NoError(t, err)
return &HtmlDoc{doc: doc}
}
func (doc *HtmlDoc) GetInputValueById(id string) string {
text, _ := doc.doc.Find("#" + id).Attr("value")
return text
}
func (doc *HtmlDoc) GetInputValueByName(name string) string {
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
return text
}
func (doc *HtmlDoc) GetCSRF() string {
return doc.GetInputValueByName("_csrf")
}
|