Danp2 / au3WebDriver

Web Driver UDF for AutoIt
MIT License
107 stars 21 forks source link

_WD_UpdateDriver: Support webdriver downgrades #479

Closed Danp2 closed 1 year ago

Danp2 commented 1 year ago

Pull request

Proposed changes

Add ability to detect mismatches between web browser and the webdriver.

Checklist

Put an x in the boxes that apply. If you're unsure about any of them, don't hesitate to ask. We are here to help!
This is simply a reminder of what we are going to look for before merging your code.

Types of changes

Please check x the type of change your PR introduces:

What is the current behavior?

No option to downgrade web driver and no notification of mismatch.

What is the new behavior?

Additional context

Add any other context about the problem here.

System under test

Please complete the following information.

Danp2 commented 1 year ago

This is the script I used for testing --

#include "wd_helper.au3"
#include "wd_core.au3"

$sBrowser = 'chrome'
$sInstallDir = Default ; Update this as needed to match your environment

$bResult = _WD_UpdateDriver($sBrowser, $sInstallDir, Default, Null)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)

$bResult = _WD_UpdateDriver($sBrowser, $sInstallDir, Default, Null, True)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)

$bResult = _WD_UpdateDriver($sBrowser, $sInstallDir)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)

$bResult = _WD_UpdateDriver($sBrowser, $sInstallDir, Default, Default, True)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)

The following is the output when starting with Chromedriver version of 115.0.5790.13 and Chrome version of 114.0.5735.110 --

    _WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 115.0.5790.13 : DriverLatest = 114.0.5735.90
    @@ Debug(7) : $bResult = False
    >Error code: 0
    _WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 115.0.5790.13 : DriverLatest = 114.0.5735.90
    @@ Debug(11) : $bResult = True
    >Error code: 0
    _WD_UpdateDriver ==> Version mismatch [24 / 0] : DriverCurrent = 115.0.5790.13 : DriverLatest = 114.0.5735.90
    @@ Debug(15) : $bResult = False
    >Error code: 24
    _WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 115.0.5790.13 : DriverLatest = 114.0.5735.90
    @@ Debug(19) : $bResult = True
    >Error code: 0

After running the above, the version of Chromedriver has been downgraded to 114.0.5735.90

itplainedge commented 1 year ago

I ran this after uninstalling my newer chrome and installing an older chrome to test it out but the console results doesn't match yours. There seems to still be a problem: (Notice I have Chrome 32 bit version 103.0.5060.134 installed as a test and have the latest version 114.0.5735.90 of the chrome driver installed on the PC yet it's not showing the current version of the chrome driver found in the folder that it's using) Shouldn't it say something like Brower = 103.0.5060.134 and DriverCurrent =114.0.5735.90 as well as knowing what he latest driver available is DriverLastest = 114.0.5735.90?

_WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 103.0.5060.134 : DriverLatest = 103.0.5060.134
@@ Debug(9) : $bResult = False
>Error code: 0
_WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 103.0.5060.134 : DriverLatest = 103.0.5060.134
@@ Debug(13) : $bResult = False
>Error code: 0
_WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 103.0.5060.134 : DriverLatest = 103.0.5060.134
@@ Debug(17) : $bResult = False
>Error code: 0
_WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 103.0.5060.134 : DriverLatest = 103.0.5060.134
@@ Debug(21) : $bResult = False
>Error code: 0
Danp2 commented 1 year ago

@itplainedge DriverCurrent is the version of the locally installed webdriver. DriverLatest is the version of the remote webdriver that matches your installed browser.

If you ran this code previously, then the newer copy of Chromedriver was overwritten by the v103 one. Please double check the version in the script directory and replace with the v114 copy as needed. Then retest. 😉

itplainedge commented 1 year ago

OK thanks for that clarification. With that it still seems that it's incrorectly extracting the version of the locally installed webdriver since I have 3 chromedrivers I'm testing:

chromedriver-v103.exe chromedriver-v114.exe chromedriver.exe (the timestamp and size still matches the latest v114) so I don't think it was automatically updated by any processes. This is the one that the autoit script is using.

I normally create a subfolder called @ScriptDir & "\Required" which hosts the chromedriver and the UDF I see that for some reason it downloaded the older version and put it in the @ScriptDir which is not how I wanted it working. Here is the code I used which only had the in the root :

#include "./Required/wd_helper.au3"
#include "./Required/wd_core.au3"

MsgBox(0, "Version", @AutoItVersion)

$sBrowser = 'chrome'
$bResult = _WD_UpdateDriver($sBrowser, Default, Default, Null)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)

$bResult = _WD_UpdateDriver($sBrowser, Default, Default, Null, True)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)

$bResult = _WD_UpdateDriver($sBrowser)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)

$bResult = _WD_UpdateDriver($sBrowser, Default, Default, Default, True)
;### Debug CONSOLE ↓↓↓
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bResult = ' & $bResult & @CRLF & '>Error code: ' & @error & @CRLF)
Danp2 commented 1 year ago

Hold on time out I see a version in the root. Let me look into that. I normally create a subfolder called Required...

That likely came from running my test script above. You can use the $sInstallDir parameter to specify an alt-location. Otherwise, it uses @scriptdir.

itplainedge commented 1 year ago

OK great I'll look to see about that. That sounds simple enough. I think for my app on server situation where different users PC's have different versions of chrome. I'll have to somehow instead have the UDF save the chromedrivers with different version numbers so each user's running of the script on their PC will know which webdriver to open without having a single chromedriver.exe that all users use.

Danp2 commented 1 year ago

FWIW, I updated the original code posted above to allow easier updates to the install directory.

itplainedge commented 1 year ago

Great, I got your code working. When I get time I'll revisit the way that I'm handling each users Chrome installation. In the educational DeepFreeze virtualization environment I'm working with, it's so much easier to run and keep Autoit app and data on the server. It also allows my users to tell me when they have an outdated browser via this Webdriver functionality since I'm the one that is doing the update on all the machines only when necessary. It's also easier to update a single app on a server than making sure every machine has the correct app version with all the tweaks I keep adding. 95% of my other apps I don't tweak as often. Make sense?