Code Monkey home page Code Monkey logo

googlevoiceautoamtion's Introduction

Advanced Page Objects Pattern

Aim of this project is to show the Page Fragment concepts to create advanced page object pattern using Arquillian Graphene framework & its Fluent Waiting API.

More details are here.

Voice Search

This project also includes simple automation scripts to automate google voice search. We need a talking library to google voice search. I use freeTTS library. .

Demo

IMAGE ALT TEXT HERE

Talking Java

import com.sun.speech.freetts.VoiceManager;
  
public class SpeakUtil {
 
    static com.sun.speech.freetts.Voice systemVoice = null;
     
    public static void allocate(){
        systemVoice = VoiceManager.getInstance().getVoice("kevin16");
        systemVoice.allocate();
    }
     
    public static void speak(String text){
        systemVoice.speak(text);
    }
     
    public static void deallocate(){
        systemVoice.deallocate();
    }
}

Google search widget

public class GoogleSearchWidget {
     
    @FindBy(id="gsri_ok0")
    private WebElement microphone;
     
    @FindBy(name="q")
    private WebElement searchBox;
     
    @FindBy(name="btnG")
    private WebElement searchButton;
     
    public void searchFor(String searchString){
        searchBox.clear();
         
        //Google makes ajax calls during search
        int length = searchString.length();
        searchBox.sendKeys(searchString.substring(0, length-1));
        Graphene.guardAjax(searchBox).sendKeys(searchString.substring(length-1));
    }
     
    public void search(){
        Graphene.guardAjax(searchButton).click();
    }
     
    public void startListening(){
         
        //wait for microphone
        Graphene.waitGui()
                .until()
                .element(this.microphone)
                .is()
                .present();
         
        microphone.click();
         
        //wait for big microphone image to appear
        //this is when google starts listening
        Graphene.waitGui()
                .until()
                .element(By.id("spchb"))
                .is()
                .present();
    }
     
    public void stopListening(){
         
        //wait for the microphone image to hide
        //at this point google will stop listening and start its search
        Graphene.waitGui()
                .until()
                .element(By.id("spchb"))
                .is().not()
                .visible();
    }
     
    public String getVoiceSearchText(){
         
        Graphene.waitGui()
                .until()
                .element(this.searchBox)
                .is()
                .visible();
         
        return this.searchBox.getAttribute("value");
    }
}

TestNG Test

public class GoogleVoiceTest extends Arquillian{
     
    @Page
    Google google;
     
    @BeforeClass
    public void setup(){
        SpeakUtil.allocate();
    }
             
    @Test(dataProvider = "voiceSearch")
    public void googleVoiceSearchTest(String searchText){
         
        google.goTo();
         
        //start listening
        google.getSearchWidget().startListening();
         
        //speak the given text
        SpeakUtil.speak(searchText);
         
        //wait for google to stop listening
        google.getSearchWidget().stopListening();
         
        //assert if google has understood correctly
        Assert.assertEquals(searchText,
                            google.getSearchWidget().getVoiceSearchText().toLowerCase());
    }
     
    @DataProvider(name = "voiceSearch")
    public static Object[][] voiceSearchTestData() {
         
       //test data for google voice test
       return new Object[][] {
               {"weather today"},
               {"show me the direction for atlanta"},
               {"magnificent 7 show timings"},
               {"will it rain tomorrow"},
               {"arquillian graphene"}
       };
    }
     
    @AfterClass
    public void deallocate(){
        SpeakUtil.deallocate();
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.