You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

html_helper.go 875 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "bytes"
  7. "testing"
  8. "github.com/PuerkitoBio/goquery"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. type HtmlDoc struct {
  12. doc *goquery.Document
  13. }
  14. func NewHtmlParser(t testing.TB, content []byte) *HtmlDoc {
  15. doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
  16. assert.NoError(t, err)
  17. return &HtmlDoc{doc: doc}
  18. }
  19. func (doc *HtmlDoc) GetInputValueById(id string) string {
  20. text, _ := doc.doc.Find("#" + id).Attr("value")
  21. return text
  22. }
  23. func (doc *HtmlDoc) GetInputValueByName(name string) string {
  24. text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
  25. return text
  26. }
  27. func (doc *HtmlDoc) GetCSRF() string {
  28. return doc.GetInputValueByName("_csrf")
  29. }