WebDriver/src/WebDriver/WDElement.class.st

209 lines
4.4 KiB
Smalltalk

"
I represent a DOM element.
For the Responsibility part: Three sentences about my main responsibilities - what I do, what I know.
For the Collaborators Part: State my main collaborators and one line about how I interact with them.
Public API and Key Messages
- message one
- message two
- (for bonus points) how to create instances.
One simple example is simply gorgeous.
Internal Representation and Key Implementation Points.
Instance Variables
driver: <Object>
element: <Object>
Implementation Points
"
Class {
#name : #WDElement,
#superclass : #Object,
#instVars : [
'driver',
'element'
],
#category : #'WebDriver-Base'
}
{ #category : #accessing }
WDElement >> attribute: attr [
| result |
result := self driver
sendWithSession: { }
to:
'element/' , element , '/attribute/'
, attr
using: #GET.
^ result = 'true' ifTrue: [ true ] ifFalse: [ result ].
]
{ #category : #accessing }
WDElement >> attributes [
| script result |
script := 'var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;'.
result := driver sendWithSession: { #script -> script . #args -> {{ 'element-6066-11e4-a52e-4f735466cecf' -> element } asDictionary} } asDictionary
to: 'execute/sync'
using: #POST.
^ result.
]
{ #category : #simulating }
WDElement >> clear [
self driver
sendWithSession: { }
to: 'element/' , element , '/clear'
using: #POST
]
{ #category : #simulating }
WDElement >> click [
self driver
sendWithSession: { }
to: 'element/' , element , '/click'
using: #POST
]
{ #category : #accessing }
WDElement >> computedLabel [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/computedlabel'
using: #GET
]
{ #category : #accessing }
WDElement >> computedRole [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/computedrole'
using: #GET
]
{ #category : #'private - utilities' }
WDElement >> driver [
^ driver
]
{ #category : #'private - utilities' }
WDElement >> driver: anObject [
driver := anObject
]
{ #category : #'private - utilities' }
WDElement >> element [
^ element
]
{ #category : #'private - utilities' }
WDElement >> element: anObject [
element := anObject
]
{ #category : #'private - utilities' }
WDElement >> inspectionWDElement [
<inspectorPresentationOrder: 10 title: 'DOM Element'>
| presenter attrPresenter screenshotPresenter |
attrPresenter := SpBoxLayout newTopToBottom
add: (SpLabelPresenter new label: ('Infos about the "{1}" element:' format: {self name}); yourself)
expand: false
fill: false
padding: 5;
add: self attributes asStringTablePresenter
expand: true
fill: true
padding: 5;
yourself.
screenshotPresenter := SpBoxLayout newTopToBottom
add: (SpLabelPresenter new label: 'Preview:'; yourself) expand: false fill: false padding: 5;
add: (SpImagePresenter new image: (Form fromBinaryStream: (self screenshot readStream)));
yourself.
presenter := SpPanedLayout newTopToBottom
add: attrPresenter;
add: screenshotPresenter;
yourself.
presenter := SpPresenter new layout: presenter; yourself.
^ presenter.
]
{ #category : #accessing }
WDElement >> isEnabled [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/enabled'
using: #GET
]
{ #category : #accessing }
WDElement >> isSelected [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/selected'
using: #GET
]
{ #category : #accessing }
WDElement >> name [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/name'
using: #GET
]
{ #category : #accessing }
WDElement >> property: attr [
^ self driver
sendWithSession: { }
to:
'element/' , element , '/property/'
, attr
using: #GET
]
{ #category : #accessing }
WDElement >> rect [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/rect'
using: #GET
]
{ #category : #accessing }
WDElement >> screenshot [
^ (driver sendWithSession: '' to: 'element/',element,'/screenshot' using: #GET) base64Decoded.
]
{ #category : #accessing }
WDElement >> text [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/text'
using: #GET
]
{ #category : #simulating }
WDElement >> value: text [
self driver
sendWithSession: { (#text -> text) }
to: 'element/' , element , '/value'
using: #POST
]