Automating star rating bar inwards appium android software attempt out is real easy, There volition live on star rating bar inwards many android software applications. Generally star rating bar is used to charge per unit of measurement products, services inwards eCommerce android software applications. Mostly you lot volition run across 3 star together with 5 star rating bars inwards such android software applications. If you lot wants to automate star ratings inwards appium android attempt out thence it is footling tricky but real tardily together with nosotros tin terminate create it using TouchAction class. Let's run across how tin terminate nosotros automate 3 star together with 5 star rating bars of android software application using appium amongst example.
Aim Of Test And App To Use
We wants to automate 3 star together with 5 star rating bars inwards android appium automation test. We volition purpose API Demos app to automate star ratings.
As you lot tin terminate run across inwards bellow image, We wants to give one star on 3 star rating bar together with four star on 5 star rating bar.
In API Demos app, Manually you lot tin terminate navigate to higher upwards covert from Views -> Rating Bar.
Create And Run Test
Create bellow given attempt out inwards eclipse together with run it using testng together with appium.
SetStarRating.java
package Android; import io.appium.java_client.TouchAction; import io.appium.java_client.android.AndroidDriver; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; world course of report SetStarRating { AndroidDriver driver; @BeforeTest world void setUp() throws Exception { DesiredCapabilities capabilities = novel DesiredCapabilities(); capabilities.setCapability("deviceName", "ZX1B32FFXF"); capabilities.setCapability("browserName", "Android"); capabilities.setCapability("platformVersion", "4.4.2"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("appPackage", "io.appium.android.apis"); capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos"); driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); // Scroll till chemical cistron which contains "Views" text If It Is non visible on screen. driver.scrollTo("Views"); // Click on Views. driver.findElement(By.name("Views")).click(); // Scroll till chemical cistron which contains "Rating Bar" text If It Is non visible on screen. driver.scrollTo("Rating Bar"); // Click on Rating Bar. driver.findElement(By.name("Rating Bar")).click(); } //Set 3 StarRatingbar = one star. @Test world void set3StarRatingbar(){ //Locate threeStarRatingbar. WebElement threeStarRatingbar = driver.findElement(By.id("io.appium.android.apis:id/ratingbar1")); //Get outset indicate of threeStarRatingbar. int startX = threeStarRatingbar.getLocation().getX(); System.out.println(startX); //Get destination indicate of threeStarRatingbar. int endX = threeStarRatingbar.getSize().getWidth(); System.out.println(endX); //Get vertical place of threeStarRatingbar. int yAxis = threeStarRatingbar.getLocation().getY(); //Set threeStarRatingbar tap seat to laid upwards Rating = one star. //You tin terminate purpose endX * 0.3 for one star, endX * 0.6 for ii star, endX * one for 3 star. int tapAt = (int) (endX * 0.3); //Set threeStarRatingbar to Rating = 1.0 using TouchAction class. TouchAction act=new TouchAction(driver); act.press(tapAt,yAxis).release().perform(); } //Set 5 StarRatingbar = four star. @Test world void set5StarRatingbar(){ //Locate fiveStarRatingbar. WebElement fiveStarRatingbar = driver.findElement(By.id("io.appium.android.apis:id/ratingbar2")); //Get outset indicate of fiveStarRatingbar. int startX = fiveStarRatingbar.getLocation().getX(); System.out.println(startX); //Get destination indicate of fiveStarRatingbar. int endX = fiveStarRatingbar.getSize().getWidth(); System.out.println(endX); //Get vertical place of fiveStarRatingbar. int yAxis = fiveStarRatingbar.getLocation().getY(); //Set fiveStarRatingbar tap seat to laid upwards Rating = four star. //You tin terminate purpose endX * 0.2 for one star, endX * 0.4 for ii star, endX * 0.6 for 3 star, endX * 0.8 for four star, endX * one for 5 star. int tapAt = (int) (endX * 0.8); //Set fiveStarRatingbar to Rating = four star using TouchAction class. TouchAction act=new TouchAction(driver); act.press(tapAt,yAxis).release().perform(); } @AfterTest world void End() { driver.quit(); } }
As you lot tin terminate run across inwards higher upwards test, I bring created 2 @Test methods. 1st @Test method volition give one star rating on 3 star rating bar together with sec @Test method volition give four star rating on 5 star rating bar. If you lot wants to increase or decrease star rating thence you lot tin terminate laid upwards value of tapAt every bit per your requirement every bit depict inwards attempt out comment.
This is the agency to handgrip star rating bar inwards android software application automation attempt out using appium.