From b6209258c11095adb425c5111dd05e8a244592ff Mon Sep 17 00:00:00 2001 From: Daniel Ziltener Date: Wed, 27 Apr 2022 02:19:19 +0200 Subject: [PATCH] Capabilities support for Firefox --- src/WebDriver/WDException.class.st | 2 +- src/WebDriver/WDInsecureCertificate.class.st | 3 + src/WebDriver/WebDriver.class.st | 61 ++++++++++++++++++-- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/WebDriver/WDException.class.st b/src/WebDriver/WDException.class.st index 5d7e526..fe66658 100644 --- a/src/WebDriver/WDException.class.st +++ b/src/WebDriver/WDException.class.st @@ -11,7 +11,7 @@ Class { #category : #WebDriver } -{ #category : #'as yet unclassified' } +{ #category : #signaling } WDException class >> raise: errDict [ "Initializes and populates the appropriate exception class." | error message stacktrace data | diff --git a/src/WebDriver/WDInsecureCertificate.class.st b/src/WebDriver/WDInsecureCertificate.class.st index e7dd32c..eb027ce 100644 --- a/src/WebDriver/WDInsecureCertificate.class.st +++ b/src/WebDriver/WDInsecureCertificate.class.st @@ -1,3 +1,6 @@ +" +Navigation caused the user agent to hit a certificate warning, which is usually the result of an expired or invalid TLS certificate. +" Class { #name : #WDInsecureCertificate, #superclass : #WDException, diff --git a/src/WebDriver/WebDriver.class.st b/src/WebDriver/WebDriver.class.st index f8014b9..e0d8c07 100644 --- a/src/WebDriver/WebDriver.class.st +++ b/src/WebDriver/WebDriver.class.st @@ -6,7 +6,8 @@ Class { 'server', 'port', 'sessionId', - 'parameters' + 'parameters', + 'optionsName' ], #category : #WebDriver } @@ -17,10 +18,11 @@ WebDriver class >> geckodriver [ subproc := OSSUnixSubprocess new command: 'geckodriver'. [ subproc run ] fork. - ^ self new + ^ self new browser: subproc server: '127.0.0.1' - port: 4444. + port: 4444 + optionsName: #moz:firefoxOptions. ] { #category : #accessing } @@ -29,7 +31,6 @@ WebDriver >> attribute: attr from: element [ to: 'session/',sessionId,'/element/',element,'/attribute/',attr using: #GET) at: #value. - ] { #category : #navigation } @@ -44,6 +45,14 @@ WebDriver >> browser: brs server: srv port: portnum [ port := portnum. ] +{ #category : #initialization } +WebDriver >> browser: brs server: srv port: portnum optionsName: optName [ + browser := brs. + server := srv. + port := portnum. + optionsName := optName. +] + { #category : #finalization } WebDriver >> deleteSession [ "Deletes the session." @@ -85,6 +94,17 @@ 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) at: #value +] + { #category : #navigation } WebDriver >> refresh [ self send: { } to: 'session/',sessionId,'/refresh' using: #POST. @@ -103,8 +123,6 @@ WebDriver >> send: dict to: url using: method [ method: method; contentReader: [ :entity | result := (NeoJSONReader on: (entity contents) readStream) propertyNamesAsSymbols: true; next. - "(result at: #error ifPresent: [ true ] ifAbsent: [ false ]) - ifTrue: [ result := WDException raise: result ]" ]; execute. ^result. @@ -118,6 +136,27 @@ WebDriver >> session [ ^sessionId. ] +{ #category : #accessing } +WebDriver >> session: capabilities [ + + sessionId ifNotNil: [ ^ self session ] ifNil: [ + sessionId := (self + send: { #desiredCapabilities -> ({ optionsName -> ({#prefs -> capabilities}) asDictionary } asDictionary) } + to: 'session' + using: #POST) at: #value at: #sessionId. + ^ sessionId ] +] + +{ #category : #accessing } +WebDriver >> source [ + + ^ (self + send: { } + to: + 'session/' , sessionId , '/source' + using: #GET) at: #value +] + { #category : #accessing } WebDriver >> status [ ^ (self send: { } to: 'status' using: #GET) at: #value. @@ -133,6 +172,16 @@ WebDriver >> type: text into: element [ self send: { #text -> text } to: 'session/',sessionId,'/element/',element,'/value' using: #POST. ] +{ #category : #accessing } +WebDriver >> url [ + + ^ (self + send: { } + to: + 'session/' , sessionId , '/url' + using: #GET) at: #value +] + { #category : #navigation } WebDriver >> url: url [ "Navigates the browser to the given URL."