@@ -14,34 +14,36 @@ function capitalize(str) {
1414}
1515
1616async function loadNewRecord ( ) {
17- let isSuccess = await browser . execute ( logicalName => {
17+ let errorMessage = await browser . execute ( logicalName => {
1818 try {
1919 Xrm . Utility . openEntityForm ( logicalName ) ;
20- return true ;
20+ return ;
21+ }
22+ catch ( e ) {
23+ return e ?. message ;
2124 }
22- catch { }
2325 } , RECORD_LOGICAL_NAME ) ;
2426
25- if ( ! isSuccess ) {
26- // Backup, but noisy to the `info` logs as toolkit needs to be re-injected
27- await browser . url ( `/main.aspx?pagetype=entityrecord&etn=${ RECORD_LOGICAL_NAME } ` ) ;
27+ if ( errorMessage ) {
28+ throw new Error ( `Could not load record via Xrm APIs: "${ errorMessage } "` ) ;
2829 }
2930
3031 await Panes . Dynamics . FormHeader . waitForDisplayed ( ) ;
3132}
3233
3334async function loadRecord ( ) {
34- let isSuccess = await browser . execute ( ( logicalName , id ) => {
35+ let errorMessage = await browser . execute ( ( logicalName , id ) => {
3536 try {
3637 Xrm . Utility . openEntityForm ( logicalName , id ) ;
37- return true ;
38+ return ;
39+ }
40+ catch ( e ) {
41+ return e ?. message ;
3842 }
39- catch { }
4043 } , RECORD_LOGICAL_NAME , RECORD_ID ) ;
4144
42- if ( ! isSuccess ) {
43- // Backup, but noisy to the `info` logs as toolkit needs to be re-injected
44- await browser . url ( `/main.aspx?pagetype=entityrecord&etn=${ RECORD_LOGICAL_NAME } &id=${ RECORD_ID } ` ) ;
45+ if ( errorMessage ) {
46+ throw new Error ( `Could not load record via Xrm APIs: "${ errorMessage } "` ) ;
4547 }
4648
4749 await Panes . Dynamics . FormHeader . waitForDisplayed ( ) ;
@@ -53,17 +55,6 @@ async function loadPane(pane, isViewingRecord) {
5355 }
5456
5557 await Panes [ capitalize ( pane ) ] . open ( ) ;
56-
57- if ( ! isViewingRecord ) {
58- return ;
59- }
60-
61- if ( / n e w / i. test ( isViewingRecord ) ) {
62- await loadNewRecord ( ) ;
63- }
64- else {
65- await loadRecord ( ) ;
66- }
6758}
6859
6960Given ( / i a m o n t h e ( \w + ) p a n e ( a n d v i e w i n g a r e c o r d | a n d v i e w i n g a n e w r e c o r d ) ? / i, loadPane ) ;
@@ -325,20 +316,20 @@ Then(/a new window should open to show the (.+) (editor|list|page)$/i, async (co
325316} ) ;
326317
327318// Copied from webdriver.io source, but modified to handle nulls
328- async function switchWindow ( urlOrTitleToMatch ) {
319+ async function switchWindow ( urlOrTitleToMatch , currentWindowId ) {
329320 if ( typeof urlOrTitleToMatch !== 'string' && ! ( urlOrTitleToMatch instanceof RegExp ) ) {
330321 throw new Error ( 'Unsupported parameter for switchWindow, required is "string" or an RegExp' ) ;
331322 }
332323
333324 const tabs = await browser . getWindowHandles ( ) ;
334325
335- for ( const tab of tabs ) {
336- await browser . switchToWindow ( tab )
326+ for ( const tab of tabs . filter ( t => t !== currentWindowId ) ) {
327+ await browser . switchToWindow ( tab ) ;
337328
338329 /**
339330 * check if url matches
340331 */
341- await browser . waitUntil ( ( ) => browser . getUrl ( ) ) ;
332+ await browser . waitUntil ( async ( ) => await browser . getUrl ( ) ) ;
342333 const url = await browser . getUrl ( ) ;
343334 if ( url . match ( urlOrTitleToMatch ) ) {
344335 return tab ;
@@ -347,7 +338,7 @@ async function switchWindow(urlOrTitleToMatch) {
347338 /**
348339 * check title
349340 */
350- await browser . waitUntil ( ( ) => browser . getTitle ( ) ) ;
341+ await browser . waitUntil ( async ( ) => await browser . getTitle ( ) ) ;
351342 const title = await browser . getTitle ( ) ;
352343 if ( title . match ( urlOrTitleToMatch ) ) {
353344 return tab ;
@@ -369,7 +360,7 @@ Then(/a new window should open with "(.+)" in the (title|url)$/i, async (title,
369360 // The title will be 'Microsoft Dynamics 365' until the page loads, so it is
370361 // safe to wait for that title to transition, but then we need to wait for the
371362 // the actual title to be present to pass the vibe check
372- await switchWindow ( new RegExp ( `(${ title } )|(^ Microsoft Dynamics 365)` , 'i' ) ) ;
363+ await switchWindow ( new RegExp ( `(${ title } )|(Microsoft Dynamics 365)` , 'i' ) , currentWindow ) ;
373364 await browser . waitUntil ( async ( ) => {
374365 const title = await browser . getTitle ( ) ;
375366
0 commit comments