Refactoring in progress

This commit is contained in:
Daniel Ziltener 2022-05-16 15:17:04 +02:00
parent ae6c229e31
commit d014f5c76e
5 changed files with 109 additions and 88 deletions

View File

@ -23,18 +23,6 @@ WebDriverTest >> tearDown [
super tearDown.
]
{ #category : #tests }
WebDriverTest >> testAttributeValue [
| element |
element := webdriver
url: 'http://info.cern.ch';
findElement: 'a' using: WDLocationStrategy cssSelector.
self
assert: (webdriver attribute: 'href' from: element)
equals: 'http://info.cern.ch/hypertext/WWW/TheProject.html'
]
{ #category : #tests }
WebDriverTest >> testFindElementInvalidCSSSelector [
self

View File

@ -1,33 +1,97 @@
"
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 : #String,
#superclass : #Object,
#instVars : [
'selector',
'locationStrategy'
'driver',
'element'
],
#category : #WebDriver
#category : #'WebDriver-Base'
}
{ #category : #accessing }
WDElement >> locationStrategy [
WDElement >> attribute: attr [
^ locationStrategy
^ self driver
sendWithSession: { }
to:
'element/' , element , '/attribute/'
, attr
using: #GET
]
{ #category : #simulating }
WDElement >> click [
self driver
sendWithSession: { }
to: 'element/' , element , '/click'
using: #POST
]
{ #category : #accessing }
WDElement >> locationStrategy: anObject [
WDElement >> driver [
locationStrategy := anObject
^ driver
]
{ #category : #accessing }
WDElement >> selector [
WDElement >> driver: anObject [
^ selector
driver := anObject
]
{ #category : #accessing }
WDElement >> selector: anObject [
WDElement >> element [
selector := anObject
^ element
]
{ #category : #accessing }
WDElement >> element: anObject [
element := anObject
]
{ #category : #accessing }
WDElement >> property: attr [
^ self driver
sendWithSession: { }
to:
'element/' , element , '/property/'
, attr
using: #GET
]
{ #category : #simulating }
WDElement >> type: text [
self driver
sendWithSession: { (#text -> text) }
to: 'element/' , element , '/value'
using: #POST
]

View File

@ -13,7 +13,7 @@ Class {
#instVars : [
'timeouts'
],
#category : #WebDriver
#category : #'WebDriver-Base'
}
{ #category : #accessing }

View File

@ -39,7 +39,7 @@ Class {
'sessionId',
'prefs'
],
#category : #WebDriver
#category : #'WebDriver-Base'
}
{ #category : #testing }
@ -76,17 +76,6 @@ WebDriver >> atPref: prefKey put: prefVal [
prefs at: prefKey put: prefVal.
]
{ #category : #accessing }
WebDriver >> attribute: attr from: element [
^ self
send: { }
to:
'session/' , sessionId , '/element/' , element , '/attribute/'
, attr
using: #GET
]
{ #category : #navigation }
WebDriver >> back [
@ -101,15 +90,6 @@ WebDriver >> browser: brs server: srv port: portnum [
port := portnum.
]
{ #category : #'event handling' }
WebDriver >> click: elem [
self
send: { }
to: 'session/' , sessionId , '/element/' , elem , '/click'
using: #POST
]
{ #category : #'private - utilities' }
WebDriver >> constructCapabilities: caps [
@ -141,9 +121,9 @@ WebDriver >> findElement: elemSelector using: locStrategy [
(#value -> elemSelector) }
to: 'session/' , sessionId , '/element'
using: #POST.
(reply at: #error ifPresent: [ true ] ifAbsent: [ false ])
ifTrue: [ ^ WDException raise: reply ]
ifFalse: [ ^ WDElement fromString: reply values first ]
^ WDElement new
driver: self;
element: reply values first.
]
{ #category : #accessing }
@ -156,10 +136,7 @@ WebDriver >> findElements: elemSelector using: locStrategy [
(#value -> elemSelector) }
to: 'session/' , sessionId , '/elements'
using: #POST.
reply isArray
ifTrue: [
^ reply collect: [ :elem | WDElement fromString: elem values first ] ]
ifFalse: [ ^ WDException raise: reply ]
^ reply collect: [ :elem | WDElement new driver: self; element: elem values first. ]
]
{ #category : #navigation }
@ -168,15 +145,9 @@ WebDriver >> forward [
self send: { } to: 'session/' , sessionId , '/forward' using: #POST
]
{ #category : #accessing }
WebDriver >> property: attr from: element [
^ self
send: { }
to:
'session/' , sessionId , '/element/' , element , '/property/'
, attr
using: #GET
{ #category : #'private - utilities' }
WebDriver >> postprocessResult: result [
^ result.
]
{ #category : #navigation }
@ -187,7 +158,27 @@ WebDriver >> refresh [
{ #category : #'private - utilities' }
WebDriver >> send: dict to: url using: method [
^ self subclassResponsibility.
|result|
result := nil.
ZnClient new
host: server;
port: port;
path: url;
contents: (NeoJSONWriter toString: dict asDictionary);
contentType: ZnMimeType applicationJson;
method: method;
contentReader: [ :entity |
result := (NeoJSONReader on: (entity contents) readStream) propertyNamesAsSymbols: true; next.
result := self postprocessResult: result.
(result keys contains: #error) ifTrue: [ WDException raise: result ].
];
execute.
^result.
]
{ #category : #'private - utilities' }
WebDriver >> sendWithSession: dict to: url using: method [
^ self send: dict to: '/session/' , sessionId , '/' , url using: method
]
{ #category : #accessing }
@ -255,15 +246,6 @@ WebDriver >> title [
^ self send: { } to: 'session/' , sessionId , '/title' using: #GET
]
{ #category : #'text input' }
WebDriver >> type: text into: element [
self
send: { (#text -> text) }
to: 'session/' , sessionId , '/element/' , element , '/value'
using: #POST
]
{ #category : #accessing }
WebDriver >> url [

View File

@ -38,20 +38,7 @@ WebDriverGeckodriver >> initialize [
prefs := Dictionary new.
]
{ #category : #navigation }
WebDriverGeckodriver >> send: dict to: url using: method [
|result|
result := nil.
ZnClient new
host: server;
port: port;
path: url;
contents: (NeoJSONWriter toString: dict asDictionary);
contentType: ZnMimeType applicationJson;
method: method;
contentReader: [ :entity |
result := (NeoJSONReader on: (entity contents) readStream) propertyNamesAsSymbols: true; next.
];
execute.
^result at: #value.
{ #category : #'private - utilities' }
WebDriverGeckodriver >> postprocessResult: result [
^ result at: #value.
]