Refactoring in progress
This commit is contained in:
parent
ae6c229e31
commit
d014f5c76e
|
@ -23,18 +23,6 @@ WebDriverTest >> tearDown [
|
||||||
super 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 }
|
{ #category : #tests }
|
||||||
WebDriverTest >> testFindElementInvalidCSSSelector [
|
WebDriverTest >> testFindElementInvalidCSSSelector [
|
||||||
self
|
self
|
||||||
|
|
|
@ -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 {
|
Class {
|
||||||
#name : #WDElement,
|
#name : #WDElement,
|
||||||
#superclass : #String,
|
#superclass : #Object,
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'selector',
|
'driver',
|
||||||
'locationStrategy'
|
'element'
|
||||||
],
|
],
|
||||||
#category : #WebDriver
|
#category : #'WebDriver-Base'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #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 }
|
{ #category : #accessing }
|
||||||
WDElement >> locationStrategy: anObject [
|
WDElement >> driver [
|
||||||
|
|
||||||
locationStrategy := anObject
|
^ driver
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
WDElement >> selector [
|
WDElement >> driver: anObject [
|
||||||
|
|
||||||
^ selector
|
driver := anObject
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #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
|
||||||
]
|
]
|
||||||
|
|
|
@ -13,7 +13,7 @@ Class {
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'timeouts'
|
'timeouts'
|
||||||
],
|
],
|
||||||
#category : #WebDriver
|
#category : #'WebDriver-Base'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
|
|
@ -39,7 +39,7 @@ Class {
|
||||||
'sessionId',
|
'sessionId',
|
||||||
'prefs'
|
'prefs'
|
||||||
],
|
],
|
||||||
#category : #WebDriver
|
#category : #'WebDriver-Base'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #testing }
|
{ #category : #testing }
|
||||||
|
@ -76,17 +76,6 @@ WebDriver >> atPref: prefKey put: prefVal [
|
||||||
prefs at: 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 }
|
{ #category : #navigation }
|
||||||
WebDriver >> back [
|
WebDriver >> back [
|
||||||
|
|
||||||
|
@ -101,15 +90,6 @@ WebDriver >> browser: brs server: srv port: portnum [
|
||||||
port := portnum.
|
port := portnum.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'event handling' }
|
|
||||||
WebDriver >> click: elem [
|
|
||||||
|
|
||||||
self
|
|
||||||
send: { }
|
|
||||||
to: 'session/' , sessionId , '/element/' , elem , '/click'
|
|
||||||
using: #POST
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #'private - utilities' }
|
{ #category : #'private - utilities' }
|
||||||
WebDriver >> constructCapabilities: caps [
|
WebDriver >> constructCapabilities: caps [
|
||||||
|
|
||||||
|
@ -141,9 +121,9 @@ WebDriver >> findElement: elemSelector using: locStrategy [
|
||||||
(#value -> elemSelector) }
|
(#value -> elemSelector) }
|
||||||
to: 'session/' , sessionId , '/element'
|
to: 'session/' , sessionId , '/element'
|
||||||
using: #POST.
|
using: #POST.
|
||||||
(reply at: #error ifPresent: [ true ] ifAbsent: [ false ])
|
^ WDElement new
|
||||||
ifTrue: [ ^ WDException raise: reply ]
|
driver: self;
|
||||||
ifFalse: [ ^ WDElement fromString: reply values first ]
|
element: reply values first.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
@ -156,10 +136,7 @@ WebDriver >> findElements: elemSelector using: locStrategy [
|
||||||
(#value -> elemSelector) }
|
(#value -> elemSelector) }
|
||||||
to: 'session/' , sessionId , '/elements'
|
to: 'session/' , sessionId , '/elements'
|
||||||
using: #POST.
|
using: #POST.
|
||||||
reply isArray
|
^ reply collect: [ :elem | WDElement new driver: self; element: elem values first. ]
|
||||||
ifTrue: [
|
|
||||||
^ reply collect: [ :elem | WDElement fromString: elem values first ] ]
|
|
||||||
ifFalse: [ ^ WDException raise: reply ]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #navigation }
|
{ #category : #navigation }
|
||||||
|
@ -168,15 +145,9 @@ WebDriver >> forward [
|
||||||
self send: { } to: 'session/' , sessionId , '/forward' using: #POST
|
self send: { } to: 'session/' , sessionId , '/forward' using: #POST
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #'private - utilities' }
|
||||||
WebDriver >> property: attr from: element [
|
WebDriver >> postprocessResult: result [
|
||||||
|
^ result.
|
||||||
^ self
|
|
||||||
send: { }
|
|
||||||
to:
|
|
||||||
'session/' , sessionId , '/element/' , element , '/property/'
|
|
||||||
, attr
|
|
||||||
using: #GET
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #navigation }
|
{ #category : #navigation }
|
||||||
|
@ -187,7 +158,27 @@ WebDriver >> refresh [
|
||||||
|
|
||||||
{ #category : #'private - utilities' }
|
{ #category : #'private - utilities' }
|
||||||
WebDriver >> send: dict to: url using: method [
|
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 }
|
{ #category : #accessing }
|
||||||
|
@ -255,15 +246,6 @@ WebDriver >> title [
|
||||||
^ self send: { } to: 'session/' , sessionId , '/title' using: #GET
|
^ 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 }
|
{ #category : #accessing }
|
||||||
WebDriver >> url [
|
WebDriver >> url [
|
||||||
|
|
||||||
|
|
|
@ -38,20 +38,7 @@ WebDriverGeckodriver >> initialize [
|
||||||
prefs := Dictionary new.
|
prefs := Dictionary new.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #navigation }
|
{ #category : #'private - utilities' }
|
||||||
WebDriverGeckodriver >> send: dict to: url using: method [
|
WebDriverGeckodriver >> postprocessResult: result [
|
||||||
|result|
|
^ result at: #value.
|
||||||
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.
|
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue