✔ Selenium 4: Minimize Browser Window | (Video 156)

Published: 02 November 2020
on channel: Rex Jones II
432
10

Selenium 4: Minimize Browser Window

► Watch Complete Selenium 4 Playlist/Series    • Selenium 4 New Features  

Video Chapters
0:00 Introduction
0:38 New Minimize Feature
4:58 Minimize via Set Position
6:15 Minimize via Robot Class

► Download Code, Presentation, & Transcript From GitHub https://github.com/RexJonesII/Free-Vi...

► Free Selenium PDF Book: https://www.rexjones2.com/book-seleni...
► Free Java PDF Book: https://www.rexjones2.com/book-part-1...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books

Social Media Contact
✔ YouTube    / rexjonesii  
✔ Twitter   / rexjonesii  
✔ LinkedIn   / rexjones34  
✔ GitHub https://github.com/RexJonesII/Free-Vi...
✔ Facebook   / jonesrexii  

► Transcript
In this session, let’s look at a new Selenium 4 feature to minimize the browser. We could always minimize the browser but this feature is built into Selenium. The other ways were to set the position of a window and to use the Robot Class. Personally, I like to watch the automation of our Test Scripts in a browser but if you have a requirement for minimizing the browser then this will help you out.

Also, if you are interested in more videos, you can subscribe to my YouTube channel and click the bell icon. Also, follow me on Twitter, connect with me on LinkedIn and Facebook.
We are going to use this Orange HRM site by entering the username, password, and clicking the button.

Username is Admin and Password is admin123. Inspect the Username and it shows txtUsername as the value for id, inspect the Password and it shows txtPassword as the value for id. Now, let’s inspect the button and it shows btnLogin as the value for id. To use the Robot Class, we select ALT + SPACE + N and do you see Minimize? That’s how we minimize using the Robot class.

Oh, by the way, this minimize feature became available in Selenium 4 Alpha 5. So far, this Test Script is set up for ChromeDriver and to load our AUT. Now, we write @Test
public void minimizeUsingNewFeature () {}
Import the @Test annotation from TestNG. Now, we write driver.manage().window(). Normally we select maximize but here’s minimize(). Enter the username driver.findElement(By.id(“txtUsername”)).sendKeys(“Admin”);
Enter the password driver.findElement(By.id(“txtPassword”)).sendKeys(“admin123”);
Next is to click the button driver.findElement(By.id(“btnLogin”)).click(); Let’s Run. It passed in 3.922 seconds.

I’ve seen it runs faster with minimize and also seen it run faster with maximize. Let’s run it with maximize and see what happens. @Test
public void maximizeWindow () {} Copy and Paste this code from minimize and change to minimize to maximize. Run. Maximize executed in 3.556 seconds

Now, let’s minimize the browser by setting the position and using the Robot class
Starting with set position, we write @Test public void minimizeUsingSetPosition () {}
driver.manage().window().setPosition(new Point(-2000, 0)); Import Point from the Selenium package. Point is a Selenium class that’s a copy of Java’s awt.Point package. It removed the dependency of awt. Copy and paste the same code. We’re finished with the Set Position test.

Next is the Robot class. @Test public void minimizeUsingRobotClass () {} Robot robot = new Robot (); Import Robot from java.awt then add throws declaration – select AWTException but we can also select Exception. First, we press the ALT Key by entering robot.keyPress(KeyEvent.VK_ALT); Now, let’s press the SPACE key. robot.keyPress(KeyEvent.VK_SPACE); Next is the N key robot.keyPress(KeyEvent.VK_N); We have to also release the keys so I’m going to copy these 3 statements, paste them and change Press to Release. For the last time, change Press to Release.

Now, let’s run all 4 of the methods: minimizUsingRobotClass, minimizeUsingSetPosition, maximizeWindow, and minimizeUsingNewFeature. Run All. We see the time for each Test Script and it looks like Robot class was the fastest. This time it showed maximize 2nd, minimize 3rd, and minimize using set position as the last for as speed Thanks for watching and I’ll see you in the next session.

#Selenium4 #Selenium4MinimizeWindow #MinimizeWindow


Watch video ✔ Selenium 4: Minimize Browser Window | (Video 156) online without registration, duration hours minute second in high quality. This video was added by user Rex Jones II 02 November 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 432 once and liked it 10 people.