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

Extend _WD_Window() function by _WD_Window($sSession, 'restore') #514

Open
Sven-Seyfert opened this issue Apr 19, 2024 · 15 comments · May be fixed by #515
Open

Extend _WD_Window() function by _WD_Window($sSession, 'restore') #514

Sven-Seyfert opened this issue Apr 19, 2024 · 15 comments · May be fixed by #515

Comments

@Sven-Seyfert
Copy link
Contributor

Sven-Seyfert commented Apr 19, 2024

Feature request

Is your feature request related to a problem? Please describe

On this forum thread were the question about How to restore the driver window?. After some tryouts and research it became clear that it was already possible with _WD_Window($sSession, 'rect' ...), but this was not so easy to understand and not intuitive.

Describe the solution you'd like

So I suggest to extend the function by a 'restore' command which should be more intuitive or for some even more familiar like in other frameworks like Selenium or WebdriverIO. Code changes are visible in PR #515 👀 .

Describe alternatives you've considered

Alternatives? Leave it as it is and the next question about the usage of 'rect' will come I predict 😅 .

Additional context

Use Case:
You start with a sized driver window (by the "args" capability), e. g. 1440x810, and you will use _WD_Window($sSession, 'maximize') to maximize the driver window, then later on you want to get back to the previous size, you only have to use _WD_Window($sSession, 'restore'). Done.

Influences and relationship to other functionality

Only _WD_Window related.

@Sven-Seyfert Sven-Seyfert linked a pull request Apr 19, 2024 that will close this issue
9 tasks
@Sven-Seyfert
Copy link
Contributor Author

I tested the change on the current Chrome, Firefox and MSEdge drivers.

@Danp2
Copy link
Owner

Danp2 commented Apr 21, 2024

Did you happen to test this using null instead of 0 for the parameters? I believe that would be more inline with the WD specs if that provides the same functionality.

@mlipok
Copy link
Contributor

mlipok commented Apr 21, 2024

@Sven-Seyfert could you please provide modified UserTesting() function to use it with wd_demo.au3

#Region - UserTesting
Func UserTesting()
.....
EndFunc   ;==>UserTesting
; if necessary, add any additional function required for testing within this region here
#EndRegion - UserTesting

@Sven-Seyfert
Copy link
Contributor Author

Sven-Seyfert commented Apr 22, 2024

Did you happen to test this using null instead of 0 for the parameters? I believe that would be more inline with the WD specs if that provides the same functionality.

You are right @Danp2 , the null variant is better and works in the same way.

But I also encountered that my syntax for the "rect" POST (basically taken from Nine on the forum thread) was not the exact one. I mean, the restore POST request is basically the same as the resize variant => both by /session/{session id}/window/rect. So I tested again with more variants then only sized window > maximized window > restore window.

I will show it in the UserTesting section like @mlipok already suggested 🤝 .

Best regards
Sven

Update:
New commit with the correct syntax is available for the PR #515 😀 .

@Sven-Seyfert
Copy link
Contributor Author

Sven-Seyfert commented Apr 22, 2024

@Sven-Seyfert could you please provide modified UserTesting() function to use it with wd_demo.au3

Do you mean I should provide a temporary example in this UserTesting() function or do you mean I should expand the function permanently and commit this change too?

I will show the example here as UserTesting() function and then we can see how to proceed, okay @mlipok ?

Best regards
Sven

@Sven-Seyfert
Copy link
Contributor Author

Sven-Seyfert commented Apr 22, 2024

@mlipok I hope you meant this:

#Region - UserTesting
Func UserTesting()
	; if necessary, you can modify the following function content by replacing, adding any additional function required for testing within this function
	Local $vResult
	$vResult = _WD_Navigate($sSession, 'https://www.google.com')
	If @error Then Return SetError(@error, @extended, $vResult)

	$vResult = _WD_LoadWait($sSession, 10, Default, Default, $_WD_READYSTATE_Interactive)
	If @error Then Return SetError(@error, @extended, $vResult)

	MsgBox(64, '_WD_Window', StringFormat( _
		'1. Window will be set to 1440x810\n' & _
		'2. Window will be restored to default\n' & _
		'3. Window will be maximized\n' & _
		'4. Window will be restored\n' & _
		'5. Window will be set to 1920x1080\n' & _
		'6. Window will be set to fullscreen\n' & _
		'7. Window will be restored again\n' & _
		'8. Window will be set to 1440x810'))

	Local Const $sResizeParametersA = '{"x": null, "y": null, "width": 1440, "height": 810}'
	Local Const $sResizeParametersB = '{"x": null, "y": null, "width": 1920, "height": 1080}'

	ConsoleWrite('1. Window will be set to 1440x810' & @CRLF)
	_WD_Window($sSession, 'rect', $sResizeParametersA)
	Sleep(500)

	ConsoleWrite('2. Window will be restored to default' & @CRLF)
	_WD_Window($sSession, 'restore')
	Sleep(500)

	ConsoleWrite('3. Window will be maximized' & @CRLF)
	_WD_Window($sSession, 'maximize')
	Sleep(500)

	ConsoleWrite('4. Window will be restored' & @CRLF)
	_WD_Window($sSession, 'restore')
	Sleep(500)

	ConsoleWrite('5. Window will be set to 1920x1080' & @CRLF)
	_WD_Window($sSession, 'rect', $sResizeParametersB)
	Sleep(500)

	ConsoleWrite('6. Window will be set to fullscreen' & @CRLF)
	_WD_Window($sSession, 'fullscreen')
	Sleep(500)

	ConsoleWrite('7. Window will be restored again' & @CRLF)
	_WD_Window($sSession, 'restore')
	Sleep(500)

	ConsoleWrite('8. Window will be set to 1440x810' & @CRLF)
	_WD_Window($sSession, 'rect', $sResizeParametersA)
	Sleep(500)
EndFunc   ;==>UserTesting

; if necessary, add any additional function required for testing within this region here
#EndRegion - UserTesting

It works fine with Chrome, Firefox and MSEdge (current versions, on my system) ✅ .

grafik

@mlipok
Copy link
Contributor

mlipok commented Apr 22, 2024

Will check ASAP

@mlipok
Copy link
Contributor

mlipok commented Apr 25, 2024

@mlipok I hope you meant this:

some small changes:

Func UserTesting()
	; if necessary, you can modify the following function content by replacing, adding any additional function required for testing within this function
	Local $vResult
	$vResult = _WD_Navigate($sSession, 'https://www.google.com')
	If @error Then Return SetError(@error, @extended, $vResult)

	$vResult = _WD_LoadWait($sSession, 10, Default, Default, $_WD_READYSTATE_Interactive)
	If @error Then Return SetError(@error, @extended, $vResult)

	MsgBox(64, '_WD_Window', StringFormat( _
		'1. Window will be set to 1440x810\n' & _
		'2. Window will be restored to default\n' & _
		'3. Window will be maximized\n' & _
		'4. Window will be restored\n' & _
		'5. Window will be set to 1920x1080\n' & _
		'6. Window will be set to fullscreen\n' & _
		'7. Window will be restored again\n' & _
		'8. Window will be set to 1440x810'))

	Local Const $sResizeParametersA = '{"x": null, "y": null, "width": 1440, "height": 810}'
	Local Const $sResizeParametersB = '{"x": null, "y": null, "width": 1920, "height": 1080}'

	ConsoleWrite('1. Window will be set to 1440x810' & @CRLF)
	_WD_Window($sSession, 'rect', $sResizeParametersA)
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after set to 1440x810')

	ConsoleWrite('2. Window will be restored to default' & @CRLF)
	_WD_Window($sSession, 'restore')
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after restored to default')

	ConsoleWrite('3. Window will be maximized' & @CRLF)
	_WD_Window($sSession, 'maximize')
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after maximized')

	ConsoleWrite('4. Window will be restored' & @CRLF)
	_WD_Window($sSession, 'restore')
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after restored')

	ConsoleWrite('5. Window will be set to 1920x1080' & @CRLF)
	_WD_Window($sSession, 'rect', $sResizeParametersB)
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after set to 1920x1080')

	ConsoleWrite('6. Window will be set to fullscreen' & @CRLF)
	_WD_Window($sSession, 'fullscreen')
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after set to fullscreen')

	ConsoleWrite('7. Window will be restored again' & @CRLF)
	_WD_Window($sSession, 'restore')
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after restored again')

	ConsoleWrite('8. Window will be set to 1440x810' & @CRLF)
	_WD_Window($sSession, 'rect', $sResizeParametersA)
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after set to 1440x810')

EndFunc   ;==>UserTesting

@mlipok
Copy link
Contributor

mlipok commented Apr 25, 2024

I tested it with all browsers only opera act differently some kind of weired but it is not related to your proposal.

All browsers have do the same actions but none of them takes any visual actions on any of restored action.

@Sven-Seyfert
Copy link
Contributor Author

Sven-Seyfert commented Apr 25, 2024

All browsers have do the same actions but none of them takes any visual actions on any of restored action.

What do mean by "visual actions" here @mlipok 🤔 ? Do you mean nothing will be restored? Of course you have to take my changes in the PR #515 to test it. But I am pretty sure you did this. So what should be a visual change?

With the restore action, the windows size changes - correctly in my test cases.

Best regards
Sven

@mlipok
Copy link
Contributor

mlipok commented Apr 25, 2024

eee.... must to review again.... not updated to your version.
What a dump situation from my side.

@mlipok
Copy link
Contributor

mlipok commented Apr 25, 2024

after browser is initialized let say this was STEP 0

in STEP 1 window is moved

	ConsoleWrite('1. Window will be set to 1440x810' & @CRLF)
	_WD_Window($sSession, 'rect', $sResizeParametersA)
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after set to 1440x810')

In STEP 2 No visual change - I was expecting that the window will back to size and position which was just after STEP 0 and before STEP 1

	ConsoleWrite('2. Window will be restored to default' & @CRLF)
	_WD_Window($sSession, 'restore')
	MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 'after restored to default')

all further STEPS works well.

@Sven-Seyfert
Copy link
Contributor Author

No worries @mlipok . I am happy that you take the time to review and test it, thank you 😊 . You don't have to hurry up.

@mlipok
Copy link
Contributor

mlipok commented Apr 25, 2024

Aa you can see above I was able to test it again ;)

@Sven-Seyfert
Copy link
Contributor Author

In STEP 2 No visual change - I was expecting that the window will back to size and position which was just after STEP 0 and before STEP 1

You're right. I think this is intended behavior. Only actions like "minimized", "maximized" and "fullscreen" can be restored. See resizing-and-positioning-windows.

only opera act differently some kind of weired

That is also correct. Unfortunately because of the browser_compatibility, I guess.

👉 That's the behavior of the "rect" endpoint /session/{session id}/window/rect. We can not change it in au3WebDriver 😔 . But at least we have a small improvement of the "rect" endpoint handling 😀 .

@Danp2 Danp2 changed the title Extent _WD_Window() function by _WD_Window($sSession, 'restore') Extend _WD_Window() function by _WD_Window($sSession, 'restore') Apr 27, 2024
@Danp2 Danp2 linked a pull request Apr 28, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants