diff --git a/.build.ps1 b/.build.ps1 index 081b62c..2b6de6c 100644 --- a/.build.ps1 +++ b/.build.ps1 @@ -2,7 +2,10 @@ Task 'Build' Selenium, { } Task 'Selenium' { if (Test-Path ./src/lib) { - Remove-Item -Path ./src/lib -Force -Recurse -ErrorAction Stop | Out-Null + Remove-Item -Path ./src/lib/WebDriver -Force -Recurse -ErrorAction Ignore | Out-Null + Remove-Item -Path ./src/lib/Browsers/*/chromedriver* -Force -Recurse -ErrorAction Stop | Out-Null + Remove-Item -Path ./src/lib/Browsers/*/geckodriver* -Force -Recurse -ErrorAction Stop | Out-Null + Remove-Item -Path ./src/lib/Browsers/*/IEDriverServer* -Force -Recurse -ErrorAction Stop | Out-Null } if (Test-Path ./temp) { @@ -12,9 +15,9 @@ Task 'Selenium' { $packages = @{ 'Selenium.WebDriver' = '3.141.0' 'Selenium.Support' = '3.141.0' - 'Selenium.WebDriver.ChromeDriver' = '80.0.3987.1600' + 'Selenium.WebDriver.ChromeDriver' = '83.0.4103.3900' 'Selenium.WebDriver.IEDriver' = '3.150.1' - 'Selenium.WebDriver.GeckoDriver' = '0.26.0' + 'Selenium.WebDriver.GeckoDriver' = '0.26.0.1' } $packages.Keys | ForEach-Object { @@ -38,7 +41,6 @@ Task 'Selenium' { New-Item -Path ./src/lib/Browsers/mac -ItemType Directory -Force | Out-Null # win - "./temp/Selenium.WebDriver.IEDriver.$($packages['Selenium.WebDriver.IEDriver'])/driver/*" | Out-Default Copy-Item -Path "./temp/Selenium.WebDriver.IEDriver.$($packages['Selenium.WebDriver.IEDriver'])/driver/*" -Destination ./src/lib/Browsers/win/ -Recurse -Force | Out-Null Copy-Item -Path "./temp/Selenium.WebDriver.GeckoDriver.$($packages['Selenium.WebDriver.GeckoDriver'])/driver/win64/*" -Destination ./src/lib/Browsers/win/ -Recurse -Force | Out-Null Copy-Item -Path "./temp/Selenium.WebDriver.ChromeDriver.$($packages['Selenium.WebDriver.ChromeDriver'])/driver/win32/*" -Destination ./src/lib/Browsers/win/ -Recurse -Force | Out-Null diff --git a/Dockerfile b/Dockerfile index 93c9800..7ad02ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ -FROM mcr.microsoft.com/powershell:6.2.3-ubuntu-16.04 +# make sure to build this with --no-cache +FROM mcr.microsoft.com/powershell:7.0.0-ubuntu-16.04 LABEL maintainer="Matthew Kelly (Badgerati)" # update -RUN apt-get update -y -RUN apt-get install -y unzip curl wget +RUN apt-get update -y \ + && apt-get install -y unzip curl wget libappindicator1 fonts-liberation # install chrome -RUN apt-get install -y libappindicator1 fonts-liberation -RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb -RUN dpkg -i /chrome.deb; apt-get -fy install -RUN rm /chrome.deb -RUN google-chrome-stable --no-sandbox --headless --disable-gpu --dump-dom https://www.chromestatus.com/ +RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb \ + && dpkg -i /chrome.deb; apt-get -fy install \ + && rm /chrome.deb \ + && google-chrome-stable --no-sandbox --headless --disable-gpu --dump-dom https://www.chromestatus.com/ # install firefox RUN apt-get install -y firefox @@ -24,8 +24,7 @@ RUN export DISPLAY=:99 ENV MONOCLE_HEADLESS '1' # set as executable on drivers -RUN chown root:root /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/chromedriver -RUN chmod +x /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/chromedriver - -RUN chown root:root /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/geckodriver -RUN chmod +x /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/geckodriver \ No newline at end of file +RUN chown root:root /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/chromedriver \ + && chmod +x /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/chromedriver \ + && chown root:root /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/geckodriver \ + && chmod +x /usr/local/share/powershell/Modules/Monocle/lib/Browsers/linux/geckodriver diff --git a/README.md b/README.md index 948c216..987c9de 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ Monocle is a Cross-Platform PowerShell Web Automation module, made to make autom Monocle currently supports the following browsers: * IE (v3.150) -* Chrome (v80.0.3987.1600) -* Firefox (driver: v0.26) -* Edge (driver: v79.0.309.71) +* Chrome (v83.0.4103.3900) +* Firefox (driver: v0.26.0.1) +* Edge (driver: v81.0.416.77) * EdgeLegacy (driver: v17.17134) ## Install @@ -180,3 +180,10 @@ FROM badgerati/monocle:latest COPY . /usr/src/scripts CMD [ "pwsh", "-c", "cd /usr/src/scripts; ./flow.ps1" ] ``` + +The you can build and run the image as follows: + +```powershell +docker build -t monocle/test . +docker run --rm monocle/test +``` diff --git a/examples/Dockerfile b/examples/Dockerfile index cd55661..5e30ba6 100644 --- a/examples/Dockerfile +++ b/examples/Dockerfile @@ -1,3 +1,3 @@ FROM badgerati/monocle:latest COPY . /usr/src/scripts -CMD [ "pwsh", "-c", "cd /usr/src/scripts; ./youtube.ps1" ] \ No newline at end of file +CMD [ "pwsh", "-c", "cd /usr/src/scripts; ./youtube-docker.ps1" ] \ No newline at end of file diff --git a/examples/youtube-docker.ps1 b/examples/youtube-docker.ps1 new file mode 100644 index 0000000..77d0839 --- /dev/null +++ b/examples/youtube-docker.ps1 @@ -0,0 +1,39 @@ +Import-Module -Name Monocle -Force -ErrorAction Stop + +# Create a browser object +#Install-MonocleDriver -Type Chrome -Version '79.0.3945.3600' +$browser = New-MonocleBrowser -Type Chrome + +# Monocle runs commands in web flows, for easy disposal and test tracking +# Each flow needs a name +Start-MonocleFlow -Name 'Load YouTube' -Browser $browser -ScriptBlock { + + # Tell the browser which URL to navigate to, will sleep while page is loading + Set-MonocleUrl -Url 'https://www.youtube.com' + + # Sets the search bar element to the passed value to query + Get-MonocleElement -Selector 'input[name=search_query]' | Set-MonocleElementValue -Value 'Beerus Madness (Extended)' + #Get-MonocleElement -Id 'search_query' | Set-MonocleElementValue -Value 'Beerus Madness (Extended)' + + # Tells the browser to click the search button + Wait-MonocleElement -Id 'search-icon-legacy' | Out-Null + Get-MonocleElement -Id 'search-icon-legacy' | Invoke-MonocleElementClick + + # Though all commands sleep when the page is busy, some buttons use javascript + # to reform the page. The following will sleep the browser until the passed URL is loaded. + # If (default) 10 seconds passes and no URL, then the flow fails + Wait-MonocleUrl -Url 'https://www.youtube.com/results?search_query=' -StartsWith + + # Downloads an image from the page. This time it's using XPath + #Get-MonocleElement -XPath "//div[@data-context-item-id='SI6Yyr-iI6M']/img[1]" | Save-MonocleImage -FilePath '.\beerus.jpg' + + # Tells the browser to click the video in the results. The video link is found via XPath + Get-MonocleElement -XPath "//a[@title='Dragon Ball Super Soundtrack - Beerus Madness (Extended)']" | Invoke-MonocleElementClick + + # Again, we expect the URL to be loaded + Wait-MonocleUrl -Url 'https://www.youtube.com/watch?v=SI6Yyr-iI6M' + +} -CloseBrowser -ScreenshotOnFail + +# or close the browser manually if not using default: +#Close-MonocleBrowser -Browser $browser \ No newline at end of file diff --git a/src/Monocle.psd1 b/src/Monocle.psd1 index fd84876..41515de 100644 --- a/src/Monocle.psd1 +++ b/src/Monocle.psd1 @@ -11,7 +11,7 @@ RootModule = 'Monocle.psm1' # Version number of this module. - ModuleVersion = '1.3.2' + ModuleVersion = '1.3.3' # ID used to uniquely identify this module GUID = '9dc3c8a1-664d-4253-a5d2-920250d3a15f' diff --git a/src/lib/Browsers/linux/chromedriver b/src/lib/Browsers/linux/chromedriver index b362f8f..7d7041d 100644 Binary files a/src/lib/Browsers/linux/chromedriver and b/src/lib/Browsers/linux/chromedriver differ diff --git a/src/lib/Browsers/linux/msedgedriver b/src/lib/Browsers/linux/msedgedriver deleted file mode 100644 index 483ad60..0000000 Binary files a/src/lib/Browsers/linux/msedgedriver and /dev/null differ diff --git a/src/lib/Browsers/mac/chromedriver b/src/lib/Browsers/mac/chromedriver index df7565d..cd12a95 100644 Binary files a/src/lib/Browsers/mac/chromedriver and b/src/lib/Browsers/mac/chromedriver differ diff --git a/src/lib/Browsers/mac/msedgedriver b/src/lib/Browsers/mac/msedgedriver index 483ad60..52d299f 100644 Binary files a/src/lib/Browsers/mac/msedgedriver and b/src/lib/Browsers/mac/msedgedriver differ diff --git a/src/lib/Browsers/win/chromedriver.exe b/src/lib/Browsers/win/chromedriver.exe index d419a51..4850c8d 100644 Binary files a/src/lib/Browsers/win/chromedriver.exe and b/src/lib/Browsers/win/chromedriver.exe differ diff --git a/src/lib/Browsers/win/msedgedriver.exe b/src/lib/Browsers/win/msedgedriver.exe index e678dee..7c3a28a 100644 Binary files a/src/lib/Browsers/win/msedgedriver.exe and b/src/lib/Browsers/win/msedgedriver.exe differ