Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on getting cross browser support working with cypress #15

Merged
merged 7 commits into from
Feb 15, 2024
2 changes: 2 additions & 0 deletions .github/actions/build-dotnet-app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ runs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ inputs.dotnet_version }}

- name: Install dependencies
shell: bash
run: dotnet restore ${{ inputs.solution_filename }}

- name: Build
shell: bash
run: dotnet build ${{ inputs.solution_filename }} --configuration Release --no-restore
18 changes: 18 additions & 0 deletions .github/actions/run-accessibility-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Run accessibility tests
description: Runs Pa11y-ci

inputs:
url:
required: true
type: string

runs:
using: composite

steps:
- name: Run Pa11y
shell: bash
run: npm install -g pa11y-ci && pa11y-ci ${{ inputs.url }} --config .pa11yci-ubuntu.json
working-directory: ./tests/Dfe.EarlyYearsQualification.AccessibilityTests/


15 changes: 15 additions & 0 deletions .github/actions/run-app-for-testing/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Run app for testing
description: Run the app within the action so we can run E2E and Accessibility tests.

inputs:
url:
required: true
type: string

runs:
using: composite

steps:
- name: Run .Net Project
shell: bash
run: dotnet run --urls "${{ inputs.url }}" --project="src/Dfe.EarlyYearsQualification.Web" --UseMockContentful=true &
13 changes: 11 additions & 2 deletions .github/actions/run-e2e-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ runs:
using: composite

steps:
- name: Build and test project
- name: Run Chrome Tests
uses: cypress-io/github-action@v6
if: success() || failure()
with:
working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/
browser: chrome
#config: baseUrl=${{ inputs.url }} // TODO: Update this once the code check workflow starts running the app locally. For now leave this as the baseUrl in the config file.
config: baseUrl="${{ inputs.url }}"

- name: Run Firefox Tests
uses: cypress-io/github-action@v6
if: success() || failure()
with:
working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/
browser: firefox
config: baseUrl="${{ inputs.url }}"

- name: Store screenshots on test failure
uses: actions/upload-artifact@v3
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/code-pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ concurrency:
env:
DOTNET_VERSION: 8
SOLUTION_NAME: 'Dfe.EarlyYearsQualification.sln'
URL: http://localhost:5000

jobs:

Expand All @@ -45,8 +46,18 @@ jobs:
uses: ./.github/actions/run-unit-tests
with:
solution_filename: ${{ env.SOLUTION_NAME }}

- name: Run app for testing
uses: ./.github/actions/run-app-for-testing
with:
url: ${{ env.URL }}

- name: Run e2e tests
uses: ./.github/actions/run-e2e-tests
with:
url: "<THIS CAN BE UPDATED WITH THE URL OF THE PR TEST SITE AT A LATER DATE>"
url: ${{ env.URL }}

- name: Run Accessibility tests
uses: ./.github/actions/run-accessibility-tests
with:
url: ${{ env.URL }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="contentful.aspnetcore" Version="7.5.0" />
<PackageReference Include="moq" Version="4.20.70" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Dfe.EarlyYearsQualification.Content.Services;
using Moq;

namespace Dfe.EarlyYearsQualification.Web.Extensions
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddMockContentful(this IServiceCollection services)
{

var mockContentfulService = new Mock<IContentService>();

mockContentfulService.Setup(x => x.GetLandingPage()).ReturnsAsync(new Content.Entities.LandingPage()
{
Header = "Test Header",
ServiceIntroduction = new Contentful.Core.Models.Document(),
StartButtonText = "Test Start Button Text"
});

services.AddSingleton(mockContentfulService.Object);
return services;
}
}
}
16 changes: 12 additions & 4 deletions src/Dfe.EarlyYearsQualification.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
using Contentful.AspNetCore;
using Dfe.EarlyYearsQualification.Content.Services;
using Dfe.EarlyYearsQualification.Web.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddContentful(builder.Configuration);
builder.Services.AddTransient<IContentService, ContentfulContentService>();

if (builder.Configuration.GetValue<bool>("UseMockContentful"))
{
builder.Services.AddMockContentful();
} else
{
builder.Services.AddTransient<IContentService, ContentfulContentService>();
}

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"defaults": {
"chromeLaunchConfig": {
"executablePath": "/usr/bin/google-chrome"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ describe("A dummy spec used to test Cypress setup", () => {
cy.visit("/");
})

it("opens on the example site", () => {
cy.url().should("eq", "https://example.cypress.io/");
})

it("opens the utilities page", () => {
cy.get("a[href='/utilities']").first().click();
cy.url().should("contain", "/utilities");
it("Checks Crown copyright link text", () => {
cy.get(".govuk-footer__copyright-logo").first().should("contain.text", "Crown copyright")
})
})
8 changes: 4 additions & 4 deletions tests/Dfe.EarlyYearsQualification.E2ETests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Dfe.EarlyYearsQualification.E2ETests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"cypress": "^13.6.3"
"cypress": "^13.6.4"
}
}
Loading