This is the continuation of our guide on utilizing the Selendroid platform to streamline user actions on a mobile app. If you have not yet, be sure to check out our Getting Started with Selendroid Part 1 guide.
Selendroid boasts a robust testing instrument with various noteworthy characteristics.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
This powerful testing framework allows for interaction with several devices at once, making it incredibly efficient. With Selendroid, testing an app can be done without altering or modifying it in any way.
Our guide today will focus on how to utilize the Selendroid platform to automate user interactions on a mobile application (.apk files).
We are testing a recipe app that enables users to view, rank, and engage with the app, useful both online and offline.
Contents:
Script Expectations
- Start the server and Install the APK file (if not already installed)
- Launch the mobile application
- Access the menu list and go to a particular category
- Conduct an advanced search to filter recipes within the category
- Write a review for a recipe
- Verify the review you wrote
- See a catalog of all recipes made by the current recipe’s author
Setting Up the Application
For rating purposes, you require a user account on the BigOven app. These user details will be needed during the automation script testing.
Let’s start:
1) Confirm that the Selendroid server is operational by using the following command.
Example: java –jar selendroid-standalone-0.15.0-with-dependencies.jar –aut 250000RecipesBigOven.apk
Note: The application being tested is called 250000RecipesBigOven.apk.
2) Connect your device to your computer, assure the test environment is in USB debugging mode.
3) Confirm that the necessary Selendroid and Selenium jar files have been imported and attached to the libraries.
The first task is to create a new package.
Name the package:
The following task is to create a TestNG test case within the package.
Create a new TestNG Class:
1) Open the Eclipse project
2) Right-click on the package name (in this case, it’s SelendroidFirst)
3) Click on TestNG >> Create TestNG Class
Set the Class Name as ‘BigOven’
The Selendroid Script
Then, insert the following code into the ‘BigOven’ class you just created:
package SelendroidFirst; import io.selendroid.client.SelendroidDriver; import io.selendroid.client.TouchAction; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import io.selendroid.common.SelendroidCapabilities; import io.selendroid.common.device.DeviceTargetPlatform; import io.selendroid.standalone.SelendroidConfiguration; import io.selendroid.standalone.SelendroidLauncher; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.List; public class BigOven{ public SelendroidLauncher selendroidServer = null; public static WebDriver driver = null; @Test(groups= {"Example"}) public void BigOven() throws Exception { //**Configurations*// SelendroidConfiguration config = new SelendroidConfiguration();config.addSupportedApp ("D:AppiumAutomationSelendroidFirst250000RecipesBigOven.apk"); SelendroidLauncher selendroidServer = new SelendroidLauncher(config); selendroidServer.launchSelendroid(); SelendroidCapabilities caps = new SelendroidCapabilities(); caps.setAut("com.bigoven.android:3.3.1"); WebDriver driver = new SelendroidDriver(caps) ; caps.setEmulator(false); //**Access Recipe list of particular category**// driver.findElement(By.id("left_image")).click(); Listkg1=driver.findElement(By.id("kitchen_grid")).findElements(By.id("grid_item_layout")); for(WebElement kg2:kg1) { if(kg2.findElement(By.id("bottom_text")).getText().equals("Browse By Category")) { kg2.click(); break; } } Thread.sleep(2000); List kg4 = driver.findElement(By.id("select_dialog_listview")).findElements(By.id("text1")); for(WebElement kg3:kg4) { if(kg3.getText().equals("Breakfast")) { kg3.click(); break; } } //**Viewing Recipe Details page**// driver.findElement(By.id("menu_refine_search")).click(); List bs = driver.findElement(By.id("layout_search_by_ingredients")).findElement (By.id("buttons_layout")).findElements(By.id("search_ingredients_button")); Thread.sleep(2000); System.out.println(bs.get(0).getText()); bs.get(0).click(); Thread.sleep(2000); //**Adding Rating Review to a particular recipe**// List bl = driver.findElement(By.className("android.widget.ListView")).findElements (By.id("recipe_title")); for(WebElement bi : bl) { System.out.println(bi.getText()); } bl.get(0).click(); Thread.sleep(2000); driver.findElement(By.id("recipe_rate_text")).click(); Thread.sleep(2000); driver.findElement(By.id("username_edit")).sendKeys("[email protected]"); driver.findElement(By.id("password_edit")).sendKeys("xxxxxxx"); driver.findElement(By.id("login_button")).click(); Thread.sleep(2000); driver.findElement(By.id("review_comment")).sendKeys("Review Comment added by testuser"); driver.findElement(By.id("add_item")).click(); Thread.sleep(2000); driver.findElement(By.id("vp_reviews_layout")).findElement(By.id("vp_reviews_img")).click(); Thread.sleep(2000); List rl = driver.findElements(By.id("review_info")); List rc = driver.findElements(By.id("reviewer_comment")); WebElement rle = rl.get(0); WebElement rce = rc.get(0); if(rle.getText().contains("Testuser12345")&& rce.getText().equals("Review Comment added by testuser")) { System.out.println("Review added successfully"); } //**Viewing all the recipes added by the user**// driver.findElement(By.id("vp_recipe_layout")).findElement(By.id("vp_recipe_img")).click(); Thread.sleep(2000); String AuthorName = driver.findElement(By.id("recipe_author_name")).getText(); System.out.println("List of recipe created by Author: " + AuthorName); driver.findElement(By.id("recipe_author_image")).click(); Thread.sleep(2000); } @AfterTest public void afterClass() { if(driver!=null) { driver.quit(); } } }
After you have created the test script, it’s time to execute the Script.
Select the test case >> Right-click >> Run As >> TestNG Test.
Pictures of the App
Main screen:
List of categories:
Refining search page:
Viewing the Recipe Details:
Logging into BigOven:
Adding Review Comments:
Observing the added comment:
Following a successful test case execution, the execution results can be viewed. In TestNG, you can read the results from the “Results of running class BigOven” console output.