WebDriver/src/WebDriver/WDElement.class.st

225 lines
4.8 KiB
Smalltalk
Raw Normal View History

2022-05-16 13:17:04 +00:00
"
I represent a DOM element.
For the Responsibility part: Three sentences about my main responsibilities - what I do, what I know.
Instance Variables
2023-04-25 15:19:00 +00:00
driver: <Object> The active WebDriver from which this element was received
element: <Object> The actual WebDriver element
2022-05-16 13:17:04 +00:00
"
2022-04-26 23:10:51 +00:00
Class {
#name : #WDElement,
2022-05-16 13:17:04 +00:00
#superclass : #Object,
2022-04-26 23:10:51 +00:00
#instVars : [
2022-05-16 13:17:04 +00:00
'driver',
'element'
2022-04-26 23:10:51 +00:00
],
2022-05-16 13:17:04 +00:00
#category : #'WebDriver-Base'
2022-04-26 23:10:51 +00:00
}
{ #category : #accessing }
2022-05-16 13:17:04 +00:00
WDElement >> attribute: attr [
2022-05-17 00:37:54 +00:00
| result |
2022-05-16 13:17:04 +00:00
2022-05-17 00:37:54 +00:00
result := self driver
2022-05-16 13:17:04 +00:00
sendWithSession: { }
to:
'element/' , element , '/attribute/'
, attr
2022-05-17 00:37:54 +00:00
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;'.
2022-05-17 18:50:10 +00:00
result := driver sendWithSession: { #script -> script . #args -> {{ 'element-6066-11e4-a52e-4f735466cecf' -> element } asDictionary} } asDictionary
to: 'execute/sync'
2022-05-17 00:37:54 +00:00
using: #POST.
^ result.
]
{ #category : #simulating }
WDElement >> clear [
self driver
sendWithSession: { }
to: 'element/' , element , '/clear'
using: #POST
2022-05-16 13:17:04 +00:00
]
{ #category : #simulating }
WDElement >> click [
self driver
sendWithSession: { }
to: 'element/' , element , '/click'
using: #POST
]
2022-05-17 00:37:54 +00:00
{ #category : #accessing }
2022-05-16 16:09:02 +00:00
WDElement >> computedLabel [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/computedlabel'
using: #GET
]
2022-05-17 00:37:54 +00:00
{ #category : #accessing }
2022-05-16 16:09:02 +00:00
WDElement >> computedRole [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/computedrole'
using: #GET
]
2022-05-17 00:37:54 +00:00
{ #category : #'private - utilities' }
2022-05-16 13:17:04 +00:00
WDElement >> driver [
2022-04-26 23:10:51 +00:00
2022-05-16 13:17:04 +00:00
^ driver
2022-04-26 23:10:51 +00:00
]
2022-05-17 00:37:54 +00:00
{ #category : #'private - utilities' }
2022-05-16 13:17:04 +00:00
WDElement >> driver: anObject [
2022-04-26 23:10:51 +00:00
2022-05-16 13:17:04 +00:00
driver := anObject
2022-04-26 23:10:51 +00:00
]
2022-05-17 00:37:54 +00:00
{ #category : #'private - utilities' }
2022-05-16 13:17:04 +00:00
WDElement >> element [
2022-04-26 23:10:51 +00:00
2022-05-16 13:17:04 +00:00
^ element
2022-04-26 23:10:51 +00:00
]
2022-05-17 00:37:54 +00:00
{ #category : #'private - utilities' }
2022-05-16 13:17:04 +00:00
WDElement >> element: anObject [
element := anObject
]
2022-05-21 16:47:21 +00:00
{ #category : #accessing }
WDElement >> findElement: elemSelector using: locStrategy [
| reply |
reply := driver
sendWithSession: {
(#using -> locStrategy).
(#value -> elemSelector)
}
to: 'element/' , element , '/element'
using: #POST.
^ self class new
driver: driver;
element: reply values first.
]
{ #category : #accessing }
WDElement >> findElements: elemSelector using: locStrategy [
| reply |
reply := driver
sendWithSession: {
(#using -> locStrategy).
(#value -> elemSelector)
}
to: 'element/' , element , '/elements'
using: #POST.
^ reply collect: [ :elem | self class new driver: driver; element: elem values first. ]
]
2022-05-17 18:50:10 +00:00
{ #category : #'private - utilities' }
WDElement >> inspectionWDElement [
<inspectorPresentationOrder: 10 title: 'DOM Element'>
2022-05-18 17:04:42 +00:00
| presenter attrPresenter screenshotPresenter |
2022-05-17 18:50:10 +00:00
attrPresenter := SpBoxLayout newTopToBottom
2022-05-18 19:44:57 +00:00
add: (SpLabelPresenter new label: ('Infos about the "{1}" element:' format: {self name}))
2022-05-17 18:50:10 +00:00
expand: false
fill: false
padding: 5;
2022-05-18 17:04:42 +00:00
add: self attributes asStringTablePresenter
2022-05-17 18:50:10 +00:00
expand: true
fill: true
padding: 5;
yourself.
screenshotPresenter := SpBoxLayout newTopToBottom
2022-05-18 19:44:57 +00:00
add: (SpLabelPresenter new label: 'Preview:') expand: false fill: false padding: 5;
2022-05-17 18:50:10 +00:00
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.
]
2022-05-17 00:37:54 +00:00
{ #category : #accessing }
2022-05-16 16:09:02 +00:00
WDElement >> isEnabled [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/enabled'
using: #GET
]
2022-05-17 00:37:54 +00:00
{ #category : #accessing }
2022-05-16 16:09:02 +00:00
WDElement >> isSelected [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/selected'
using: #GET
]
2022-05-17 00:37:54 +00:00
{ #category : #accessing }
2022-05-16 16:09:02 +00:00
WDElement >> name [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/name'
using: #GET
]
2022-05-16 13:17:04 +00:00
{ #category : #accessing }
WDElement >> property: attr [
^ self driver
sendWithSession: { }
to:
'element/' , element , '/property/'
, attr
using: #GET
]
2022-05-17 00:37:54 +00:00
{ #category : #accessing }
2022-05-16 16:09:02 +00:00
WDElement >> rect [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/rect'
using: #GET
]
2022-05-17 18:50:10 +00:00
{ #category : #accessing }
WDElement >> screenshot [
^ (driver sendWithSession: '' to: 'element/',element,'/screenshot' using: #GET) base64Decoded.
]
2022-05-17 00:37:54 +00:00
{ #category : #accessing }
2022-05-16 16:09:02 +00:00
WDElement >> text [
^ self driver
sendWithSession: { }
to: 'element/' , element , '/text'
using: #GET
]
2022-05-16 13:17:04 +00:00
{ #category : #simulating }
2022-05-16 16:09:02 +00:00
WDElement >> value: text [
2022-04-26 23:10:51 +00:00
2022-05-16 13:17:04 +00:00
self driver
sendWithSession: { (#text -> text) }
to: 'element/' , element , '/value'
using: #POST
2022-04-26 23:10:51 +00:00
]