Current Date :March 29, 2024
Tips and Tricks For Appium and Selenium

Tips and Tricks For Appium and Selenium

Selenium and Appium are two popular automation testing tools. Selenium is largely leveraged for testing web applications whereas Appium is broadly used for testing mobile applications.

Bundled with various features, both these tools are extremely recommended for software testing. But you require to have a proper understanding of these appium and selenium tools to get amplest out of them. 

There are a few tips and tricks that can assist you to get the best out of these tools and leverage them to their best capabilities.

Let’s make our job simpler with these veteran Tips and Tricks about Appium and Selenium.

The Use of Waits: 

Using Thread.Sleep() is a popular method of “waiting” while any processing is operating on. But it possesses a few disadvantages. Here is how we can overcome it.

a)    WebDriverWait.  It census your query every 500ms, and return when the wait condition is satisfied. WebDriverWait can explicitly set a maximum threshold to escape locks and infinite waiting.

b)    FindElementBy / FindElement(..): Second method is by invoking FindElementBy or just FindElement(..). FindElementBy waits until the element is detected and returns null if the maximum wait time passes. But ensure you have to explicitly configure the inevitable waits.

1. Locating Elements

Locating elements is not a difficult job in selenium and there are multiple ways to do it. But the haunting section is getting StaleElementReferenceException.

It occurs when you assign an IWebElement reference but it already has some other location in the DOM. The answer to StaleElementReferenceException is to re-query and reassign the element reference.

LOOKING FOR A DEDICATED TEAM TO ENHANCE YOUR PRODUCT’S QUALITY

2. Sending Keyboard Input

Selenium allows sending inputs in two ways. First is by setting “value” property of editable elements by using ExecuteScript() / ExecuteAsyncScript(). Second is to use SendKeys() API.

I would suggest you use ExecuteScript() / ExecuteAsyncScript() method when you are more concerned about filling in a few fields and when you are not concerned about DOM events being fired and concurrent character-by-character verification.

But if you want to concentrate on real-time validation, the second method i.e. using SendKeys() API will be more suitable for you.

3. Executing JavaScript code

You can perform JavaScript in either of the below-given ways depending upon your requirements.

i)    ExecuteScript().ExecuteScript() does not perform the next line of test code till script execution is returned.

ii)    ExecuteAsyncScript() does not block your test code.

4. Drag & Drop Interfaces

Action Builder API and the “DragAndDrop” and “DragAndDropToOffset” ways support an easy drag and drop interface in Selenium.

5. Switching between windows and iframes

You can simply switch between windows and frames in Selenium.

  • For iFrames

driver.SwitchTo().Frame(frameElement); //IWebElement

  • For Windows

driver.SwitchTo().Window(handle);// driver window handle and then can switch back to the original window by using

driver.SwitchTo().DefaultContent();

  • Using drivers for multiple browsers

When utilizing the driver API, always refer to it by applying RemoteWebDriver class

for all the browsers employed for running tests.

It is suitable to label your environment in a text/XML file and then deconstruct this and return the right driver instance.

6. Cleaning Up

When you are done with your testing, you require to free all the resources and close the browser.

For this you can use Close(), Quit(), and Dispose().  Quit() closes all browsers, close() closes the current browser while Dispose() calls the quit() and closes all browsers.

Now when we are done with a few tips and tricks of operating with selenium, let us now get better at our Apium skills.

Appium is one of the generally used mobile app testing tools. Though its users encounter some general problems while using it.

Here are some tips and tricks that can assist you to handle some general problems faced in using it and performing its working more efficiently and effectively.

7. Writing cross-platform tests 

One of the major problems in testing mobile apps is we have to write various test scenarios for Android and iOS. Having regular tests can be a big advantage in terms of saving time and effort.

Though it gets much simpler having the same set of test cases for both if your application is the same from a UI point of view.

Just ensure that the accessibility IDs on corresponding UI elements in every version of the app match with each other. If it holds true, you can run the same test on both applications. Also, be certain your test sets up the suitable capabilities for each platform.

Based on various platforms, here are some more and little-known tips and tricks about Appium that can make your testing simpler.

8. For All Platforms

AutoWebView – it is very helpful for Cordova apps and helps to begin in the webview context.

9. For Android

  • ignoreUnimportantViews – It is a very useful method to quicken your Android tests.
  • nativeWebScreenshot – Assists you to take a screenshot from UI Automator. It is very useful if your screenshots from the chrome driver are not as required.

10. For IoS

  • locationServicesAuthorized – It assists you to stop showing an alert when you are working to use the user’s location by pre-authorizing location services.
  • Auto[Accept|Dismiss]Alerts – It assists you to avoid alerts from disrupting your tests.
  • nativeWebTap – Grants users to use non-javascript taps.
  • safariIgnoreFraudWarning – It is useful in cases where your test environment doesn’t have a 100% perfect SSL setup.
  • interKeyDelay – Seldom Appium’s typing speed can cause difficulty with your application, in such cases, interKeyDelay can avoid the problem.
  • sendKeyStrategy – Helps in avoiding the keyboard completely.

11. Networking Conditioning

You can use driver.setNetworkConnection(value) to simulate different states of connectivity when you run your tests.

Also Read: Why Appium Is Perfect For IOS And Android App Testing

Hope these tips will demonstrate helpful to you, will be back soon with some extra useful testing tips and skills. So stay tuned!

At TestUnity, we strive for the highest quality in every project, and our professional QA specialists are ready to ensure it. Contact us if you’re looking for a dedicated team to enhance your product’s quality.

Share

Testunity is a SaaS-based technology platform driven by a vast community of testers & QAs spread around the world, powered by technology & testing experts to create the dedicated testing hub. Which is capable of providing almost all kind of testing services for almost all the platforms exists in software word.

Leave a Reply

Your email address will not be published. Required fields are marked *