diff --git a/src/WebDriver/WDDetachedShadowRoot.class.st b/src/WebDriver/WDDetachedShadowRoot.class.st new file mode 100644 index 0000000..fc0415d --- /dev/null +++ b/src/WebDriver/WDDetachedShadowRoot.class.st @@ -0,0 +1,13 @@ +" +A command failed because the referenced shadow root is no longer attached to the DOM. +" +Class { + #name : #WDDetachedShadowRoot, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDDetachedShadowRoot class >> matchesErrorCode: errCode [ + ^ errCode = 'detached shadow root' +] diff --git a/src/WebDriver/WDElementClickIntercepted.class.st b/src/WebDriver/WDElementClickIntercepted.class.st index 007dfae..4bcc4e2 100644 --- a/src/WebDriver/WDElementClickIntercepted.class.st +++ b/src/WebDriver/WDElementClickIntercepted.class.st @@ -4,5 +4,10 @@ The Element Click command could not be completed because the element receiving t Class { #name : #WDElementClickIntercepted, #superclass : #WDException, - #category : #WebDriver + #category : #'WebDriver-Exception' } + +{ #category : #testing } +WDElementClickIntercepted class >> matchesErrorCode: errCode [ + ^ errCode = 'element click intercepted' +] diff --git a/src/WebDriver/WDElementNotInteractable.class.st b/src/WebDriver/WDElementNotInteractable.class.st index a6d5242..0a679b5 100644 --- a/src/WebDriver/WDElementNotInteractable.class.st +++ b/src/WebDriver/WDElementNotInteractable.class.st @@ -4,5 +4,10 @@ A command could not be completed because the element is not pointer- or keyboard Class { #name : #WDElementNotInteractable, #superclass : #WDException, - #category : #WebDriver + #category : #'WebDriver-Exception' } + +{ #category : #testing } +WDElementNotInteractable class >> matchesErrorCode: errCode [ + ^ errCode = 'element not interactable' +] diff --git a/src/WebDriver/WDException.class.st b/src/WebDriver/WDException.class.st index fe66658..189463c 100644 --- a/src/WebDriver/WDException.class.st +++ b/src/WebDriver/WDException.class.st @@ -8,26 +8,32 @@ Class { 'stacktrace', 'data' ], - #category : #WebDriver + #category : #'WebDriver-Exception' } +{ #category : #testing } +WDException class >> matchesErrorCode: errCode [ + ^ self subclassResponsibility. +] + { #category : #signaling } WDException class >> raise: errDict [ + "Initializes and populates the appropriate exception class." - | error message stacktrace data | + + | errorClass error message stacktrace data | error := errDict at: #error. message := errDict at: #message. stacktrace := errDict at: #stacktrace. data := errDict at: #data ifAbsent: nil. - (error = 'element click intercepted') - ifTrue: [ ^ WDElementClickIntercepted new data: data; stacktrace: stacktrace; signal: message ]. - (error = 'element not interactable') - ifTrue: [ ^ WDElementNotInteractable new data: data; stacktrace: stacktrace; signal: message ]. - (error = 'insecure certificate') - ifTrue: [ ^ WDInsecureCertificate new data: data; stacktrace: stacktrace; signal: message ]. - (error = 'invalid selector') - ifTrue: [ ^ WDInvalidSelector new data: data; stacktrace: stacktrace; signal: message ]. - + errorClass := self subclasses + detect: [ :operationClass | + operationClass matchesErrorCode: error ] + ifNone: [ self ]. + ^ errorClass new + data: data; + stacktrace: stacktrace; + signal: message ] { #category : #accessing } diff --git a/src/WebDriver/WDInsecureCertificate.class.st b/src/WebDriver/WDInsecureCertificate.class.st index eb027ce..7573467 100644 --- a/src/WebDriver/WDInsecureCertificate.class.st +++ b/src/WebDriver/WDInsecureCertificate.class.st @@ -4,5 +4,10 @@ Navigation caused the user agent to hit a certificate warning, which is usually Class { #name : #WDInsecureCertificate, #superclass : #WDException, - #category : #WebDriver + #category : #'WebDriver-Exception' } + +{ #category : #testing } +WDInsecureCertificate class >> matchesErrorCode: errCode [ + ^ errCode = 'insecure certificate' +] diff --git a/src/WebDriver/WDInvalidArgument.class.st b/src/WebDriver/WDInvalidArgument.class.st new file mode 100644 index 0000000..817253e --- /dev/null +++ b/src/WebDriver/WDInvalidArgument.class.st @@ -0,0 +1,13 @@ +" +The arguments passed to a command are either invalid or malformed. +" +Class { + #name : #WDInvalidArgument, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDInvalidArgument class >> matchesErrorCode: errCode [ + ^ errCode = 'invalid argument' +] diff --git a/src/WebDriver/WDInvalidCookieDomain.class.st b/src/WebDriver/WDInvalidCookieDomain.class.st new file mode 100644 index 0000000..c145838 --- /dev/null +++ b/src/WebDriver/WDInvalidCookieDomain.class.st @@ -0,0 +1,13 @@ +" +An illegal attempt was made to set a cookie under a different domain than the current page. +" +Class { + #name : #WDInvalidCookieDomain, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDInvalidCookieDomain class >> matchesErrorCode: errCode [ + ^ errCode = 'invalid cookie domain' +] diff --git a/src/WebDriver/WDInvalidElementState.class.st b/src/WebDriver/WDInvalidElementState.class.st new file mode 100644 index 0000000..42b3ecc --- /dev/null +++ b/src/WebDriver/WDInvalidElementState.class.st @@ -0,0 +1,13 @@ +" +A command could not be completed because the element is in an invalid state, e.g. attempting to clear an element that isn’t both editable and resettable. +" +Class { + #name : #WDInvalidElementState, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDInvalidElementState class >> matchesErrorCode: errCode [ + ^ errCode = 'invalid element state' +] diff --git a/src/WebDriver/WDInvalidSelector.class.st b/src/WebDriver/WDInvalidSelector.class.st index 2850703..496658e 100644 --- a/src/WebDriver/WDInvalidSelector.class.st +++ b/src/WebDriver/WDInvalidSelector.class.st @@ -4,5 +4,10 @@ Argument was an invalid selector. Class { #name : #WDInvalidSelector, #superclass : #WDException, - #category : #WebDriver + #category : #'WebDriver-Exception' } + +{ #category : #testing } +WDInvalidSelector class >> matchesErrorCode: errCode [ + ^ errCode = 'invalid selector' +] diff --git a/src/WebDriver/WDInvalidSessionId.class.st b/src/WebDriver/WDInvalidSessionId.class.st new file mode 100644 index 0000000..7cda7fc --- /dev/null +++ b/src/WebDriver/WDInvalidSessionId.class.st @@ -0,0 +1,13 @@ +" +Occurs if the given session id is not in the list of active sessions, meaning the session either does not exist or that it’s not active. +" +Class { + #name : #WDInvalidSessionId, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDInvalidSessionId class >> matchesErrorCode: errCode [ + ^ errCode = 'invalid session id' +] diff --git a/src/WebDriver/WDJavascriptError.class.st b/src/WebDriver/WDJavascriptError.class.st new file mode 100644 index 0000000..dd73989 --- /dev/null +++ b/src/WebDriver/WDJavascriptError.class.st @@ -0,0 +1,13 @@ +" +An error occurred while executing JavaScript supplied by the user. +" +Class { + #name : #WDJavascriptError, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDJavascriptError class >> matchesErrorCode: errCode [ + ^ errCode = 'javascript error' +] diff --git a/src/WebDriver/WDMoveTargetOutOfBounds.class.st b/src/WebDriver/WDMoveTargetOutOfBounds.class.st new file mode 100644 index 0000000..927bdd8 --- /dev/null +++ b/src/WebDriver/WDMoveTargetOutOfBounds.class.st @@ -0,0 +1,13 @@ +" +The target for mouse interaction is not in the browser’s viewport and cannot be brought into that viewport. +" +Class { + #name : #WDMoveTargetOutOfBounds, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDMoveTargetOutOfBounds class >> matchesErrorCode: errCode [ + ^ errCode = 'move target out of bounds' +] diff --git a/src/WebDriver/WDNoSuchAlert.class.st b/src/WebDriver/WDNoSuchAlert.class.st new file mode 100644 index 0000000..33914bf --- /dev/null +++ b/src/WebDriver/WDNoSuchAlert.class.st @@ -0,0 +1,13 @@ +" +An attempt was made to operate on a modal dialog when one was not open. +" +Class { + #name : #WDNoSuchAlert, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDNoSuchAlert class >> matchesErrorCode: errCode [ + ^ errCode = 'no such alert' +] diff --git a/src/WebDriver/WDNoSuchCookie.class.st b/src/WebDriver/WDNoSuchCookie.class.st new file mode 100644 index 0000000..8aa2786 --- /dev/null +++ b/src/WebDriver/WDNoSuchCookie.class.st @@ -0,0 +1,13 @@ +" +No cookie matching the given path name was found amongst the associated cookies of the current browsing context’s active document. +" +Class { + #name : #WDNoSuchCookie, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDNoSuchCookie class >> matchesErrorCode: errCode [ + ^ errCode = 'no such cookie' +] diff --git a/src/WebDriver/WDNoSuchElement.class.st b/src/WebDriver/WDNoSuchElement.class.st new file mode 100644 index 0000000..afc3720 --- /dev/null +++ b/src/WebDriver/WDNoSuchElement.class.st @@ -0,0 +1,13 @@ +" +An element could not be located on the page using the given search parameters. +" +Class { + #name : #WDNoSuchElement, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDNoSuchElement class >> matchesErrorCode: errCode [ + ^ errCode = 'no such element' +] diff --git a/src/WebDriver/WDNoSuchFrame.class.st b/src/WebDriver/WDNoSuchFrame.class.st new file mode 100644 index 0000000..41020d6 --- /dev/null +++ b/src/WebDriver/WDNoSuchFrame.class.st @@ -0,0 +1,13 @@ +" +A command to switch to a frame could not be satisfied because the frame could not be found. +" +Class { + #name : #WDNoSuchFrame, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDNoSuchFrame class >> matchesErrorCode: errCode [ + ^ errCode = 'no such frame' +] diff --git a/src/WebDriver/WDNoSuchShadowRoot.class.st b/src/WebDriver/WDNoSuchShadowRoot.class.st new file mode 100644 index 0000000..8ef66b3 --- /dev/null +++ b/src/WebDriver/WDNoSuchShadowRoot.class.st @@ -0,0 +1,13 @@ +" +The element does not have a shadow root. +" +Class { + #name : #WDNoSuchShadowRoot, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDNoSuchShadowRoot class >> matchesErrorCode: errCode [ + ^ errCode = 'no such shadow root' +] diff --git a/src/WebDriver/WDNoSuchWindow.class.st b/src/WebDriver/WDNoSuchWindow.class.st new file mode 100644 index 0000000..998df79 --- /dev/null +++ b/src/WebDriver/WDNoSuchWindow.class.st @@ -0,0 +1,13 @@ +" +A command to switch to a window could not be satisfied because the window could not be found. +" +Class { + #name : #WDNoSuchWindow, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDNoSuchWindow class >> matchesErrorCode: errCode [ + ^ errCode = 'no such window' +] diff --git a/src/WebDriver/WDScriptTimeout.class.st b/src/WebDriver/WDScriptTimeout.class.st new file mode 100644 index 0000000..be6164f --- /dev/null +++ b/src/WebDriver/WDScriptTimeout.class.st @@ -0,0 +1,13 @@ +" +An operation did not complete before its timeout expired. +" +Class { + #name : #WDScriptTimeout, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDScriptTimeout class >> matchesErrorCode: errCode [ + ^ errCode = 'script timeout' +] diff --git a/src/WebDriver/WDSessionNotCreated.class.st b/src/WebDriver/WDSessionNotCreated.class.st new file mode 100644 index 0000000..09a050f --- /dev/null +++ b/src/WebDriver/WDSessionNotCreated.class.st @@ -0,0 +1,13 @@ +" +A new session could not be created. +" +Class { + #name : #WDSessionNotCreated, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDSessionNotCreated class >> matchesErrorCode: errCode [ + ^ errCode = 'session not created' +] diff --git a/src/WebDriver/WDStaleElementReference.class.st b/src/WebDriver/WDStaleElementReference.class.st new file mode 100644 index 0000000..56dd9e6 --- /dev/null +++ b/src/WebDriver/WDStaleElementReference.class.st @@ -0,0 +1,13 @@ +" +A command failed because the referenced element is no longer attached to the DOM. +" +Class { + #name : #WDStaleElementReference, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDStaleElementReference class >> matchesErrorCode: errCode [ + ^ errCode = 'stale element reference' +] diff --git a/src/WebDriver/WDTimeout.class.st b/src/WebDriver/WDTimeout.class.st new file mode 100644 index 0000000..cec7056 --- /dev/null +++ b/src/WebDriver/WDTimeout.class.st @@ -0,0 +1,13 @@ +" +An operation did not complete before its timeout expired. +" +Class { + #name : #WDTimeout, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDTimeout class >> matchesErrorCode: errCode [ + ^ errCode = 'timeout' +] diff --git a/src/WebDriver/WDUnableToCaptureScreen.class.st b/src/WebDriver/WDUnableToCaptureScreen.class.st new file mode 100644 index 0000000..27ba10f --- /dev/null +++ b/src/WebDriver/WDUnableToCaptureScreen.class.st @@ -0,0 +1,13 @@ +" +A screen capture was made impossible. +" +Class { + #name : #WDUnableToCaptureScreen, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDUnableToCaptureScreen class >> matchesErrorCode: errCode [ + ^ errCode = 'unable to capture screen' +] diff --git a/src/WebDriver/WDUnableToSetCookie.class.st b/src/WebDriver/WDUnableToSetCookie.class.st new file mode 100644 index 0000000..a5bb1c6 --- /dev/null +++ b/src/WebDriver/WDUnableToSetCookie.class.st @@ -0,0 +1,13 @@ +" +A command to set a cookie’s value could not be satisfied. +" +Class { + #name : #WDUnableToSetCookie, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDUnableToSetCookie class >> matchesErrorCode: errCode [ + ^ errCode = 'unable to set cookie' +] diff --git a/src/WebDriver/WDUnexpectedAlertOpen.class.st b/src/WebDriver/WDUnexpectedAlertOpen.class.st new file mode 100644 index 0000000..885435b --- /dev/null +++ b/src/WebDriver/WDUnexpectedAlertOpen.class.st @@ -0,0 +1,13 @@ +" +A modal dialog was open, blocking this operation. +" +Class { + #name : #WDUnexpectedAlertOpen, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDUnexpectedAlertOpen class >> matchesErrorCode: errCode [ + ^ errCode = 'unexpected alert open' +] diff --git a/src/WebDriver/WDUnknownCommand.class.st b/src/WebDriver/WDUnknownCommand.class.st new file mode 100644 index 0000000..94a33c6 --- /dev/null +++ b/src/WebDriver/WDUnknownCommand.class.st @@ -0,0 +1,13 @@ +" +A command could not be executed because the remote end is not aware of it. +" +Class { + #name : #WDUnknownCommand, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDUnknownCommand class >> matchesErrorCode: errCode [ + ^ errCode = 'unknown command' +] diff --git a/src/WebDriver/WDUnknownError.class.st b/src/WebDriver/WDUnknownError.class.st new file mode 100644 index 0000000..3577604 --- /dev/null +++ b/src/WebDriver/WDUnknownError.class.st @@ -0,0 +1,13 @@ +" +An unknown error occurred in the remote end while processing the command. +" +Class { + #name : #WDUnknownError, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDUnknownError class >> matchesErrorCode: errCode [ + ^ errCode = 'unknown error' +] diff --git a/src/WebDriver/WDUnknownMethod.class.st b/src/WebDriver/WDUnknownMethod.class.st new file mode 100644 index 0000000..77cfdcf --- /dev/null +++ b/src/WebDriver/WDUnknownMethod.class.st @@ -0,0 +1,13 @@ +" +The requested command matched a known URL but did not match any method for that URL. +" +Class { + #name : #WDUnknownMethod, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDUnknownMethod class >> matchesErrorCode: errCode [ + ^ errCode = 'unknown method' +] diff --git a/src/WebDriver/WDUnsupportedOperation.class.st b/src/WebDriver/WDUnsupportedOperation.class.st new file mode 100644 index 0000000..5877928 --- /dev/null +++ b/src/WebDriver/WDUnsupportedOperation.class.st @@ -0,0 +1,13 @@ +" +Indicates that a command that should have executed properly cannot be supported for some reason. +" +Class { + #name : #WDUnsupportedOperation, + #superclass : #WDException, + #category : #'WebDriver-Exception' +} + +{ #category : #testing } +WDUnsupportedOperation class >> matchesErrorCode: errCode [ + ^ errCode = 'unsupported operation' +] diff --git a/src/WebDriver/WebDriver.class.st b/src/WebDriver/WebDriver.class.st index 3addcb9..3563a9c 100644 --- a/src/WebDriver/WebDriver.class.st +++ b/src/WebDriver/WebDriver.class.st @@ -1,5 +1,5 @@ " -I am a cleanroom implementation of the W3C WebDriver protocol. +I am a cleanroom implementation of the [W3C WebDriver protocol](https://w3c.github.io/webdriver/). Please comment me using the following template inspired by Class Responsibility Collaborator (CRC) design: @@ -36,8 +36,7 @@ Class { 'browser', 'server', 'port', - 'sessionId', - 'optionsName' + 'sessionId' ], #category : #WebDriver } @@ -51,8 +50,7 @@ WebDriver class >> geckodriver [ ^ WebDriverGeckodriver new browser: subproc server: '127.0.0.1' - port: 4444 - optionsName: #moz:firefoxOptions. + port: 4444. ] { #category : #accessing } @@ -73,12 +71,11 @@ WebDriver >> back [ ] { #category : #initialization } -WebDriver >> browser: brs server: srv port: portnum optionsName: optName [ +WebDriver >> browser: brs server: srv port: portnum [ browser := brs. server := srv. port := portnum. - optionsName := optName ] { #category : #'event handling' } @@ -177,7 +174,7 @@ WebDriver >> session [ sessionId ifNil: [ sessionId := (self - send: (self constructCapabilities: { }) + send: (self constructCapabilities: { } asDictionary) to: 'session' using: #POST) at: #sessionId ]. ^ sessionId diff --git a/src/WebDriver/WebDriverGeckodriver.class.st b/src/WebDriver/WebDriverGeckodriver.class.st index 9679768..2699d8e 100644 --- a/src/WebDriver/WebDriverGeckodriver.class.st +++ b/src/WebDriver/WebDriverGeckodriver.class.st @@ -10,10 +10,10 @@ Class { { #category : #'private - utilities' } WebDriverGeckodriver >> constructCapabilities: caps [ - ^ { (#desiredCapabilities + ^ { #desiredCapabilities -> - { (optionsName -> { (#prefs -> caps) } asDictionary) } - asDictionary) } + ({ #moz:firefoxOptions -> ({ #prefs -> caps } asDictionary) } + asDictionary) } asDictionary. ] { #category : #navigation }