github.com/MontFerret/ferret@v0.18.0/pkg/drivers/value.go (about) 1 package drivers 2 3 import ( 4 "context" 5 "io" 6 7 "github.com/MontFerret/ferret/pkg/runtime/events" 8 9 "github.com/MontFerret/ferret/pkg/runtime/collections" 10 "github.com/MontFerret/ferret/pkg/runtime/core" 11 "github.com/MontFerret/ferret/pkg/runtime/values" 12 ) 13 14 type ( 15 // WaitEvent is an enum that represents what event is needed to wait for 16 WaitEvent int 17 18 // HTMLNode is an interface from which a number of DOM API object types inherit. 19 // It allows those types to be treated similarly; 20 // for example, inheriting the same set of methods, or being tested in the same way. 21 HTMLNode interface { 22 core.Value 23 core.Iterable 24 core.Getter 25 core.Setter 26 collections.Measurable 27 io.Closer 28 29 GetNodeType(ctx context.Context) (values.Int, error) 30 31 GetNodeName(ctx context.Context) (values.String, error) 32 33 GetChildNodes(ctx context.Context) (*values.Array, error) 34 35 GetChildNode(ctx context.Context, idx values.Int) (core.Value, error) 36 37 QuerySelector(ctx context.Context, selector QuerySelector) (core.Value, error) 38 39 QuerySelectorAll(ctx context.Context, selector QuerySelector) (*values.Array, error) 40 41 CountBySelector(ctx context.Context, selector QuerySelector) (values.Int, error) 42 43 ExistsBySelector(ctx context.Context, selector QuerySelector) (values.Boolean, error) 44 45 XPath(ctx context.Context, expression values.String) (core.Value, error) 46 } 47 48 // HTMLElement is the most general base interface which most objects in a GetMainFrame implement. 49 HTMLElement interface { 50 HTMLNode 51 52 GetInnerText(ctx context.Context) (values.String, error) 53 54 SetInnerText(ctx context.Context, innerText values.String) error 55 56 GetInnerHTML(ctx context.Context) (values.String, error) 57 58 SetInnerHTML(ctx context.Context, innerHTML values.String) error 59 60 GetValue(ctx context.Context) (core.Value, error) 61 62 SetValue(ctx context.Context, value core.Value) error 63 64 GetStyles(ctx context.Context) (*values.Object, error) 65 66 GetStyle(ctx context.Context, name values.String) (core.Value, error) 67 68 SetStyles(ctx context.Context, values *values.Object) error 69 70 SetStyle(ctx context.Context, name, value values.String) error 71 72 RemoveStyle(ctx context.Context, name ...values.String) error 73 74 GetAttributes(ctx context.Context) (*values.Object, error) 75 76 GetAttribute(ctx context.Context, name values.String) (core.Value, error) 77 78 SetAttributes(ctx context.Context, values *values.Object) error 79 80 SetAttribute(ctx context.Context, name, value values.String) error 81 82 RemoveAttribute(ctx context.Context, name ...values.String) error 83 84 GetInnerHTMLBySelector(ctx context.Context, selector QuerySelector) (values.String, error) 85 86 SetInnerHTMLBySelector(ctx context.Context, selector QuerySelector, innerHTML values.String) error 87 88 GetInnerHTMLBySelectorAll(ctx context.Context, selector QuerySelector) (*values.Array, error) 89 90 GetInnerTextBySelector(ctx context.Context, selector QuerySelector) (values.String, error) 91 92 SetInnerTextBySelector(ctx context.Context, selector QuerySelector, innerText values.String) error 93 94 GetInnerTextBySelectorAll(ctx context.Context, selector QuerySelector) (*values.Array, error) 95 96 GetPreviousElementSibling(ctx context.Context) (core.Value, error) 97 98 GetNextElementSibling(ctx context.Context) (core.Value, error) 99 100 GetParentElement(ctx context.Context) (core.Value, error) 101 102 Click(ctx context.Context, count values.Int) error 103 104 ClickBySelector(ctx context.Context, selector QuerySelector, count values.Int) error 105 106 ClickBySelectorAll(ctx context.Context, selector QuerySelector, count values.Int) error 107 108 Clear(ctx context.Context) error 109 110 ClearBySelector(ctx context.Context, selector QuerySelector) error 111 112 Input(ctx context.Context, value core.Value, delay values.Int) error 113 114 InputBySelector(ctx context.Context, selector QuerySelector, value core.Value, delay values.Int) error 115 116 Press(ctx context.Context, keys []values.String, count values.Int) error 117 118 PressBySelector(ctx context.Context, selector QuerySelector, keys []values.String, count values.Int) error 119 120 Select(ctx context.Context, value *values.Array) (*values.Array, error) 121 122 SelectBySelector(ctx context.Context, selector QuerySelector, value *values.Array) (*values.Array, error) 123 124 ScrollIntoView(ctx context.Context, options ScrollOptions) error 125 126 Focus(ctx context.Context) error 127 128 FocusBySelector(ctx context.Context, selector QuerySelector) error 129 130 Blur(ctx context.Context) error 131 132 BlurBySelector(ctx context.Context, selector QuerySelector) error 133 134 Hover(ctx context.Context) error 135 136 HoverBySelector(ctx context.Context, selector QuerySelector) error 137 138 WaitForElement(ctx context.Context, selector QuerySelector, when WaitEvent) error 139 140 WaitForElementAll(ctx context.Context, selector QuerySelector, when WaitEvent) error 141 142 WaitForAttribute(ctx context.Context, name values.String, value core.Value, when WaitEvent) error 143 144 WaitForAttributeBySelector(ctx context.Context, selector QuerySelector, name values.String, value core.Value, when WaitEvent) error 145 146 WaitForAttributeBySelectorAll(ctx context.Context, selector QuerySelector, name values.String, value core.Value, when WaitEvent) error 147 148 WaitForStyle(ctx context.Context, name values.String, value core.Value, when WaitEvent) error 149 150 WaitForStyleBySelector(ctx context.Context, selector QuerySelector, name values.String, value core.Value, when WaitEvent) error 151 152 WaitForStyleBySelectorAll(ctx context.Context, selector QuerySelector, name values.String, value core.Value, when WaitEvent) error 153 154 WaitForClass(ctx context.Context, class values.String, when WaitEvent) error 155 156 WaitForClassBySelector(ctx context.Context, selector QuerySelector, class values.String, when WaitEvent) error 157 158 WaitForClassBySelectorAll(ctx context.Context, selector QuerySelector, class values.String, when WaitEvent) error 159 } 160 161 HTMLDocument interface { 162 HTMLNode 163 164 GetTitle() values.String 165 166 GetElement() HTMLElement 167 168 GetURL() values.String 169 170 GetName() values.String 171 172 GetParentDocument(ctx context.Context) (HTMLDocument, error) 173 174 GetChildDocuments(ctx context.Context) (*values.Array, error) 175 176 Scroll(ctx context.Context, options ScrollOptions) error 177 178 ScrollTop(ctx context.Context, options ScrollOptions) error 179 180 ScrollBottom(ctx context.Context, options ScrollOptions) error 181 182 ScrollBySelector(ctx context.Context, selector QuerySelector, options ScrollOptions) error 183 184 MoveMouseByXY(ctx context.Context, x, y values.Float) error 185 } 186 187 // HTMLPage interface represents any web page loaded in the browser 188 // and serves as an entry point into the web page's content 189 HTMLPage interface { 190 core.Value 191 core.Iterable 192 core.Getter 193 core.Setter 194 collections.Measurable 195 events.Observable 196 io.Closer 197 198 IsClosed() values.Boolean 199 200 GetURL() values.String 201 202 GetMainFrame() HTMLDocument 203 204 GetFrames(ctx context.Context) (*values.Array, error) 205 206 GetFrame(ctx context.Context, idx values.Int) (core.Value, error) 207 208 GetCookies(ctx context.Context) (*HTTPCookies, error) 209 210 SetCookies(ctx context.Context, cookies *HTTPCookies) error 211 212 DeleteCookies(ctx context.Context, cookies *HTTPCookies) error 213 214 GetResponse(ctx context.Context) (HTTPResponse, error) 215 216 PrintToPDF(ctx context.Context, params PDFParams) (values.Binary, error) 217 218 CaptureScreenshot(ctx context.Context, params ScreenshotParams) (values.Binary, error) 219 220 WaitForNavigation(ctx context.Context, targetURL values.String) error 221 222 WaitForFrameNavigation(ctx context.Context, frame HTMLDocument, targetURL values.String) error 223 224 Navigate(ctx context.Context, url values.String) error 225 226 NavigateBack(ctx context.Context, skip values.Int) (values.Boolean, error) 227 228 NavigateForward(ctx context.Context, skip values.Int) (values.Boolean, error) 229 } 230 ) 231 232 const ( 233 // WaitEventPresence indicating to wait for value to appear 234 WaitEventPresence = 0 235 236 // WaitEventAbsence indicating to wait for value to disappear 237 WaitEventAbsence = 1 238 )