Skip to content

Commit

Permalink
Merge pull request #61 from Badgerati/develop
Browse files Browse the repository at this point in the history
v1.3.3
  • Loading branch information
Badgerati authored May 22, 2020
2 parents 1658946 + 2129e99 commit 9372ff4
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 22 deletions.
10 changes: 6 additions & 4 deletions .build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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
Expand Down
25 changes: 12 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
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
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion examples/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM badgerati/monocle:latest
COPY . /usr/src/scripts
CMD [ "pwsh", "-c", "cd /usr/src/scripts; ./youtube.ps1" ]
CMD [ "pwsh", "-c", "cd /usr/src/scripts; ./youtube-docker.ps1" ]
39 changes: 39 additions & 0 deletions examples/youtube-docker.ps1
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 9372ff4

Please sign in to comment.