SDET- QA Automation Techie

Full Stack QA Automation Testing Blog

  • Home
  • Training
    • Online
    • Self-Paced
  • Video Tutorials
  • Interview Skills
    • HR Interview Questions Videos
    • Domain Knowledge
  • Career Guidance
  • Home
  • Software Testing
    • Manual Testing Tutorials
    • Manual Testing Project
    • Manaul Testing FAQS
    • ISTQB
    • AGILE
  • Web Automation Testing
    • Java Programmng
    • Python Programmng
    • Selenium with Java
    • Selenium with Python
    • Robot Framework(Selenium with Python)
    • selenium with Cucumber
    • TestNG+IntelliJ
    • Mobile App Testing(Appium)
    • JMeter
  • API Automation Testing
    • Rest Assured API Testing (BDD)
    • Rest Assured API Testing (Java+ TestNG)
    • Robot Framework(Rest API Testing with Python)
    • Postman
    • SoapUI
    • API Testing(FAQ's)
  • SDET|DevOps
    • Continuos Integration
    • SDET Essentials
    • AWS For Testers
    • Docker
  • SQL
    • Oracle(SQL)
    • MySQL for Testers
    • NoSQL
  • Unix/Linux
    • UNIX TUTORIALS
    • Linux Shell Scripting
  • ETL Testing
    • ETL Data warehouse Tutorial
    • ETL Concepts Tools and Templates
    • ETL Testing FAQ's
    • ETL Testing Videos
  • Big Data Hadoop
  • Video Tutorials
  • ApachePOI Video Tutorials
  • Downloads
    • E-Books for Professionals
    • Resumes
  • Automation Essencials
    • Cloud Technologies
      • Docker For Testers
      • AWS For Testers
      • Sub Child Category 3
    • Java Collections
    • Selenium Locators
    • Frequently Asked Java Programs
    • Frequently Asked Python Programs
    • Protractor
    • Cypress Web Automation

Handling Ratingstar Using Appium

 Handling Ratingstar Using Appium   

Rating 3 Star
import java.net.URL;
import java.util.List;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;

public class Example14Rating3Star {
   
    public static void main(String[] args) throws Exception {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);
               
        driver.findElementsById("android:id/text1").get(10).click(); //Views
               
        //scrolling down till we get the element
                MobileElement listitem = (MobileElement) driver.findElement(
                        MobileBy.AndroidUIAutomator(
                                "new UiScrollable(new UiSelector()).scrollIntoView("
                                        + "new UiSelector().description(\"Rating Bar\"));"));
               
                listitem.click(); //click on Seek Bar
   
   
        //Locate threeStarRatingbar.
        WebElement threeStarRatingbar = driver.findElementById("io.appium.android.apis:id/ratingbar1");
       
        //Get start point of threeStarRatingbar.
          int startX = threeStarRatingbar.getLocation().getX();
          System.out.println(startX);
       
         //Get end point of threeStarRatingbar.
          int endX = threeStarRatingbar.getSize().getWidth();
          System.out.println(endX);
         
          //Get vertical location of threeStarRatingbar.
              int yAxis = threeStarRatingbar.getLocation().getY();
                 
            //Set threeStarRatingbar tap position to set Rating = 1 star.
            //You can use endX * 0.3 for 1 star, endX * 0.6 for 2 star, endX * 0.9 for 3 star.
              int tapAt = (int) (endX * 0.9);   
           
              //Set threeStarRatingbar to Rating = 1.0 using TouchAction class.
                  TouchAction act=new TouchAction(driver); 
               
                 //act.press(tapAt,yAxis).release().perform();
                  act.press(PointOption.point(tapAt, yAxis)).release().perform();
                 
               
    }

}
Rating 5 Star

import java.net.URL;
import java.util.List;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;

public class Example14Rating5Star {
   
    public static void main(String[] args) throws Exception {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);
               
        driver.findElementsById("android:id/text1").get(10).click(); //Views
               
        //scrolling down till we get the element
                MobileElement listitem = (MobileElement) driver.findElement(
                        MobileBy.AndroidUIAutomator(
                                "new UiScrollable(new UiSelector()).scrollIntoView("
                                        + "new UiSelector().description(\"Rating Bar\"));"));
               
                listitem.click(); //click on Seek Bar
   
   
        //Locate threeStarRatingbar.
        WebElement threeStarRatingbar = driver.findElementById("io.appium.android.apis:id/ratingbar2");
       
        //Get start point of threeStarRatingbar.
          int startX = threeStarRatingbar.getLocation().getX();
          System.out.println(startX);
       
         //Get end point of threeStarRatingbar.
          int endX = threeStarRatingbar.getSize().getWidth();
          System.out.println(endX);
         
          //Get vertical location of threeStarRatingbar.
              int yAxis = threeStarRatingbar.getLocation().getY();
                 
              //Set fiveStarRatingbar tap position to set Rating = 4 star.
              //You can use endX * 0.2 for 1 star, endX * 0.4 for 2 star, endX * 0.6 for 3 star, endX * 0.8 for 4 star, endX * 1 for 5 star.
              int tapAt = (int) (endX * 0.6);   
           
              //Set threeStarRatingbar to Rating = 1.0 using TouchAction class.
                  TouchAction act=new TouchAction(driver); 
               
                 //act.press(tapAt,yAxis).release().perform();
                  act.press(PointOption.point(tapAt, yAxis)).release().perform();
                 
               
    }

}
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home
popup

Popular Posts

  • How To Explain Project In Interview Freshers and Experienced
    “ Describe an important project you’ve worked on ” is one of the most common questions you can expect in an interview. The purpose of a...
  • API/Webservices Testing using RestAssured (Part 1)
    Rest Assured : Is an API designed for automating REST services/Rest API's Pre-Requisites Java Free videos: https://www.you...
  • MANUAL TESTING REAL TIME INTERVIEW QUESTIONS & ANSWERS
    1. How will you receive the project requirements? A. The finalized SRS will be placed in a project repository; we will access it fr...

Facebook Page

Pages

  • Home
  • Resumes
  • Job Websites India/UK/US
  • ISTQB
  • Selenium with Java
  • E-Books for Professionals
  • Manual Testing Tutorials
  • Agile Methodology
  • Manual Testing Projects

Live Traffic

YouTube


Blog Visitors

Copyright © SDET- QA Automation Techie | Powered by Blogger
Design by SDET | Blogger Theme by | Distributed By Gooyaabi Templates