-
Notifications
You must be signed in to change notification settings - Fork 218
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
Jennyf/ui web app #556
Merged
Merged
Jennyf/ui web app #556
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eb247f6
initial commit
jennyf19 59a6e8d
more selenium updates
jennyf19 65ce4fb
few more updates
jennyf19 3cc5b38
add consts and a few more updates
jennyf19 a4a188b
fix target framework
jennyf19 0e785c3
rename
jennyf19 458de71
adding in extra files from deployment
jennyf19 c700f01
fix test
jennyf19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
tests/IntegrationTests/WebAppUiTests/WebAppIntegrationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
using System.Threading.Tasks; | ||
using Microsoft.Identity.Web.Test.Common; | ||
using Microsoft.Identity.Web.Test.LabInfrastructure; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Chrome; | ||
using Xunit; | ||
|
||
namespace WebAppUiTests | ||
{ | ||
#if !FROM_GITHUB_ACTION | ||
public class WebAppIntegrationTests | ||
{ | ||
[Fact] | ||
public async Task ChallengeUser_SignInSucceedsTestAsync() | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } | ||
|
||
// Arrange | ||
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false); | ||
|
||
ChromeOptions options = new ChromeOptions(); | ||
// ~2x faster, no visual rendering | ||
// comment-out below when debugging to see the UI automation | ||
options.AddArguments(TestConstants.Headless); | ||
IWebDriver driver = new ChromeDriver(options); | ||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); | ||
|
||
// Act | ||
Trace.WriteLine("Starting Selenium automation: web app sign-in & call Graph"); | ||
driver.Navigate() | ||
.GoToUrl("https://webapptestmsidweb.azurewebsites.net/MicrosoftIdentity/Account/signin"); | ||
PerformLogin(driver, labResponse.User); | ||
|
||
// Assert | ||
Assert.Contains(labResponse.User.Upn, driver.PageSource); | ||
Assert.Contains(TestConstants.PhotoLabel, driver.PageSource); | ||
driver.Quit(); | ||
driver.Dispose(); | ||
} | ||
|
||
private static void PerformLogin( | ||
IWebDriver driver, | ||
LabUser user) | ||
{ | ||
UserInformationFieldIds fields = new UserInformationFieldIds(); | ||
|
||
EnterUsername(driver, user, fields); | ||
EnterPassword(driver, user, fields); | ||
HandleStaySignedInPrompt(driver); | ||
} | ||
|
||
private static void EnterUsername( | ||
IWebDriver driver, | ||
LabUser user, | ||
UserInformationFieldIds fields) | ||
{ | ||
// Lab user needs to be a guest in the msidentity-samples-testing tenant | ||
Trace.WriteLine(string.Format("Logging in ... Entering user name: {0}", user.Upn)); | ||
|
||
driver.FindElement(By.Id(fields.AADUsernameInputId)).SendKeys(user.Upn.Contains("EXT") ? user.HomeUPN : user.Upn); | ||
|
||
Trace.WriteLine("Logging in ... Clicking <Next> after user name"); | ||
|
||
driver.FindElement(By.Id(fields.AADSignInButtonId)).Click(); | ||
} | ||
|
||
private static void EnterPassword( | ||
IWebDriver driver, | ||
LabUser user, | ||
UserInformationFieldIds fields) | ||
{ | ||
Trace.WriteLine("Logging in ... Entering password"); | ||
string password = user.GetOrFetchPassword(); | ||
string passwordField = fields.GetPasswordInputId(); | ||
driver.FindElement(By.Id(passwordField)).SendKeys(password); | ||
|
||
Trace.WriteLine("Logging in ... Clicking next after password"); | ||
driver.FindElement(By.Id(fields.GetPasswordSignInButtonId())).Click(); | ||
} | ||
|
||
private static void HandleStaySignedInPrompt(IWebDriver driver) | ||
{ | ||
Trace.WriteLine("Logging in ... Clicking 'No' for staying signed in"); | ||
var acceptBtn = driver.FindElement(By.Id(TestConstants.StaySignedInNoId)); | ||
acceptBtn?.Click(); | ||
} | ||
} | ||
#endif //FROM_GITHUB_ACTION | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.1; net5.0</TargetFrameworks> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.7" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> | ||
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" /> | ||
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="85.0.4183.8700" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Microsoft.Identity.Web.Test.LabInfrastructure\Microsoft.Identity.Web.Test.LabInfrastructure.csproj" /> | ||
<ProjectReference Include="..\..\WebAppCallsMicrosoftGraph\WebAppCallsMicrosoftGraph.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/Microsoft.Identity.Web.Test.LabInfrastructure/UserInformationFieldIds.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Identity.Web.Test.Common; | ||
|
||
namespace Microsoft.Identity.Web.Test.LabInfrastructure | ||
{ | ||
public class UserInformationFieldIds | ||
{ | ||
private string _passwordInputId; | ||
private string _passwordSignInButtonId; | ||
|
||
public string GetPasswordInputId() | ||
{ | ||
if (string.IsNullOrWhiteSpace(_passwordInputId)) | ||
{ | ||
DetermineFieldIds(); | ||
} | ||
|
||
return _passwordInputId; | ||
} | ||
|
||
public string GetPasswordSignInButtonId() | ||
{ | ||
if (string.IsNullOrWhiteSpace(_passwordSignInButtonId)) | ||
{ | ||
DetermineFieldIds(); | ||
} | ||
|
||
return _passwordSignInButtonId; | ||
} | ||
|
||
/// <summary> | ||
/// When starting auth, the first screen, which collects the username, is from AAD. | ||
/// </summary> | ||
public string AADSignInButtonId | ||
{ | ||
get | ||
{ | ||
return TestConstants.WebSubmitId; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// When starting auth, the first screen, which collects the username, is from AAD. | ||
/// </summary> | ||
public string AADUsernameInputId | ||
{ | ||
get | ||
{ | ||
return TestConstants.WebUPNInputId; | ||
} | ||
} | ||
|
||
private void DetermineFieldIds() | ||
{ | ||
_passwordInputId = TestConstants.WebPasswordId; | ||
_passwordSignInButtonId = TestConstants.WebSubmitId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-ef": { | ||
"version": "3.1.7", | ||
"commands": [ | ||
"dotnet-ef" | ||
] | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...osoftGraph/Properties/ServiceDependencies/webAppTestMsIdWeb - Web Deploy/profile.arm.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_dependencyType": "appService.windows" | ||
}, | ||
"parameters": { | ||
"resourceGroupName": { | ||
"type": "string", | ||
"defaultValue": "MsIdWeb", | ||
"metadata": { | ||
"description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." | ||
} | ||
}, | ||
"resourceGroupLocation": { | ||
"type": "string", | ||
"defaultValue": "centralus", | ||
"metadata": { | ||
"description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support." | ||
} | ||
}, | ||
"resourceName": { | ||
"type": "string", | ||
"defaultValue": "webAppTestMsIdWeb", | ||
"metadata": { | ||
"description": "Name of the main resource to be created by this template." | ||
} | ||
}, | ||
"resourceLocation": { | ||
"type": "string", | ||
"defaultValue": "[parameters('resourceGroupLocation')]", | ||
"metadata": { | ||
"description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." | ||
} | ||
} | ||
}, | ||
"variables": { | ||
"appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]", | ||
"appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]" | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Resources/resourceGroups", | ||
"name": "[parameters('resourceGroupName')]", | ||
"location": "[parameters('resourceGroupLocation')]", | ||
"apiVersion": "2019-10-01" | ||
}, | ||
{ | ||
"type": "Microsoft.Resources/deployments", | ||
"name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]", | ||
"resourceGroup": "[parameters('resourceGroupName')]", | ||
"apiVersion": "2019-10-01", | ||
"dependsOn": [ | ||
"[parameters('resourceGroupName')]" | ||
], | ||
"properties": { | ||
"mode": "Incremental", | ||
"template": { | ||
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"resources": [ | ||
{ | ||
"location": "[parameters('resourceLocation')]", | ||
"name": "[parameters('resourceName')]", | ||
"type": "Microsoft.Web/sites", | ||
"apiVersion": "2015-08-01", | ||
"tags": { | ||
"[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty" | ||
}, | ||
"dependsOn": [ | ||
"[variables('appServicePlan_ResourceId')]" | ||
], | ||
"kind": "app", | ||
"properties": { | ||
"name": "[parameters('resourceName')]", | ||
"kind": "app", | ||
"httpsOnly": true, | ||
"reserved": false, | ||
"serverFarmId": "[variables('appServicePlan_ResourceId')]", | ||
"siteConfig": { | ||
"metadata": [ | ||
{ | ||
"name": "CURRENT_STACK", | ||
"value": "dotnetcore" | ||
} | ||
] | ||
} | ||
}, | ||
"identity": { | ||
"type": "SystemAssigned" | ||
} | ||
}, | ||
{ | ||
"location": "[parameters('resourceLocation')]", | ||
"name": "[variables('appServicePlan_name')]", | ||
"type": "Microsoft.Web/serverFarms", | ||
"apiVersion": "2015-08-01", | ||
"sku": { | ||
"name": "S1", | ||
"tier": "Standard", | ||
"family": "S", | ||
"size": "S1" | ||
}, | ||
"properties": { | ||
"name": "[variables('appServicePlan_name')]" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified version from MSAL. they have to check ADFS & B2C. we can add B2C later, so should be easy to expand this class when needed.