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

Add tree dump utility to E2E test framework and fix Image border issue #3754

Merged
merged 25 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .ado/templates/e2e-test-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ jobs:
script: yarn run test
workingDirectory: packages/E2ETest

- task: CopyFiles@2
displayName: Copy tree dump output files
inputs:
sourceFolder: $(LocalAppData)\Packages\ReactUWPTestApp_kc2bncckyf4ap\LocalState
targetFolder: $(Build.StagingDirectory)/ReactUWPTestAppTreeDump
contents: TreeDump\**
condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
displayName: "Publish Artifact:ReactUWPTestAppTreeDump"
inputs:
artifactName: ReactUWPTestAppTreeDump
pathtoPublish: $(Build.StagingDirectory)/ReactUWPTestAppTreeDump
condition: succeededOrFailed()

- task: PublishTestResults@2
inputs:
testResultsFormat: "JUnit"
Expand Down
8 changes: 8 additions & 0 deletions change/react-native-windows-2019-12-10-12-31-34-treedump.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "TreeDump for E2E test and fix for image border issue",
"packageName": "react-native-windows",
"email": "dida@ntdev.microsoft.com",
"commit": "88f9b0eaecfe88e2243b66d969420131224f1c56",
"date": "2019-12-10T20:31:33.939Z"
}
7 changes: 7 additions & 0 deletions packages/E2ETest/app/Consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const APP_NAME = 'ReactUWPTestApp';
export const SEARCH_BUTTON = 'SearchButton';
export const HOME_BUTTON = '_HomeButton';
export const REACT_CONTROL_ERROR_TEST_ID = 'ReactControlErrorMessage';
export const TREE_DUMP_RESULT = 'TreeDump';

// UnknownTestPage
export const UNKNOWN_TESTPAGE = 'UnknownTestPage';
Expand Down Expand Up @@ -31,3 +32,9 @@ export const ACCESSBILITY_TESTPAGE = 'AccessiblityTestPage';
export const DIRECT_MANIPULATION_TESTPAGE = 'DirectManipulationTestPage';
export const MEASURE_IN_WINDOW_BUTTON = 'MeasureInWindow';
export const MEASURE_IN_WINDOW_RESULT = 'MeasureInWindowResult';

// Image Test Page
export const IMAGE_TESTPAGE = 'ImageTestPage';
export const IMAGE_CHANGE_BORDER = 'ChangeBorder';
export const SHOW_IMAGE_BORDER = 'BorderButton';
export const IMAGE_CONTAINER = 'ImageContainer';
70 changes: 70 additions & 0 deletions packages/E2ETest/app/ImageTestPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import {StyleSheet, View, Image, Button, requireNativeComponent} from 'react-native'
import React, { useState } from 'react';
import { TREE_DUMP_RESULT, SHOW_IMAGE_BORDER, IMAGE_CONTAINER } from './Consts';
const TreeDumpControl = requireNativeComponent('TreeDumpControl');

const styles = StyleSheet.create({
container: {
height:300,
width:500,
backgroundColor: 'yellow',
alignItems:'center',
},
containerWithBorder: {
height:300,
width:500,
borderRadius: 10.0,
borderWidth:10,
borderColor: '#00ff0055',
backgroundColor: 'yellow',
alignItems:'center',
},
imageWithBorder: {
height: '100%',
width: '100%',
borderRadius: 10.0,
borderWidth:10,
borderColor: '#0000ff55',
backgroundColor: 'red',
},
image: {
height: '100%',
width: '100%',
backgroundColor: 'red',
},
treeDumpControl: {
height: 150,
width: 500,
margin: 10,
},
});

export function ImageTestPage() {
const [imageWithBorder, setImageBorder] = useState(false);
const [clickCount, setClickCount] = useState(0);
const onOressBorder = () => {
Copy link
Member

@chrisglein chrisglein Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const onOressBorder = () => {
const onPressBorder = () => {
``` #Resolved

var previousImageBorderState = imageWithBorder;
setImageBorder(!previousImageBorderState);
var previousClickCount = clickCount;
setClickCount(previousClickCount+1);
}
return(
<View>
<View testID={IMAGE_CONTAINER} style={imageWithBorder?styles.containerWithBorder:styles.container}>
<Image
style={imageWithBorder?styles.imageWithBorder:styles.image}
resizeMode={'center'}
source={{uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=='}}
/>
</View >
<Button title= {imageWithBorder?"Hide Border":"Show Border"}
onPress={onOressBorder}
Copy link
Member

@chrisglein chrisglein Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onPress={onOressBorder}
onPress={onPressBorder}
``` #Resolved

testID={SHOW_IMAGE_BORDER}/>
<TreeDumpControl style={styles.treeDumpControl} dumpID={imageWithBorder?'ImageWithBorder':'ImageWithoutBorder'+clickCount} uiaID={IMAGE_CONTAINER} testID={TREE_DUMP_RESULT} />
Copy link
Contributor

@licanhua licanhua Dec 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'ImageWithoutBorder'+clickCount [](start = 94, length = 31)

ImageWithoutBorder0.txt and ImageWithoutBorder2.txt is not readable, also you created a hard binding between ImageTestPage and Image.spec.ts. If you refactor the test case like changing the order or inserting a new click, it doesn't work anymore. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to refactor the dumpID to "ImageWithoutBorder" and "ImageWithoutBorder-Subsequent", so it would work for click count > 2. The dump file is different if you initially don't have a border, or had a border then removed the border.


In reply to: 358381794 [](ancestors = 358381794)

</View>);
}
7 changes: 7 additions & 0 deletions packages/E2ETest/app/TestPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import {
LOGIN_TESTPAGE,
ACCESSBILITY_TESTPAGE,
DIRECT_MANIPULATION_TESTPAGE,
IMAGE_TESTPAGE,
} from './Consts';
import { LoginTestPage } from './LoginTestPage';
import { AccessibilityTestPage } from './AccessibilityTestPage';
import { DirectManipulationTestPage } from './DirectManipulationPage';
import { ImageTestPage } from './ImageTestPage';

export interface ITestPage {
testId: string;
Expand Down Expand Up @@ -45,6 +47,11 @@ const TestPages: ITestPage[] = [
description: 'Direct Manipulation Test Page',
content: DirectManipulationTestPage,
},
{
testId: IMAGE_TESTPAGE,
description: 'Image Test Page',
content: ImageTestPage,
},
{
testId: UNKNOWN_TESTPAGE,
description: 'Unknown Page',
Expand Down
Binary file added packages/E2ETest/msbuild.binlog
Binary file not shown.
38 changes: 37 additions & 1 deletion packages/E2ETest/wdio/pages/BasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { REACT_CONTROL_ERROR_TEST_ID, HOME_BUTTON } from '../../app/Consts';
import {
REACT_CONTROL_ERROR_TEST_ID,
HOME_BUTTON,
TREE_DUMP_RESULT,
} from '../../app/Consts';

export function By(testId: string): WebdriverIO.Element {
return $('~' + testId);
}

export function wait(timeout: number) {
return new Promise(resolve => {
setTimeout(resolve, timeout);
});
}

export class BasePage {
isPageLoaded(): boolean {
return this.homeButton.isDisplayed();
Expand All @@ -23,6 +33,28 @@ export class BasePage {
);
}

getTreeDumpResult() {
var testResult = false;
const maxWait = 20;
var waitCount = 1;
do {
testResult = this.treeDumpResult.getText() == 'TreeDump:Passed';
if (!testResult) {
console.log(
'####Waiting for treedump comparison result ' +
waitCount +
'/' +
maxWait +
'...####'
);
wait(100);
Copy link
Member

@chrisglein chrisglein Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no event you can wait for? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was going to add event and wait for that, but we have issues with the optimized constructor with Context parameter on release build issue, so I decided to do polling for now. Will open a issue to revisit later after Jon fixes the Custom ViewManager bug.


In reply to: 357846482 [](ancestors = 357846482)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to open an issue to add a WaitForIdle or similar.


In reply to: 357870760 [](ancestors = 357870760,357846482)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create #3779 to track this.


In reply to: 358440736 [](ancestors = 358440736,357870760,357846482)

waitCount += 1;
}
} while (waitCount <= maxWait && testResult == false);
Copy link
Member

@chrisglein chrisglein Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} while (waitCount <= maxWait && testResult == false);
} while (waitCount <= maxWait && !testResult);
``` #Resolved


return testResult;
}

protected timeoutForPageLoaded(currentTimeout?: number) {
if (currentTimeout) return currentTimeout;
return this.waitforPageTimeout;
Expand All @@ -44,6 +76,10 @@ export class BasePage {
return this.isPageLoaded();
}

private get treeDumpResult() {
return By(TREE_DUMP_RESULT);
}

// Default timeout for waitForPageLoaded command in PageObject
private waitforPageTimeout: number = 10000;
}
11 changes: 11 additions & 0 deletions packages/E2ETest/wdio/pages/HomePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
TEXTINPUT_TESTPAGE,
LOGIN_TESTPAGE,
DIRECT_MANIPULATION_TESTPAGE,
IMAGE_TESTPAGE,
} from '../../app/Consts';
import LoginPage from './LoginPage';
import DirectManipulationPage from './DirectManipulationPage';
import ImageTestPage from './ImageTestPage';

class HomePage extends BasePage {
backToHomePage() {
Expand All @@ -38,6 +40,11 @@ class HomePage extends BasePage {
DirectManipulationPage.waitForPageLoaded();
}

clickAndGotoImagePage() {
this.ImagePageButton.click();
ImageTestPage.waitForPageLoaded();
}

private get testInputTestPageButton() {
return By(TEXTINPUT_TESTPAGE);
}
Expand All @@ -49,6 +56,10 @@ class HomePage extends BasePage {
private get directManipulationPageButton() {
return By(DIRECT_MANIPULATION_TESTPAGE);
}

private get ImagePageButton() {
return By(IMAGE_TESTPAGE);
}
}

export default new HomePage();
28 changes: 28 additions & 0 deletions packages/E2ETest/wdio/pages/ImageTestPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import { BasePage, By } from './BasePage';
import { SHOW_IMAGE_BORDER } from '../../app/Consts';

class ImageTestPage extends BasePage {
backToHomePage() {
this.homeButton.click();
this.waitForPageLoaded();
}

isPageLoaded() {
return super.isPageLoaded();
}

toggleImageBorder() {
this._imageBorder.click();
}

private get _imageBorder() {
return By(SHOW_IMAGE_BORDER);
}
}

export default new ImageTestPage();
33 changes: 33 additions & 0 deletions packages/E2ETest/wdio/test/Image.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import HomePage from '../pages/HomePage';
import ImageTestPage from '../pages/ImageTestPage';
import assert from 'assert';

beforeAll(() => {
HomePage.backToHomePage();
HomePage.clickAndGotoImagePage();
});

describe('ImageWithoutBorderTest', () => {
it('ImageWithoutBorderTest', () => {
const result = ImageTestPage.getTreeDumpResult();
assert(result, '#1. Dump comparison for image without border!');
});

it('ImageWithBorderTest', () => {
ImageTestPage.toggleImageBorder();
const result = ImageTestPage.getTreeDumpResult();
assert(result, '#2. Dump comparison for image with border!');
});

// toggle back to no border and verify border properties are reset
it('ImageWithoutBorderTest', () => {
ImageTestPage.toggleImageBorder();
const result = ImageTestPage.getTreeDumpResult();
assert(result, '#3. Second dump comparison for image without border!');
});
});
15 changes: 15 additions & 0 deletions packages/E2ETest/windows/ReactUWPTestApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.ReactNative", "..
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.ReactNative.SharedManaged", "..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.shproj", "{67A1076F-7790-4203-86EA-4402CCB5E782}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TreeDumpLibrary", "TreeDumpLibrary\TreeDumpLibrary.csproj", "{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\..\..\vnext\Chakra\Chakra.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
..\..\..\vnext\Shared\Shared.vcxitems*{2d5d43d9-cffc-4c40-b4cd-02efb4e2742b}*SharedItemsImports = 4
..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{67a1076f-7790-4203-86ea-4402ccb5e782}*SharedItemsImports = 13
..\..\..\vnext\JSI\Shared\JSI.Shared.vcxitems*{a62d504a-16b8-41d2-9f19-e2e86019e5e4}*SharedItemsImports = 4
..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{abbb0407-0e82-486f-94ce-710900fcaadc}*SharedItemsImports = 4
..\..\..\vnext\Microsoft.ReactNative.SharedManaged\Microsoft.ReactNative.SharedManaged.projitems*{c0a6bd9c-3ee5-4b12-8ce4-cee95178539c}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Expand Down Expand Up @@ -163,6 +166,18 @@ Global
{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x64.Build.0 = Release|x64
{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x86.ActiveCfg = Release|Win32
{F7D32BD0-2749-483E-9A0D-1635EF7E3136}.Release|x86.Build.0 = Release|Win32
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Debug|ARM.ActiveCfg = Debug|ARM
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Debug|ARM.Build.0 = Debug|ARM
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Debug|x64.ActiveCfg = Debug|x64
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Debug|x64.Build.0 = Debug|x64
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Debug|x86.ActiveCfg = Debug|x86
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Debug|x86.Build.0 = Debug|x86
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Release|ARM.ActiveCfg = Release|ARM
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Release|ARM.Build.0 = Release|ARM
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Release|x64.ActiveCfg = Release|x64
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Release|x64.Build.0 = Release|x64
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Release|x86.ActiveCfg = Release|x86
{C0A6BD9C-3EE5-4B12-8CE4-CEE95178539C}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions packages/E2ETest/windows/ReactUWPTestApp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Windows.UI.Xaml.Navigation;
using Microsoft.ReactNative;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.Foundation;

namespace ReactUWPTestApp
{
Expand Down Expand Up @@ -42,6 +44,8 @@ public App()
#endif

PackageProviders.Add(new Microsoft.ReactNative.Managed.ReactPackageProvider()); // Includes any modules in this project
PackageProviders.Add(new TreeDumpLibrary.ReactPackageProvider());

this.InitializeComponent();
}

Expand All @@ -54,6 +58,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
{
base.OnLaunched(e);
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
ApplicationView.GetForCurrentView().TryResizeView(new Size(800, 600));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[Windows.UI.Xaml.Controls.Border]
ActualOffset=<0, 0, 0>
Background=#FFFFFF00
BorderBrush=#5500FF00
BorderThickness=10,10,10,10
Clip=[NULL]
CornerRadius=10,10,10,10
Height=300
HorizontalAlignment=Stretch
Margin=0,0,0,0
Padding=0,0,0,0
RenderSize=500,300
VerticalAlignment=Stretch
Visibility=Visible
Width=500
[react.uwp.ViewPanel]
ActualOffset=<10, 10, 0>
Background=[NULL]
BorderBrush=#5500FF00
BorderThickness=10,10,10,10
Clip=[NULL]
CornerRadius=10,10,10,10
HorizontalAlignment=Stretch
Margin=0,0,0,0
RenderSize=480,280
VerticalAlignment=Stretch
Visibility=Visible
[Windows.UI.Xaml.DependencyObject]
Loading