Skip to content

Commit

Permalink
version update
Browse files Browse the repository at this point in the history
General "house cleaning" update...
Refactored WebDriverManager class:
    - Incorporated recently published ChromeDriver release end-points that do not require json parsing
    - Added "channel" argument to GetLatestDriverVersion method [@6DiegoDiego9]
    - Improved use of RegExp for searching/parsing
    - General code cleanup
Reviewed object instantiation:
    - Removed New_WebElement & New_WebShadowRoot methods of ClassFactory class - these cannot be instantiated with New keyword
    - Bug fix: if WebElements class is instantiated with New and element objects added with Add method, Highlight and UnHighlight fail
    - Added example in test_Highlight module to test above bug fix
    - Set class attribute VB_Creatable = False in DLL for all classes that cannot be instantiated with New
    - Added table to "Object Instantiation" section of Wiki summarizing means of instantiation for each class
Removed all DEPRECATED methods/properties (see #86)
Renamed GetAlertText method of WebAlert class to GetText
Changed RemoveAll method of WebCookies and WebElements classes from Friend to Public to be consistent with associated Public Remove methods in same classes
Bug fix: new (default) Json Viewer feature of Edge browser broke PageToJson* methods - now supported
Added SwitchTo method to WebWindow class (synonym for Activate method)
Replaced all instantiations of WebJsonConverter object with predeclared reference [@6DiegoDiego9]
Modified test modules code for all of above
DLL installer now checks for 64-bit Office and reports to user if not [private email from user]
Replaced BuildAddin.xlsm in dev\tools with a refactored and more complete UpdateVersion.xlsm
Updated Readme files, Wiki Help topics, and Object Model Overview
Minor code cleanups
  • Loading branch information
GCuser99 committed Sep 9, 2023
1 parent 8a7f0fe commit 7ffc042
Show file tree
Hide file tree
Showing 38 changed files with 478 additions and 547 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.bas text eol=crlf linguist-language=VBA
*.cls text eol=crlf linguist-language=VBA
*.frm linguist-language=VBA
*.vbs text eol=crlf linguist-language=VBScript
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A comprehensive Selenium wrapper for browser automation developed for MS Office
- Improved JavaScript Alert management with WebAlert class and SwitchToAlert method of WebDriver class
- Advanced keys support including Chord and Repeat methods of the WebKeyboard class
- Improved SendKeys and new SendKeysToOS methods - the later for sending key inputs to non-browser windows
- ExecuteCDP method exposing Chrome DevTools Protocol - a low-level interface for browser interaction.
- ExecuteCDP method exposing [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) - a low-level interface for browser interaction.

## Setup

Expand Down
Binary file removed dev/tools/BuildAddin.xlsm
Binary file not shown.
Binary file added dev/tools/UpdateVersion.xlsm
Binary file not shown.
2 changes: 1 addition & 1 deletion dev/tools/readme.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The BuildAddin.xlsm provides functionality for (re)building the SeleniumVBA.xlam macro file and for publishing GitHub components (source, zip file, etc). Advanced knowledge of working with GitHub Desktop and the VBIDE object model is required. Please note if all that is needed is a copy of SeleniumVBA.xlam, then download the xlam (or zip) file from the "dist" folder. The macro provided here is intended to make life easier for contributors/collaborators - modify as you see fit.
The UpdateVersion.xlsm macro Workbook provides functionality for (re)building the SeleniumVBA.xlam and SeleniumVBA.accdb macro files and for publishing GitHub components (source, zip file, etc). Advanced knowledge of working with GitHub Desktop and the VBIDE object model is required. Please note if all that is needed is a copy of SeleniumVBA.xlam, then download the xlam file from the "dist" folder. The macros provided here are intended to make life easier for contributors/collaborators. I have spent little effort making this user-friendly - modify as you see fit.
Binary file not shown.
Binary file not shown.
Binary file modified dev/twinBasic/no_registration/SeleniumVBA_win64.dll
Binary file not shown.
Binary file modified dist/SeleniumVBA.accdb
Binary file not shown.
Binary file modified dist/SeleniumVBA.xlam
Binary file not shown.
Binary file modified dist/SeleniumVBADLLSetup.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions dist/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Below is a table showing the compatibility for each solution with various versio
|Access DB|Not|32/64-bit|32/64-bit|32/64-bit|32/64-bit|32/64-bit|
|ActiveX DLL*|Not|64-bit Only|64-bit Only|64-bit Only|64-bit Only|64-bit Only|

*the ActiveX DLL can be called from MS VBScript, as well as MS Excel and MS Access
*the [twinBASIC](https://twinbasic.com) ActiveX DLL can be called from MS VBScript, as well as MS Excel and MS Access

### Excel Add-in and Access DB Installation:

Expand All @@ -31,9 +31,9 @@ Instructions for referencing add-in versions of SeleniumVBA from another MS Exce

### ActiveX DLL Installation:

For the ActiveX DLL, more detailed instructions on how to install and use the DLL will be presented during installation. The setup program, which was compiled using Inno Setup, will install and register the DLL, and copy test Excel, Access, and VBScript documents to the installation folder. After installation, be aware that when it is first called during a VBA session, SeleniumVBA will display a "twinBASIC" banner for 5 seconds. Subsequent calls during the session will not show the banner.
For the [twinBASIC](https://twinbasic.com) ActiveX DLL, more detailed instructions on how to install and use the DLL will be presented during installation. The setup program, which was compiled using Inno Setup, will install and register the DLL, and copy test Excel, Access, and VBScript documents to the installation folder. After installation, be aware that when it is first called during a VBA session, SeleniumVBA will display a "twinBASIC" banner for 5 seconds. Subsequent calls during the session will not show the banner.

The ActiveX DLL solution requires no dependencies (such as .Net Framework).
The [twinBASIC](https://twinbasic.com) ActiveX DLL solution requires no dependencies (such as .Net Framework).

### Advanced Customization - SeleniumVBA.ini File:

Expand Down
28 changes: 9 additions & 19 deletions src/ClassFactory.bas
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Attribute VB_Description = "This class is used for object instantiation when ref
'@ModuleDescription "This class is used for object instantiation when referencing SeleniumVBA externally from another code project"
'@folder("SeleniumVBA.Source")
' ==========================================================================
' SeleniumVBA v4.5
' SeleniumVBA v4.6
'
' A Selenium wrapper for browser automation developed for MS Office VBA
'
Expand Down Expand Up @@ -56,31 +56,27 @@ Option Explicit
'new WebCookies should be instantiated from WebDriver.CreateCookies
'new WebWindow should be instantiated from WebDriver.ActiveWindow or from one of the methods in WebWindows object
'new WebWindows should be instantiated from WebDriver.Windows
'new WebElement should be instantiated from WebDriver.FindElement*
'new WebShadowRoot should be instantiated from WebDriver.GetWebShadowRoot

'@Description("Instantiates a WebDriver object")
Public Function New_WebDriver() As WebDriver
Attribute New_WebDriver.VB_Description = "Instantiates a WebDriver object"
Set New_WebDriver = New WebDriver
End Function

'@Description("Instantiates a WebDriverManager object")
Public Function New_WebDriverManager() As WebDriverManager
Attribute New_WebDriverManager.VB_Description = "Instantiates a WebDriverManager object"
Set New_WebDriverManager = New WebDriverManager
End Function

'@Description("Instantiates a WebElement object")
Public Function New_WebElement() As WebElement
Attribute New_WebElement.VB_Description = "Instantiates a WebElement object"
Set New_WebElement = New WebElement
End Function

'@Description("Instantiates a WebElements object")
Public Function New_WebElements() As WebElements
Attribute New_WebElements.VB_Description = "Instantiates a WebElements object"
Set New_WebElements = New WebElements
End Function

'@Description("Instantiates a WebDriverManager object")
Public Function New_WebDriverManager() As WebDriverManager
Attribute New_WebDriverManager.VB_Description = "Instantiates a WebDriverManager object"
Set New_WebDriverManager = New WebDriverManager
End Function

'@Description("Instantiates a WebCookie object")
Public Function New_WebCookie() As WebCookie
Attribute New_WebCookie.VB_Description = "Instantiates a WebCookie object"
Expand All @@ -104,9 +100,3 @@ Public Function New_WebPrintSettings() As WebPrintSettings
Attribute New_WebPrintSettings.VB_Description = "Instantiates a WebPrintSettings object"
Set New_WebPrintSettings = New WebPrintSettings
End Function

'@Description("Instantiates a WebShadowRoot object")
Public Function New_WebShadowRoot() As WebShadowRoot
Attribute New_WebShadowRoot.VB_Description = "Instantiates a WebShadowRoot object"
Set New_WebShadowRoot = New WebShadowRoot
End Function
2 changes: 1 addition & 1 deletion src/WebActionChain.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Attribute VB_Description = "This class is used to emulate a human interaction se
'@Exposed
'@folder("SeleniumVBA.Source")
' ==========================================================================
' SeleniumVBA v4.5
' SeleniumVBA v4.6
'
' A Selenium wrapper for browser automation developed for MS Office VBA
'
Expand Down
10 changes: 5 additions & 5 deletions src/WebAlert.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Attribute VB_Description = "This class is used to manage browser alerts - must b
'@Exposed
'@folder("SeleniumVBA.Source")
' ==========================================================================
' SeleniumVBA v4.5
' SeleniumVBA v4.6
'
' A Selenium wrapper for browser automation developed for MS Office VBA
'
Expand Down Expand Up @@ -59,10 +59,10 @@ Private tCMD As typCMD

Private driver_ As WebDriver

'@Description("Returns the text prompt of the active alert")
Public Function GetAlertText() As String
Attribute GetAlertText.VB_Description = "Returns the text prompt of the active alert"
GetAlertText = driver_.execute(tCMD.CMD_GET_ALERT_TEXT)("value")
'@Description("Returns the prompt text of the active alert")
Public Function GetText() As String
Attribute GetText.VB_Description = "Returns the prompt text of the active alert"
GetText = driver_.execute(tCMD.CMD_GET_ALERT_TEXT)("value")
End Function

'@Description("Sends the specified text to the active prompt-type alert - Selenium special keys not recognized for alerts")
Expand Down
24 changes: 9 additions & 15 deletions src/WebCapabilities.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Attribute VB_Description = "This class is used to manage/set Selenium optional C
'@Exposed
'@folder("SeleniumVBA.Source")
' ==========================================================================
' SeleniumVBA v4.5
' SeleniumVBA v4.6
'
' A Selenium wrapper for browser automation developed for MS Office VBA
'
Expand Down Expand Up @@ -104,8 +104,7 @@ Attribute SetCapability.VB_Description = "Sets a generic capability"
Set data_.Item("alwaysMatch")(key) = val
Else
If Left$(val, 1) = "[" Or Left$(val, 1) = "{" Then 'its a json string - try to parse
Dim jc As New WebJsonConverter
Set data_.Item("alwaysMatch")(key) = jc.ParseJson(val)
Set data_.Item("alwaysMatch")(key) = WebJsonConverter.ParseJson(val)
Else 'its a string parameter
data_.Item("alwaysMatch")(key) = val
End If
Expand Down Expand Up @@ -139,8 +138,7 @@ Attribute SetOption.VB_Description = "Sets an option key/value"
data_.Item("alwaysMatch")(browserOptionKey)(key) = val
Else 'string
If Left$(val, 1) = "[" Or Left$(val, 1) = "{" Then 'its a json string - try to parse
Dim jc As New WebJsonConverter
Set data_.Item("alwaysMatch")(browserOptionKey)(key) = jc.ParseJson(val)
Set data_.Item("alwaysMatch")(browserOptionKey)(key) = WebJsonConverter.ParseJson(val)
Else 'its a string parameter
data_.Item("alwaysMatch")(browserOptionKey)(key) = val
End If
Expand Down Expand Up @@ -331,8 +329,7 @@ Attribute SetPreference.VB_Description = "Sets an option preference key/value"
Else
If Left$(val, 1) = "[" Or Left$(val, 1) = "{" Then 'it's json string - try to parse
'convert to dictionary or collection
Dim jc As New WebJsonConverter
Set data_.Item("alwaysMatch")(browserOptionKey)("prefs")(key) = jc.ParseJson(val)
Set data_.Item("alwaysMatch")(browserOptionKey)("prefs")(key) = WebJsonConverter.ParseJson(val)
Else
data_.Item("alwaysMatch")(browserOptionKey)("prefs")(key) = val
End If
Expand Down Expand Up @@ -403,8 +400,7 @@ End Function
'@Description("Returns Json string for qc")
Public Function ToJson() As String
Attribute ToJson.VB_Description = "Returns Json string for qc"
Dim jc As New WebJsonConverter
ToJson = jc.ConvertToJson(data_, 4)
ToJson = WebJsonConverter.ConvertToJson(data_, 4)
End Function

'@Description("Saves the capabilities to file path")
Expand All @@ -423,14 +419,13 @@ Public Sub LoadFromFile(Optional ByVal filePath As String = ".\capabilities.json
Attribute LoadFromFile.VB_Description = "Loads the capabilities from file path"
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim jc As New WebJsonConverter

filePath = WebShared.getFullLocalPath(filePath, driver_.DefaultIOFolder)

If Not fso.FileExists(filePath) Then Err.Raise 53, "WebCapabilities", "Capabilities Json file does not exist:" & vbNewLine & vbNewLine & filePath
'note that this will fail if input file format is utf-8 with non-ascii chars - see https://github.com/GCuser99/SeleniumVBA/discussions/32
Set ts = fso.OpenTextFile(filePath, , , TristateUseDefault)
Set data_ = jc.ParseJson(ts.ReadAll)
Set data_ = WebJsonConverter.ParseJson(ts.ReadAll)
ts.Close

If data_.Item("browserName") <> WebShared.getBrowserNameString(browser_) Then Err.Raise 1, "WebCapabilities", "Browser name from file does not match browser name assigned to driver instance."
Expand Down Expand Up @@ -491,7 +486,7 @@ Private Sub addToOptionList(ByVal optionName As String, addList() As String)
Dim j As Integer
Dim i As Integer

'lists are represented as collections for caps initialized from LoadFromFile (via jc.ParseJson)
'lists are represented as collections for caps initialized from LoadFromFile (via WebJsonConverter.ParseJson)
If IsObject(data_.Item("alwaysMatch")(browserOptionKey)(optionName)) Then
Set parameters = data_.Item("alwaysMatch")(browserOptionKey)(optionName)
Else 'starting from scratch
Expand Down Expand Up @@ -525,8 +520,7 @@ Private Function paramListToStringArray(parmList() As Variant) As String()
k = k + UBound(parmList(i)) - LBound(parmList(i)) + 1
Else
If Left$(parmList(i), 1) = "[" Then 'its a json string - try to parse
Dim jc As New WebJsonConverter
k = k + jc.ParseJson(parmList(i)).Count
k = k + WebJsonConverter.ParseJson(parmList(i)).Count
Else 'its a string parameter
k = k + 1
End If
Expand All @@ -547,7 +541,7 @@ Private Function paramListToStringArray(parmList() As Variant) As String()
Else
If Left$(parmList(i), 1) = "[" Then 'its a json string
Dim col As Collection
Set col = jc.ParseJson(parmList(i))
Set col = WebJsonConverter.ParseJson(parmList(i))
For j = 1 To col.Count
k = k + 1
strlist(k) = col.Item(j)
Expand Down
2 changes: 1 addition & 1 deletion src/WebCookie.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Attribute VB_Description = "This class is used to manage/modify a cookie object"
'@Exposed
'@folder("SeleniumVBA.Source")
' ==========================================================================
' SeleniumVBA v4.5
' SeleniumVBA v4.6
'
' A Selenium wrapper for browser automation developed for MS Office VBA
'
Expand Down
12 changes: 6 additions & 6 deletions src/WebCookies.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Attribute VB_Description = "This class is used to manage a collection of cookie
'@Exposed
'@folder("SeleniumVBA.Source")
' ==========================================================================
' SeleniumVBA v4.5
' SeleniumVBA v4.6
'
' A Selenium wrapper for browser automation developed for MS Office VBA
'
Expand Down Expand Up @@ -118,14 +118,13 @@ Attribute SaveToFile.VB_Description = "Saves the cookie collection to a file pat
Dim ts As TextStream
Dim darray() As Dictionary
Dim i As Long
Dim jc As New WebJsonConverter
filePath = WebShared.getFullLocalPath(filePath, driver_.DefaultIOFolder)
Set ts = fso.CreateTextFile(filePath, True, True)
ReDim darray(1 To Me.Count)
For i = 1 To Me.Count
Set darray(i) = Me.Item(i).ToDictionary
Next i
ts.Write jc.ConvertToJson(darray(), 4)
ts.Write WebJsonConverter.ConvertToJson(darray(), 4)
ts.Close
End Sub

Expand All @@ -137,7 +136,6 @@ Attribute LoadFromFile.VB_Description = "Loads the cookie collection from a file
Dim str As String
Dim v As Collection
Dim ck As WebCookie
Dim jc As New WebJsonConverter

Me.RemoveAll

Expand All @@ -146,7 +144,7 @@ Attribute LoadFromFile.VB_Description = "Loads the cookie collection from a file
Set ts = fso.OpenTextFile(filePath, , , TristateUseDefault)
str = ts.ReadAll
ts.Close
Set v = jc.ParseJson(str)
Set v = WebJsonConverter.ParseJson(str)

Dim i As Long
For i = 1 To v.Count
Expand All @@ -170,7 +168,9 @@ Attribute NewEnum.VB_UserMemId = -4
Set NewEnum = colCookie.[_NewEnum]
End Function

Friend Sub RemoveAll()
'@Description("Removes all member cookie objects from the collection")
Public Sub RemoveAll()
Attribute RemoveAll.VB_Description = "Removes all member cookie objects from the collection"
Do While colCookie.Count > 0
colCookie.Remove 1
Loop
Expand Down
Loading

1 comment on commit 7ffc042

@6DiegoDiego9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, another great update!
Thank you so much Mike!

Please sign in to comment.