Go library for parsing and submitting HTML forms

gosubmit

Build Status

Description

Docs are available here: https://godoc.org/github.com/jeremija/gosubmit

Helps filling out plain html forms during testing. Will automatically take the existing values from the form so there is no need to manually set things like csrf tokens. Alerts about missing required fields, or when pattern validation does not match. See example_test.go for a full example.

package gosubmit_test

import (
	// TODO import app
	. "github.com/jeremija/gosubmit"

	"net/http"
	"net/http/httptest"
)

func TestLogin(t *testing.T) {
	w := httptest.NewRecorder()
	r := httptest.NewRequest("GET", "/auth/login", nil)

	app.ServeHTTP(w, r)

	r, err := ParseResponse(w.Result(), r.URL).FirstForm().NewTestRequest(
		Set("username", "user"),
		Set("password", "password"),
	)

	if err != nil {
		t.Fatalf("Error filling form: %s", err)
	}

	w := httptest.NewRecorder()
	app.ServeHTTP(w, r)

	if code := w.Result().StatusCode; code != http.StatusOK {
		t.Errorf("Expected status ok but got %d", code)
	}
}

Autofilling of all required input fields is supported:

r, err := ParseResponse(w.Result(), r.URL).FirstForm().NewTestRequest(
	Autofill(),
)

Elements that include a pattern attribute for validation will not be autofilled and have to be filled in manually. For example:

r, err := ParseResponse(w.Result(), r.URL).FirstForm().NewTestRequest(
	Autofill(),
	Set("validatedURL", "https://www.example.com"),
)

Testing Helpers

To avoid checking for error in tests manually when creating a new test request , the value of t *testing.T can be provided:

r := ParseResponse(w.Result(), r.URL).FirstForm().Testing(t).NewTestRequest(
	Autofill(),
	Set("validatedURL", "https://www.example.com"),
)

In case of any errors, the t.Fatalf() function will be called. t.Helper() is used appropriately to ensure line numbers reported by go test are correct.

Supported Elements

  • input[type=checkbox]
  • input[type=date]
  • input[type=email]
  • input[type=hidden]
  • input[type=number]
  • input[type=radio]
  • input[type=text]
  • input[type=url]
  • textarea
  • select
  • select[multiple]
  • button[type=submit] with name and value
  • input[type=submit] with name and value

If an input element is not on this list, it will default to text input.

Who Is Using gosubmit?

License

MIT

Owner
Jerko Steiner
Coder, guitarist, traveler, photographer. Software architect, creator of Peer Calls & founder of rondomoon
Jerko Steiner
Similar Resources

DeepCopy a portable app that allows you to copy all forms of specified file types from your entire file system of the computer

DeepCopy a portable app that allows you to copy all forms of specified file types from your entire file system of the computer

Dec 20, 2021

Go-httpheaders - Canonicalized forms of common HTTP headers for Go

Go-httpheaders - Canonicalized forms of common HTTP headers for Go

Mar 20, 2022

Simple system for writing HTML/XML as Go code. Better-performing replacement for html/template and text/template

Simple system for writing HTML as Go code. Use normal Go conditionals, loops and functions. Benefit from typing and code analysis. Better performance than templating. Tiny and dependency-free.

Dec 5, 2022

bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS

bluemonday bluemonday is a HTML sanitizer implemented in Go. It is fast and highly configurable. bluemonday takes untrusted user generated content as

Jan 4, 2023

VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients

VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients

VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients Email clients use different rendering standards. This is

Dec 17, 2022

This command line converts .html file into .html with images embed.

embed-html This command line converts .html file into .html with images embed. Install go get github.com/gonejack/embed-html Usage embed-html *.ht

Oct 6, 2022

A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

Jan 9, 2023

Golang library for querying and parsing OFX

OFXGo OFXGo is a library for querying OFX servers and/or parsing the responses. It also provides an example command-line client to demonstrate the use

Nov 25, 2022

Golang library for querying and parsing OFX

OFXGo OFXGo is a library for querying OFX servers and/or parsing the responses. It also provides an example command-line client to demonstrate the use

Jan 3, 2023

A Go library for fetching, parsing, and updating RSS feeds.

rss RSS is a small library for simplifying the parsing of RSS and Atom feeds. The package could do with more testing, but it conforms to the RSS 1.0,

Dec 14, 2022

The /etc/hosts parsing and resolver library for golang

Hostsfile The /etc/hosts parsing and resolver library for golang Hostsfile is a go (golang) package for parsing hosts files and performing reverse IP

May 11, 2022

Mathematical expression parsing and calculation engine library. 数学表达式解析计算引擎库

Math-Engine 使用 Go 实现的数学表达式解析计算引擎库,它小巧,无任何依赖,具有扩展性(比如可以注册自己的函数到引擎中),比较完整的完成了数学表达式解析执行,包括词法分析、语法分析、构建AST、运行。 go get -u github.com/dengsgo/math-engine 能够

Jan 3, 2023

Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner

Molecule Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner. The API is loosely based on this excellent Go JSON

Jan 5, 2023

Lightweight Router for Golang using net/http standard library with custom route parsing, handler and context.

Go-Lightweight-Router Lightweight Router for Golang using net/http standard library with custom route parsing, handler and context. Further developmen

Nov 3, 2021

Simple library to handle ANSI functions and parsing of color formatting strings

Emerald A basic color library for use in my Go projects, built on top of mgutz/ansi. Package ansi is a small, fast library to create ANSI colored stri

Oct 28, 2022

Flag is a simple but powerful command line option parsing library for Go support infinite level subcommand

Flag Flag is a simple but powerful commandline flag parsing library for Go. Documentation Documentation can be found at Godoc Supported features bool

Sep 26, 2022

A lightweight go library for parsing form data or json from an http.Request.

Forms Forms is a lightweight, but incredibly useful go library for parsing form data from an http.Request. It supports multipart forms, url-encoded fo

Dec 16, 2022

A Golang library to manipulate strings according to the word parsing rules of the UNIX Bourne shell.

shellwords A Golang library to manipulate strings according to the word parsing rules of the UNIX Bourne shell. Installation go get github.com/Wing924

Sep 27, 2022

Lenient VCS repository URL parsing library for Go

============================================= go-vcsurl - Lenient VCS repository URL parser go-vcsurl parses VCS repository URLs in many common format

Dec 23, 2019
Comments
  • No license -> no docs

    No license -> no docs

    The normal go docs server only displays docs for packages that have a valid open source license.

    https://pkg.go.dev/github.com/jeremija/gosubmit is empty

    Please add a LICENSE file

Golang Forms made easy.

Go-FORM-it Description go-form-it makes form creation and handling easy. It allows the creation of form without having to write HTML code or bother to

Aug 20, 2022
A lightweight go library for parsing form data or json from an http.Request.

Forms Forms is a lightweight, but incredibly useful go library for parsing form data from an http.Request. It supports multipart forms, url-encoded fo

Dec 16, 2022
:steam_locomotive: Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.

Package form Package form Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. It has the following features: Supports map of

Dec 26, 2022
Data validation, cleaning and error collection for golang

GoForms - form data validation, cleaning and error reporting The goforms library is a proof-of-concept for a data validation, cleaning and error colle

Jan 14, 2022
Hera is a Python framework for constructing and submitting Argo Workflows.

Hera is an Argo Workflows Python SDK. Hera aims to make workflow construction and submission easy and accessible to everyone! Hera abstracts away workflow setup details while still maintaining a consistent vocabulary with Argo Workflows.

Dec 31, 2022
HTML forms for Golang

HTML forms for Golang Installation: go get github.com/vmihailenco/gforms Example Example: package blog import ( "net/http" "github.com/vmih

Apr 3, 2020
ByNom is a Go package for parsing byte sequences, suitable for parsing text and binary data

ByNom is a Go package for parsing byte sequences. Its goal is to provide tools to build safe byte parsers without compromising the speed or memo

May 5, 2021
Forms is a fast, powerful, flexible, sortable web form rendering library written in golang.

forms Description forms makes form creation and handling easy. It allows the creation of form without having to write HTML code or bother to make the

Oct 2, 2022
Golang Forms made easy.

Go-FORM-it Description go-form-it makes form creation and handling easy. It allows the creation of form without having to write HTML code or bother to

Aug 20, 2022
It's so many regular expression forms are difficult to understand, such as perl, python, grep awk

Introduction Jamie Zawinski: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. It

Mar 31, 2022