mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(testing): e2e flag no longer needed, testID is now applicable in dev or prod builds (#10396)
- you can now test on development or production with testID set - for android, this changes testID to use resource id instead of content description - you no longer need to pass `--env.e2e`. e2e is simply usable if testID is set - the `testID` property will also set `accessibilityIdentifier` and `accessibilityIdentifier` property will set `testID` only if there is a `testID` already set
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Application, ApplicationEventData } from '../application';
|
||||
import { Trace } from '../trace';
|
||||
import { SDK_VERSION } from '../utils/constants';
|
||||
import { resources } from '../utils/android';
|
||||
import type { View } from '../ui/core/view';
|
||||
import { GestureTypes } from '../ui/gestures';
|
||||
import { notifyAccessibilityFocusState } from './accessibility-common';
|
||||
@@ -166,6 +167,12 @@ function ensureNativeClasses() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set resource id that can be used with test frameworks without polluting the content description.
|
||||
const id = host.getTag(resources.getId(`:id/nativescript_accessibility_id`));
|
||||
if (id != null) {
|
||||
info.setViewIdResourceName(id);
|
||||
}
|
||||
|
||||
const accessibilityRole = view.accessibilityRole;
|
||||
if (accessibilityRole) {
|
||||
const androidClassName = RoleTypeMap.get(accessibilityRole);
|
||||
@@ -661,11 +668,6 @@ function applyContentDescription(view: View, forceUpdate?: boolean) {
|
||||
|
||||
const contentDescription = contentDescriptionBuilder.join('. ').trim().replace(/^\.$/, '');
|
||||
|
||||
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && view.testID) {
|
||||
// ignore when testID is enabled
|
||||
return;
|
||||
}
|
||||
|
||||
if (contentDescription) {
|
||||
if (Trace.isEnabled()) {
|
||||
Trace.write(`${cls} - set to "${contentDescription}"`, Trace.categories.Accessibility);
|
||||
|
||||
1
packages/core/global-types.d.ts
vendored
1
packages/core/global-types.d.ts
vendored
@@ -131,7 +131,6 @@ declare const __CSS_PARSER__: string;
|
||||
declare const __NS_WEBPACK__: boolean;
|
||||
declare const __UI_USE_EXTERNAL_RENDERER__: boolean;
|
||||
declare const __UI_USE_XML_PARSER__: boolean;
|
||||
declare const __USE_TEST_ID__: boolean | undefined;
|
||||
declare const __ANDROID__: boolean;
|
||||
declare const __IOS__: boolean;
|
||||
declare const __VISIONOS__: boolean;
|
||||
|
||||
Binary file not shown.
@@ -794,20 +794,19 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[testIDProperty.setNative](value: string) {
|
||||
this.setTestID(this.nativeViewProtected, value);
|
||||
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
setTestID(view, value) {
|
||||
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) {
|
||||
const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id');
|
||||
setAccessibilityIdentifier(view, value) {
|
||||
const id = Utils.android.resources.getId(':id/nativescript_accessibility_id');
|
||||
|
||||
if (id) {
|
||||
view.setTag(id, value);
|
||||
view.setTag(value);
|
||||
}
|
||||
|
||||
view.setContentDescription(value);
|
||||
if (id) {
|
||||
view.setTag(id, value);
|
||||
view.setTag(value);
|
||||
}
|
||||
|
||||
if (this.testID && this.testID !== value) this.testID = value;
|
||||
if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value;
|
||||
}
|
||||
|
||||
[accessibilityEnabledProperty.setNative](value: boolean): void {
|
||||
@@ -817,16 +816,7 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
[accessibilityIdentifierProperty.setNative](value: string): void {
|
||||
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) {
|
||||
// ignore when using testID;
|
||||
} else {
|
||||
const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id');
|
||||
|
||||
if (id) {
|
||||
this.nativeViewProtected.setTag(id, value);
|
||||
this.nativeViewProtected.setTag(value);
|
||||
}
|
||||
}
|
||||
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[accessibilityRoleProperty.setNative](value: AccessibilityRole): void {
|
||||
|
||||
@@ -679,13 +679,14 @@ export class View extends ViewCommon implements ViewDefinition {
|
||||
}
|
||||
|
||||
[testIDProperty.setNative](value: string) {
|
||||
this.setTestID(this.nativeViewProtected, value);
|
||||
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
public setTestID(view: any, value: string): void {
|
||||
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) {
|
||||
view.accessibilityIdentifier = value;
|
||||
}
|
||||
public setAccessibilityIdentifier(view: any, value: string): void {
|
||||
view.accessibilityIdentifier = value;
|
||||
|
||||
if (this.testID && this.testID !== value) this.testID = value;
|
||||
if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value;
|
||||
}
|
||||
|
||||
[accessibilityEnabledProperty.setNative](value: boolean): void {
|
||||
@@ -695,15 +696,11 @@ export class View extends ViewCommon implements ViewDefinition {
|
||||
}
|
||||
|
||||
[accessibilityIdentifierProperty.getDefault](): string {
|
||||
return this.nativeViewProtected.accessibilityLabel;
|
||||
return this.nativeViewProtected.accessibilityIdentifier;
|
||||
}
|
||||
|
||||
[accessibilityIdentifierProperty.setNative](value: string): void {
|
||||
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) {
|
||||
// ignore when using testID
|
||||
} else {
|
||||
this.nativeViewProtected.accessibilityIdentifier = value;
|
||||
}
|
||||
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[accessibilityRoleProperty.setNative](value: AccessibilityRole): void {
|
||||
|
||||
@@ -1173,7 +1173,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
return;
|
||||
}
|
||||
|
||||
public setTestID(view: any, value: string) {
|
||||
public setAccessibilityIdentifier(view: any, value: string) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,21 +465,11 @@ export class TextBase extends TextBaseCommon {
|
||||
}
|
||||
|
||||
[testIDProperty.setNative](value: string): void {
|
||||
this.setTestID(this.nativeTextViewProtected, value);
|
||||
this.setAccessibilityIdentifier(this.nativeTextViewProtected, value);
|
||||
}
|
||||
|
||||
[accessibilityIdentifierProperty.setNative](value: string): void {
|
||||
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) {
|
||||
// ignore when using testID;
|
||||
} else {
|
||||
// we override the default setter to apply it on nativeTextViewProtected
|
||||
const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id');
|
||||
|
||||
if (id) {
|
||||
this.nativeTextViewProtected.setTag(id, value);
|
||||
this.nativeTextViewProtected.setTag(value);
|
||||
}
|
||||
}
|
||||
this.setAccessibilityIdentifier(this.nativeTextViewProtected, value);
|
||||
}
|
||||
|
||||
[maxLinesProperty.setNative](value: number) {
|
||||
|
||||
Reference in New Issue
Block a user