lefthandedgoat / canopy

f# web automation and testing library, built on top of Selenium (friendly to c# also)
http://lefthandedgoat.github.io/canopy/
MIT License
506 stars 115 forks source link

positionBrowser units #444

Closed uzhas-sovka closed 6 years ago

uzhas-sovka commented 6 years ago

What are they? Definitely not pixels and not percentage of screen. I tried various values, and while the main law is obvious (the large the width, the larger browser window), I can't find any predictable numbers. Three machines with various resolutions give various screen coverage.

PS, Canopy is great, I use it literally every day.

amirrajan commented 6 years ago

Quick note that may get you the information you need: https://github.com/lefthandedgoat/canopy/blob/master/src/canopy/canopy.fs#L246

uzhas-sovka commented 6 years ago

Thanks for your reply, but this was my first search in Canopy repository.

uzhas-sovka commented 6 years ago

For example, x.positionBrowser 0 0 43 30 gives almost full width on 1024x768 monitor

What's 1024/43? 23.81. Inches? :)

lefthandedgoat commented 6 years ago

Sorry all of this got very goofy when I upgraded to .net core. I couldn't use Winforms anymore to automatically do it anymore.

From the docs

positionBrowser
Position current browser on the screen - position is in percentages: positionBrowser left top width height

You also have to set these values so that the percents work correctly.

https://github.com/lefthandedgoat/canopy/blob/master/src/canopy/screen.fs#L5-L7

you can also use the pin function to take up the left half the screen, right half, or full screen: http://lefthandedgoat.github.io/canopy/actions.html

It will require you to setup your resolution in the above linked code.

Sorry for the confusion!!

uzhas-sovka commented 6 years ago

Thanks for prompt reply. But it seems I have to re-compile Canopy for each machine?

screen.screenWidth <- 1078 let x = new Instance() //screen.screenWidth <- 1078 x.positionBrowser 0 0 50 30

doesn't work.

I know about the possibility to pin or to tile, but I have to stretch browser to full width and half height of screen...

uzhas-sovka commented 6 years ago

Fresh experiment. Real width is 1024.

screen.screenWidth <- 1024
let x = new Instance()
x.positionBrowser 0 0 80 30
browser occupies exactly full width (not 80%).

//screen.screenWidth <- 1024
let x = new Instance()
x.positionBrowser 0 0 80 30

browser extends far beyond right border.

So my initial guessing about re-compiling was wrong, the variable is used during test run. But in a strange manner... Surely I can measure a sort of pre-correction, but maybe there is some additional secret value, like "scale" or something...

lefthandedgoat commented 6 years ago

It may not be working correctly. I will look into it.

As far as recompiling, no you wont have to. You can set the screen sizes off of parameters or configuration. Also if you are not using .net core, you can use the Winforms methods to get the dimensions programmatically, I think I was using:

https://msdn.microsoft.com/en-us/library/system.windows.systemparameters.primaryscreenwidth.aspx https://msdn.microsoft.com/en-us/library/system.windows.systemparameters.primaryscreenheight.aspx

uzhas-sovka commented 6 years ago

Yes, I'm on vanilla 4.5.

lefthandedgoat commented 6 years ago

I have strange behavior too but I figured it out.

canopy.configuration.autoPinBrowserRightOnLaunch <- false
canopy.screen.screenHeight <- 2160
canopy.screen.screenWidth <- 3840

start chrome

positionBrowser 0 0 50 50

That works for me, but only if I turn off Windows 10's scale and layout. At 100% it does not work correctly, but at 100% it does. Can you see if yours is turned on?

image

uzhas-sovka commented 6 years ago

Yep! You are right! I'm on Windows 7, but the main idea is true: I've just turned scale down to 100% from 125%, and browser fit perfectly.

Thanks a lot!

lefthandedgoat commented 6 years ago

Add a reference to 'PresentationFramework' to your project and do

canopy.screen.screenHeight <- System.Windows.SystemParameters.PrimaryScreenHeight
canopy.screen.screenWidth <- System.Windows.SystemParameters.PrimaryScreenWidth

I just tested it and those values take into account the screen scaling.

Hope this resolves your issue!

uzhas-sovka commented 6 years ago

Works excellent with the minor change:

canopy.screen.screenHeight <- int System.Windows.SystemParameters.PrimaryScreenHeight
canopy.screen.screenWidth <- int System.Windows.SystemParameters.PrimaryScreenWidth

presentationframework.dll has to be added, the path is C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF on my system.