CTRL Key Combination for Browser zoom not functional

Bug reports.
aaron.mckay
Posts: 7
Joined: Wed Feb 11, 2015 11:02 pm

CTRL Key Combination for Browser zoom not functional

Post by aaron.mckay » Thu Feb 19, 2015 1:16 am

Hi there,
We have occasional issues with our automation which is conducted in a remote desktop.
We've implemented all of the remote desktop aspects as per the user guides section "remotely working with ranorex"

But we are ending up occasionally with zoom problems caused by our use of scroll wheel usage and mouse click down and up on various web pages.

To get around this, we want to at the start of our test case to set zoom to 100%.
CTRL-0 is accepted by Chrome, Firefox and IE.

Within our API framework we have implemented the following method which doesn't work
(We also used D0)

public void SetBrowserTo100PercentZoom()
{
Keyboard.Down(Keys.ControlKey);
Keyboard.Down(0);
Keyboard.Up(0);
Keyboard.Up(Keys.ControlKey);
}

Also testing in Ranorex Studio we have also tried the same basic steps (see attached).
This isn't related to the website, it fails on a basic google search page
I've attached a zip of the studio project.

Happy if this is an issue with execution, but at this point it looks like a bug.
Thanks,
Aaron
Attachments
TestKeyboardpress.zip
Ranorex Studio project
(2.85 MiB) Downloaded 77 times

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: CTRL Key Combination for Browser zoom not functional

Post by krstcs » Thu Feb 19, 2015 4:16 pm

In order for the key strokes to be sent to the correct place, you need to make sure that the browser (not the DOM) has focus by using the following before you attempt to enter the key strokes:

Code: Select all

Keyboard.PrepareFocus(<Browser repo item>);
Shortcuts usually aren't...

aaron.mckay
Posts: 7
Joined: Wed Feb 11, 2015 11:02 pm

Re: CTRL Key Combination for Browser zoom not functional

Post by aaron.mckay » Tue Apr 14, 2015 2:09 am

Apologies for the delay, I didn't get an email regarding a response until I just manually checked.

I've modified my method to now include a

Keyboard.PrepareFocus("/form[@processname='chrome']");

And I'm still not capable of changing the browser zoom

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CTRL Key Combination for Browser zoom not functional

Post by Support Team » Tue Apr 14, 2015 4:53 pm

Hi Aaron,

May i ask you to try the following piece of code?
repo.BrowserForm.Self.Activate();
Keyboard.Down(WinForms.Keys.ControlKey);
Keyboard.Down(WinForms.Keys.D0);
Keyboard.Up(WinForms.Keys.D0);
Keyboard.Up(WinForms.Keys.ControlKey);
Whereby BrowserForm is the Formobject of your browser.

For example:

Code: Select all

/form[@processname='chrome']
Regards,
Markus (S)
.
Image

aaron.mckay
Posts: 7
Joined: Wed Feb 11, 2015 11:02 pm

Re: CTRL Key Combination for Browser zoom not functional

Post by aaron.mckay » Wed Apr 15, 2015 2:02 am

Excellent Thanks Markus. Small typo in that you needed an e on the end of Activat, but the
repo.BrowserForm.Self.Activate(); works fine in Ranorex Studio.

Going back to the original API requirement, I've been playing with what I assume is the equivalent which is
webDocument.Browser.Activate();
However how do I pass my form object to this method given that it takes no arguments.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CTRL Key Combination for Browser zoom not functional

Post by Support Team » Thu Apr 16, 2015 8:31 pm

Hi aaron,

Thank you for the hint, I've already updated the code snippet.

If you want to put this into a user code action, you can use the following approach:
public void Zoom(Ranorex.Adapter adapterObject)
{
var browserform = adapterObject.As<Form>();
browserform.Activate();
			
Keyboard.Down(WinForms.Keys.ControlKey);
Keyboard.Down(WinForms.Keys.D0);
Keyboard.Up(WinForms.Keys.D0);
Keyboard.Up(WinForms.Keys.ControlKey);
}
Now you can add this in your action table as shown in the screenshot below
UserCodeZoom.png
UserCodeZoom.png (4.86 KiB) Viewed 1533 times
Regards,
Markus (S)
.
Image

aaron.mckay
Posts: 7
Joined: Wed Feb 11, 2015 11:02 pm

Re: CTRL Key Combination for Browser zoom not functional

Post by aaron.mckay » Mon Apr 20, 2015 12:36 am

Hi Markus,
Just to repeat, I need the following code for an API based framework. We are not using Ranorex Studio as our IDE. I've tried to take this code into a basic C# script but I cannot get it to work.

I've copied the following code to assist.
Cheers,
Aaron

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ranorex;
using System.Windows.Forms;
using Ranorex.Core;

namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
//static int Main(string[] args)
public void TestMethod1()
{
System.Diagnostics.Process pr = System.Diagnostics.Process.Start("chrome.exe");
Ranorex.Form test = Host.Local.FindSingle<Ranorex.Form>("/form[@title='New Tab - Google Chrome']");
test.Activate();

Keyboard.Down(Keys.ControlKey);
Keyboard.Down(0);
Keyboard.Up(0);
Keyboard.Up(Keys.ControlKey);

}
}
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CTRL Key Combination for Browser zoom not functional

Post by Support Team » Tue Apr 21, 2015 3:43 pm

Hi aaron,

Please try the following code instead of your Keyboard actions:
Keyboard.Press(System.Windows.Forms.Keys.NumPad0 | System.Windows.Forms.Keys.Control, 82, Keyboard.DefaultKeyPressTime, 1, true);
Please do let me know if this also worked on your site.

Regards,
Markus
.
Image

aaron.mckay
Posts: 7
Joined: Wed Feb 11, 2015 11:02 pm

Re: CTRL Key Combination for Browser zoom not functional

Post by aaron.mckay » Thu Apr 23, 2015 5:45 am

Hi Markus,
The code is working in Chrome which is good to see.
In Firefox, you have to put a delay between the Process being started and the CTRL-0 which is fine.

However I can't get this to work in (typical) IE.
Any further ideas?

Thanks for your help so far,
Aaron

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CTRL Key Combination for Browser zoom not functional

Post by Support Team » Fri Apr 24, 2015 4:02 pm

Hi Aaron,

It is because IE doesn't recognize this combination when using the zero from the numeric keypad, so you can use the "normal" zero instead:
Keyboard.Press(System.Windows.Forms.Keys.D0 | System.Windows.Forms.Keys.Control, 11, Keyboard.DefaultKeyPressTime, 1, true);
Regards,
Markus
.
Image

aaron.mckay
Posts: 7
Joined: Wed Feb 11, 2015 11:02 pm

Re: CTRL Key Combination for Browser zoom not functional

Post by aaron.mckay » Tue Apr 28, 2015 1:08 am

Hi Markus,
Thank you very much for this. New code works fine for Chrome/Firefox and IE.
Very impressed by Ranorex Support.
Cheers,
Aaron