2

I am using Robot IDE for creating robot automation test scripts. For my test when I start audio call then browser is asking for the permission with "Allow" and "Block" buttons. So as it's a web based alert/popup dialog I can't able to access it in my robot script. If I am clicking on "Allow" button manually then it proceeds the test and passes successfully but I need to click it manually.

For Image, please click here

As you can see from the image I want to click on Allow button which is necessary to go ahead in my test.

So can anyone know how can I click on the "Allow" button of the browser confirmation popup via robot test script.

Thanks in advance!

My project structure is

enter image description here

user2235971
  • 33
  • 1
  • 1
  • 7
  • Have you tried using the [Dismiss alert](http://robotframework.org/Selenium2Library/Selenium2Library.html#Dismiss%20Alert) keyword? – Bryan Oakley Apr 13 '17 at 11:46
  • @BryanOakley, Yes I have used that keyword but it gives error "There were no alerts" and fails the test case – user2235971 Apr 13 '17 at 12:14
  • Possible duplicate of [How do i allow Chrome to use my microphone programatically?](http://stackoverflow.com/questions/38832776/how-do-i-allow-chrome-to-use-my-microphone-programatically) – A. Kootstra Apr 13 '17 at 19:30
  • @A.Kootstra, Do you know how can I use it in Robot framework? – user2235971 Apr 14 '17 at 09:21

1 Answers1

2

The Chrome settings that drive this functionality can be viewed using the chrome://settings/. These settings are stored in the Chrome Profile. The path to this profile can be found using chrome://version/. In the preferences file a JSON structure of settings can be found.

In the below Robot Framework example the script opens Google and then clicks on the microphone icon to start the voice search. Under normal circumstances this results in a pop-up for microphone access.

The reason the assignment is split into two variables is because the url contains characters (. : //) that are considered separators. This is then overcome by creating that part of the structure manually: Create Dictionary https://www.google.nl:443,*=${SiteOptions}.

This then results in the desireable preference structure:

...
"profile":{
     ...
     "content_settings": {
         ...
         "exceptions": {
            ...
            "media_stream_mic":{
               "https://www.google.nl:443,*":{
                  "last_used":1492245954.955647,
                  "setting":1
               }
            },

Robot Script:

*** Settings ***
Library    Selenium2Library    

*** Test Cases ***

 Chrome With Preferences
    ${chrome_options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver

    &{SiteOptions}         Create Dictionary    last_used=${1470931206}     setting=${1}
    &{media_stream_mic}    Create Dictionary    https://www.google.nl:443,*=${SiteOptions}
    ${prefs}               Create Dictionary    profile.content_settings.exceptions.media_stream_mic=${media_stream_mic}

    Call Method    ${chrome_options}    add_experimental_option    prefs    ${prefs}

    Create WebDriver    Chrome    chrome_options=${chrome_options}

    Go To    https://google.com

    Click Link    css=#gs_st0 > a    # Click the search microphone icon.

    sleep     5s
    [Teardown]    Close Browser
A. Kootstra
  • 6,827
  • 3
  • 20
  • 43
  • I have my project structure which is designed by my superiors as per Jenkins and I didn't know where to put & set the preferences. – user2235971 Apr 25 '17 at 11:08
  • This is something that would require more information to answer, and really is a separate question in itself. The above script is Test Code, and I suspect is stored in the ./tests folder of your project. Look for the `Create Webdriver` keyword in the `.robot` files and that is the location where to make the changes. If you find multiple results, then this also means multiple things to change. – A. Kootstra Apr 25 '17 at 12:42
  • A. Kootstra Thanks for the quick reply. I will try the solution provided by you in my Project. – user2235971 Apr 25 '17 at 12:49
  • With using the following code it solved my issue. ${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver Call Method ${options} add_argument start-maximized Call Method ${options} add_argument --use-fake-ui-for-media-stream Call Method ${options} add_argument --use-fake-device-for-media-stream ${executor}= Evaluate str('${HOME_URL}') Create WebDriver ${CHROME_BROWSER} chrome_options=${options} Goto ${HOME_URL} – user2235971 Oct 11 '17 at 13:04