L&D series: Automation For Webview

Ferawati Hartanti Pratiwi
Inside Bukalapak
Published in
3 min readJun 14, 2020
https://www.digitalhrtech.com/wp-content/uploads/2020/02/Learning-development-jobs.jpg

Learning and Development chapter 1.

Let’s take a break from Golang. I’m using Java this time. For now, I’ll share a random article but it still related to automation. More precisely I will discuss how to automate webview with Appium.

Set Current Context

http://appium.io/docs/en/commands/context/set-context/

Details :

  • androidDriver as our driver. If we’re naming it with iosDriver or even just driver , we should rename it with the one we have.
  • allContext as our context such as native or web-view. If we’re not sure what context do we have, just System.out.println(context) inside the looping.
  • AFAIK webview context is always or maybe mostly have WEBVIEW. So we just need to check it first before moving the context.
  • Yeah, that’s it. With that code, we’ve already got a switch from native to webview. If we have more than 1 of webview context, just switch the context outside the looping because the webview probably has a different name.
  • Just change the if (context.contains("NATIVE")) if we’re willing to do the opposite or androidDriver.context("NATIVE"); without a conditional statement (just make sure that the context name is correct).

Find Element

http://appium.io/docs/en/commands/element/find-element/

Details :

  • We can use elements by their CSS, ID, Name, or XPath.
  • No need to define By.cssSelector(".qa-css") .

Get Text

http://appium.io/docs/en/commands/element/attributes/text/

Details :

  • First, find the element we want to get the text from.
  • We can use elements by their CSS, ID, Name, or XPath.
  • Appium has already provided a method getText() just use it to get much text that we want to validate.

Go To URL

http://appium.io/docs/en/commands/web/navigation/go-to-url/

Details :

  • Appium has already provided a method get() just use it to get into many URLs we want to go to.

Get Title

http://appium.io/docs/en/commands/web/window/title/

  • Appium has already provided a method getTitle() just use it to get the browser title of the current context.

Go Back

http://appium.io/docs/en/commands/web/navigation/back/

Details :

  • Appium has already provided a method back() just use it to get back to the previous page of our webview.

Refresh

http://appium.io/docs/en/commands/web/navigation/refresh/

Details :

  • Appium has already provided a method refresh() just use it to refresh our webview page.

Click

http://appium.io/docs/en/commands/element/actions/click/

Details :

  • First, find the element we want to be clicked.
  • We can use elements by their CSS, ID, Name, or XPath.
  • Appium has already provided a method click() just use it to tap any element in webview.

Send Keys

http://appium.io/docs/en/commands/element/actions/send-keys/

Details :

  • First, find the element we want to send the key's value.
  • We can use elements by their CSS, ID, Name, or XPath.
  • Appium has already provided a method sendKeys() just use it to send any value to some textfield.

Clear Element

http://appium.io/docs/en/commands/element/actions/clear/

Details :

  • First, find the element we want to clear the value.
  • We can use elements by their CSS, ID, Name, or XPath.
  • Appium has already provided a method clear() just use it to clear the value of some fields.

Delete All Cookies

http://appium.io/docs/en/commands/web/storage/delete-all-cookies/

Details :

  • Appium has already provided a method manage().deleteAllCookies() just use it to clear all of our webview browser cookies.

Switch To Frame

http://appium.io/docs/en/commands/web/frame/switch/

Details :

  • Appium has already provided a method switchTo().frame() just to switch the frame to whatever frame we want.

You can read more documentation in the Appium official website of course.

See you at my next Learning and Development chapter. — MperMperPisang

--

--

Ferawati Hartanti Pratiwi
Inside Bukalapak

QA (Quality Ambassador) | mpermperpisang official Medium account