Join us on :

Url Command:

The browser.url(url) command opens the specified URL in the browser instance. The command takes a single string type parameter that is usually a URL of application under test


									browser.url('chercher.tech/practice/popups')
									


You might face below error when you use above command no-ftp-get-command-webdriverio

Whenever we pass the website address to the get() method. It first of checks for the protocol in the address, but in the above program we didnot mention any the protocol.

What is protocol ?
Protocol is simple it mention what kind of site is that.

  • http
  • https
  • ftp
  • file
Now let's add the protocol to the URL

									it('Get Command with WebdriverIO', () => {
										browser.url('https://chercher.tech/practice/popups')
									});
									

Get Title:

The getTitle() command is used to retrieve the title of the webpage the user is currently working on. A null string is returned if the webpage has no title. The command doesn’t require any parameter and returns a trimmed string value


									browser.getTitle()
									

Get Current URL Command:

The browser.getUrl() command is used to retrieve the URL of the webpage the user is currently accessing. The command doesn't require any parameter and returns a string value


									browser.getUrl()
									

Get Page Source Command:

The getPageSource() command is used to retrieve the page source of the webpage the user is currently accessing. The command doesn’t require any parameter and returns a string value


									browser.getPageSource()
									


Complete code


									it('get page title with WebdriverIO', () => {
										browser.url('https://chercher.tech/practice/popups')
										console.log(browser.getTitle()); 
										console.log(browser.getUrl());
										console.log(browser.getPageSource());
									});
									

Maximize a browser:

In WebdriverIO as we open a browser sometime it may not open on full screen, thus it is a good practice to maximise a browser at time it open.

WebdriverIO provides maximizeWindow() function to maximize the current browser window.


									browser.maximizeWindow()
									

Size & Position of Browser in Webdriver

Sometimes you need to set window position and size or get window size and position. In selenium software test. WebdriverIO software testing tool has many useful methods using which we can play with web browser window for different purpose.

What Is window size and position?

  • Window size means height and width of window.
  • Window position means distance of window from left side(X Coordinates) of screen and top side(Y Coordinates) of screen.
size-position-of-window-webdriverio

Set Size of window

We can use setWindowSize() function to set the size of window in webdriverio. We can set window width to 400 and height to 500 dimensions using bellow given syntax


									browser.setWindowSize(400, 500)
									

Get Size of window

We can use getWindowSize() method to get size of window. Below given syntax will return window height and width.


									it('Browser Commands with WebdriverIO', () => {
										browser.url('https://chercher.tech/practice/popups')
										browser.setWindowSize(400, 500)
										console.log(browser.getWindowSize())
									});
									


Output of the window size


									{ height: 500, width: 400 }
									

Set position of the Browser

We can set the postion of the browser window using setWindowPosition

Get position of the Browser

Use getWindowPosition() to get window position.


									it('getWindowPosition Commands with WebdriverIO', () => {
										browser.url('https://chercher.tech/practice/popups')
										browser.setWindowPosition(400, 500)
										console.log(browser.getWindowPosition())
										console.log(browser.getWindowPosition().x)
										console.log(browser.getWindowPosition().y)
									});
									

navigateTo(url: string):

navigateTo() function takes the user to given webpage based on the url passed.

back()

WebdriverIO provides back() command to move backwards in the browser's history.

forward()

forward() command moves forward in a browser history.

refresh()

refresh() function refreshes the current webpage in WebdriverIO


									it('Navigation Commands in WebdriverIO', () => {
										browser.url('https://chercher.tech/practice/popups')
										browser.url("http://google.com")
										browser.back()
										console.log(browser.getTitle())
										browser.forward()
										console.log(browser.getTitle())
										browser.refresh()
										console.log(browser.getTitle())
									});
									


navigation-comands-webdiverio

About Author

Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know. Knowledge is the only thing that doubles when you spend it.

I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions