• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • Alles
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DevOps
    • Digital Days
    • Docker
    • eHealth
    • Enterprise Architecture
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • Alles
    • Bloggers
    • Speakers
Home » How to resize your browser window to test responsive design with CodedUI
  • How to resize your browser window to test responsive design with CodedUI

    • By Marcel de Vries
    • .NET 8 years ago
    • .NET 0 comments
    • .NET .NET
    How to resize your browser window to test responsive design with CodedUI

    *Moved to: http://fluentbytes.com/how-to-resize-your-browser-window-to-test-responsive-design-with-codedui/

    A question I have had a lot lately is how to test your websites responsive UI design with codedUI.

    the main requirement here is that you would be able to check if you can enter values on a specific screen in different browsers in different window sizes.

    So starting the browser in CodedUI is simple, you just use the BrowserWindow class and call the Launch method to start the browser in a reliable way. Starting different browsers (Chrome, firefox) is also possible by just setting the BrowserWindow.CurrentBrowser to a value of “chrome” or “firefox” so that is already solved.

    the main issue is the size of the browser window. For the responsive UI to show, you need to run a test case in e.g. different screen sizes. Unfortunately there is no method on the BrowserWindow class to set the screen size of the browser.

    But there is an easy fix for that.

    The BrowserWIndow class has a property called WindowHandle. We can use this property to call a windows API to resize the window.

    Here you have a Extension method that I created to fix this issue

     

    public static class BrowserWindowExtensions
    {
        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool SetWindowPos(IntPtr hWnd, IntPtr hwndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
    
        public static void ResizeWindow(this BrowserWindow control , int width, int height)
        {
            //Call the native method to resize the window
            SetWindowPos(control.WindowHandle ,(IntPtr)(-1), 0, 0, width, height, 0x0002 | 0x0040);
        }
    }
    

    The way you make this work in your CodedUI tests is as follows:

    [TestMethod]
    public void CodedUITestMethod1()
    {
        //BrowserWindow.CurrentBrowser = "chrome";
        //BrowserWindow.CurrentBrowser = "firefox";
        var bw = BrowserWindow.Launch("http://getbootstrap.com/2.3.2/");
        // first maximize the browser
        bw.Maximized = true;
        HtmlHyperlink link = new HtmlHyperlink(bw);
        link.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Base CSS");
        // now set the control to always search and eliminate the cache
        // so it will search again when I resize the window
        link.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
        
        Mouse.Click(link);
    
        // now resize the browserwindow to the size of the mobile
        // e.g.:
        // QVGA: quarter VGA (240×320 pixels)
        // HVGA: half VGA (320×480 pixels)
        // WVGA: wide VGA (480×800 pixels)
        // FWVGA: full wide VGA (480×854 pixels)
        // nHD: one-ninth high definition (360×640 pixels)
        // qHD: one-quarter high definition (540×960 pixels)
        bw.ResizeWindow(480, 800);
        // now go back ant try again
        bw.NavigateToUrl(new Uri("http://getbootstrap.com/2.3.2/"));
        // now try and search for the control again, this should fail, because 
        // it is now initialy hidden
        // I need to reveal it first before I can click
        bool exceptionraised = false;
        try
        {
            Mouse.Click(link);
        }
        catch (Exception) { exceptionraised = true; }
    
        Assert.IsTrue(exceptionraised);
    }
    

    Hope this helps you solve this little inconvenience …

    Follow my new blog on http://fluentbytes.com

    Share this

Marcel de Vries

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • Innovative patterns in software quality management

    Innovative patterns in software quality management Tom van den Berg - 1 month ago

  • Developing a Service Fabric service using another host

    Developing a Service Fabric service using another host Tim van de Lockand - 5 months ago

  • Adding a package to your private WinGet.RestSource feed…

    Adding a package to your private WinGet.RestSource feed… Léon Bouquiet - 10 months ago

Related downloads

  • Beslisboom voor een rechtmatig ‘kopietje productie’

  • Klantreferentie: Remmicom zet wetgeving om in intellige…

  • Klantreferentie RDW: Samenwerken voor veilig en vertrou…

  • Klantreferentie BeFrank: Strategische IT voor een innov…

  • Wie durft te experimenteren met data in de zorg?

Related videos

  • mijnverzekeringenopeenrij.nl

    mijnverzekeringenopeenrij.nl

  • Winnaar | Innovation Projects 2017

    Winnaar | Innovation Projects 2017

  • Explore | Info Support & HAN & Poliskluis

    Explore | Info Support & HAN & Poliskluis

  • Info Support | Bedrijfsfilm

    Info Support | Bedrijfsfilm

  • LifeApps bij HagaZiekenhuis

    LifeApps bij HagaZiekenhuis

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel
Altijd actief
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Beheer opties Beheer diensten Beheer leveranciers Lees meer over deze doeleinden
Voorkeuren
{title} {title} {title}