Skip to content

Commit 4654120

Browse files
authored
Merge pull request #268 from csf-dev/craigfowler/issue267
2 parents 8827693 + 0581475 commit 4654120

5 files changed

Lines changed: 68 additions & 19 deletions

File tree

.github/workflows/dotnetCi.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
build_test_and_pack:
2525
name: Build, test & package
26-
runs-on: ubuntu-slim
26+
runs-on: ubuntu-24.04
2727
timeout-minutes: 30
2828

2929
env:
@@ -40,7 +40,7 @@ jobs:
4040
BranchParam: ${{ github.event_name == 'pull_request' && 'sonar.pullrequest.branch' || 'sonar.branch.name' }}
4141
PullRequestParam: ${{ github.event_name == 'pull_request' && format('/d:sonar.pullrequest.key={0}', github.event.number) || '' }}
4242
DISPLAY: :99
43-
43+
4444
steps:
4545
- name: Checkout
4646
uses: actions/checkout@v4
@@ -68,19 +68,18 @@ jobs:
6868
with:
6969
java-version: 21
7070
distribution: 'zulu'
71-
- name: Install GUI packages so Chrome may run
72-
run: |
73-
sudo apt-get update
74-
sudo apt install -y xorg xvfb gtk2-engines-pixbuf dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable psmisc
71+
# See https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md
72+
- name: Disable AppArmor restrictions so Chrome may run
73+
run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns
74+
- name: Start an Xvfb display so Chrome may run
75+
run: Xvfb -ac $DISPLAY -screen 0 1280x1024x16 &
7576

7677
# Environment setup pre-build
7778

7879
- name: Setup Selenium Manager config
7980
run: |
8081
mkdir ~/.cache/selenium
8182
cp Tools/se-config.toml ~/.cache/selenium
82-
- name: Start an Xvfb display so Chrome may run
83-
run: Xvfb -ac $DISPLAY -screen 0 1280x1024x16 &
8483
- name: Restore .NET packages
8584
run: dotnet restore
8685
- name: Restore Node modules
@@ -100,34 +99,38 @@ jobs:
10099
/d:sonar.host.url=${{ env.SonarCloudUrl }}
101100
/d:sonar.token=${{ env.SonarCloudSecretKey }}
102101
/d:${{ env.BranchParam }}=${{ env.BranchName }} ${{ env.PullRequestParam }}
103-
/d:sonar.javascript.lcov.reportPaths=CSF.Screenplay.JsonToHtmlReport.Template/src/TestResults/lcov.info
102+
/d:sonar.javascript.lcov.reportPaths=$PWD/CSF.Screenplay.JsonToHtmlReport.Template/src/TestResults/lcov.info
104103
/s:$PWD/.sonarqube-analysisproperties.xml
105104
- name: Build the solution
106105
run: dotnet build -c ${{ env.Configuration }} --no-incremental
107106
- name: Run .NET tests with coverage
108107
id: dotnet_tests
109-
continue-on-error: true
108+
shell: bash {0}
110109
run: |
111110
for proj in Tests/*.Tests
112111
do
113112
projNameArray=(${proj//// })
114113
projName=${projNameArray[1]}
115114
assemblyPath=$proj/bin/$Configuration/$Tfm/$projName.dll
116115
coverlet "$assemblyPath" --target "dotnet" --targetargs "test $proj -c $Configuration --no-build --logger:nunit --test-adapter-path:." -f=opencover -o="TestResults/$projName.opencover.xml"
117-
if [ $? -ne 0 ]
116+
exitCode=$?
117+
if [ $exitCode -ne 0 ]
118118
then
119-
echo "failures=true" >> $GITHUB_OUTPUT
119+
echo "One or more tests have failed; this build should eventually fail"
120+
echo "failures=true" >> "$GITHUB_OUTPUT"
120121
fi
121122
done
122123
- name: Run JavaScript tests with coverage
123124
id: js_tests
124-
continue-on-error: true
125+
shell: bash {0}
125126
run: |
126127
cd CSF.Screenplay.JsonToHtmlReport.Template/src
127128
npm test
128-
if [ $? -ne 0 ]
129+
exitCode=$?
130+
if [ $exitCode -ne 0 ]
129131
then
130-
echo "failures=true" >> $GITHUB_OUTPUT
132+
echo "One or more tests have failed; this build should eventually fail"
133+
echo "failures=true" >> "$GITHUB_OUTPUT"
131134
fi
132135
cd ../..
133136
@@ -139,11 +142,23 @@ jobs:
139142
- name: Gracefully stop Xvfb
140143
run: killall Xvfb
141144
continue-on-error: true
142-
- name: Upload test results artifacts
145+
- name: Upload .NET test results artifacts
143146
uses: actions/upload-artifact@v4
144147
with:
145148
name: NUnit test results
146149
path: Tests/*.Tests/**/TestResults.xml
150+
# This step won't produce any artifacts if the verbose factory isn't
151+
# selected via appsettings.json in CSF.Screenplay.Selenium.Tests, but that's OK
152+
- name: Upload verbose webdriver log artifacts
153+
uses: actions/upload-artifact@v4
154+
with:
155+
name: Verbose webdriver logs
156+
path: '**/chrome-verbose-log.txt'
157+
- name: Upload JS test results artifacts
158+
uses: actions/upload-artifact@v4
159+
with:
160+
name: Jest test results
161+
path: CSF.Screenplay.JsonToHtmlReport.Template/src/TestResults/**/*
147162
- name: Upload Screenplay JSON report artifact
148163
uses: actions/upload-artifact@v4
149164
with:
@@ -164,7 +179,7 @@ jobs:
164179
name: Screenplay HTML reports
165180
path: Tests/**/ScreenplayReport.html
166181
- name: Fail the build if any test failures
167-
if: ${{ steps.dotnet_tests.outputs.failures == 'true' || steps.js_tests.outputs.failures == 'true' }}
182+
if: steps.dotnet_tests.outputs.failures == 'true' || steps.js_tests.outputs.failures == 'true'
168183
run: |
169184
echo "Failing the build due to test failures"
170185
exit 1

CSF.Screenplay.Docs/docfx.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"**/obj/**",
1212
"Tests/**",
1313
"Old/**",
14-
"CSF.Screenplay.JsonToHtmlReport.Template/**"
14+
"CSF.Screenplay.JsonToHtmlReport.Template/**",
15+
"CSF.Screenplay.SpecFlow/**"
1516
]
1617
}
1718
],
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using CSF.Extensions.WebDriver.Factories;
3+
using OpenQA.Selenium;
4+
using OpenQA.Selenium.Chrome;
5+
6+
namespace CSF.Screenplay.Selenium;
7+
8+
/// <summary>
9+
/// An implementation of <see cref="ICreatesWebDriverFromOptions"/> which writes verbose logs to a file.
10+
/// </summary>
11+
/// <remarks>
12+
/// <para>
13+
/// This driver factory is unused most of the time, but it's helpful if you're trying to diagnose problems with ChromeDriver,
14+
/// say in a CI build that's been failing. Select this factory by changing the <c>appsettings.json</c> file and you'll get
15+
/// log files.
16+
/// </para>
17+
/// </remarks>
18+
public class VerboseChromeDriverFactory : ICreatesWebDriverFromOptions
19+
{
20+
public WebDriverAndOptions GetWebDriver(WebDriverCreationOptions options, Action<DriverOptions>? supplementaryConfiguration = null)
21+
{
22+
var chromeOptions = (ChromeOptions) options.OptionsFactory();
23+
var service = ChromeDriverService.CreateDefaultService();
24+
service.EnableVerboseLogging = true;
25+
service.LogPath = "chrome-verbose-log.txt";
26+
var driver = new ChromeDriver(service, chromeOptions);
27+
28+
return new(driver, chromeOptions);
29+
}
30+
}

Tests/CSF.Screenplay.Selenium.Tests/appsettings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"DriverConfigurations": {
44
"DefaultChrome": {
55
"DriverType": "ChromeDriver"
6+
},
7+
"VerboseChrome": {
8+
"DriverType": "ChromeDriver",
9+
"DriverFactoryType": "CSF.Screenplay.Selenium.VerboseChromeDriverFactory, CSF.Screenplay.Selenium.Tests"
610
}
711
},
812
"SelectedConfiguration": "DefaultChrome"

Tools/se-config.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
# already installed.
99

1010
browser = "chrome"
11-
force-browser-download = true
1211
browser-version = "stable"

0 commit comments

Comments
 (0)