Can anyone help me with how to automate play/pause video present on the web page using Selenium..
Thanks in advance...
This is extremely dependent on the browser and the player handling the video. You'll need to use the JavaScript executor, most likely.
I was discussing this last night with a pal and he came up with the following example using the Python variant of Webdriver for a demo video from html5demos.com:
driver = webdriver.Firefox()
driver.get("http://html5demos.com/video")
driver.execute_script('document.getElementsByTagName("video")[0].play()')
You can also "pause" where the "play" is used.
There's a larger question here: what are you actually trying to verify? That simply playing and pausing doesn't throw any errors? Make sure you know what you're validating and that it makes sense to actually work to automate the video test versus just leaving that particular use case to a manual test. (Though you could use the above script to get you to that point!)
** EDIT: Check out this bit of Python code (not mine) which exposes a "Paused" property. Now you could at least validate video loads, starts, and can be stopped. I'm still skeptical of the use of this sort of test, but at least it's a start.
By Using FlashObjectwebDriver !
Now what is FlashObjectWebDriver ?
FlashObjectWebDriver is an interface under Webdriver Library.
FlashObjectWebDriver has a Method called : callFlashObject
callFlashObject method can be over loaded using arguments ie.
callFlashObject(“Play”) : For Playing the Flash
callFlashObject(“Pause”) : For Pausing the Flash
callFlashObject(“Previous”) : For playing previous Flash video
callFlashObject(“next”) : For playing next Flash video
callFlashObject(“SetVariable”, “/:Message) : For displaying the message .
Implementation :
FlashObjectWebDriver flashApp = new FlashObjectWebDriver(driver, "myFlashMovie");
// Pass the URL of video
driver.get("http://demo.guru99.com/flash-testing.html");
Thread.sleep(5000);
flashApp.callFlashObject("Play");
Thread.sleep(5000);
flashApp.callFlashObject("StopPlay");
Thread.sleep(5000);
flashApp.callFlashObject("SetVariable","/:message","Flash testing using selenium Webdriver");
System.out.println(flashApp.callFlashObject("GetVariable","/:message"));
Related
I am trying to make an audio file play on google.com. I have the following code:
ChromeOptions options = new ChromeOptions();
options.AddArguments(
//"--allow-file-access-from-files",
"--use-fake-ui-for-media-stream",
//"--allow-file-access",
"--use-file-for-fake-audio-capture=" + AppDomain.CurrentDomain.BaseDirectory + "/audio.wav",
"--use-fake-device-for-media-stream"
);
IWebDriver chrome = new ChromeDriver(options);
this code opens a chrome window with the use of selenium in C# and everything works as expected. When i go to an online audio recorder or https://appr.tc/?debug=loopback then my audio file plays just like it is supposed to do. However, when i go to google.com and I click on the search by voice button at the end of the searchbar nothing happens. (when I just talk then google.com recognizes my voice) What am I missing and why doesn't it work? I am trying to recreate this but in C# http://www.testautomationguru.com/selenium-webdriver-google-voice-search-automation-using-arquillian-graphene/. Is there some kind of javascript code I could execute on the page to make it work? I wouldn't mind using a firefoxdriver instead of a chrome one if that solves the problem.
Thanks
Edit: I found a little more information on https://webrtc.org/testing/ so I suppose this means that google.com doesn't make use of the webrtc getUserMedia() call to get the audio? Any way I could modify the page so it does or can I change some other setting? I also just checked https://speechnotes.co/ and on that site my audio also isn't detected but my real microphone is.
google.com makes use of webKitSpeechRecognition() in javascript which is the built in chrome speech recognition, checkchrome speech recognition WebKitSpeechRecognition() not accepting input of fake audio device --use-file-for-fake-audio-capture or audio file
I am testing the browser for mobile responsiveness. I changed the browser window size to iPhone 5 which is 320 x 568 using this command
driver.Manage().Window.Size = new Size(320, 568);
When I run the test, the browser opens fine according to the mentioned size without any issue. But it fails to find a hyperlink text which is displayed on the page. I get Element not visible exception when I could actually see the link text on the screen. So, could anyone help me solve this issue or have any ideas that I could try?
Any help would be highly appreciated.
Thanks.
Perhaps it's due to the time delay, that means code executes even before the link appears, So write the following code in your language
Code from Ruby Selenium-binding
wait = Selenium::WebDriver::Wait.new(timeout: 10) # seconds
wait.until { driver.find_element(id: "foo").displayed? }
driver.find_element(id: "foo").click
Try to scroll to the element.
You could use java script to do that.
In Python this can be done via
WebDriver.execute_script("arguments[0].scrollIntoView();", elem)
Some elements of the DOM of the webpage change when you test for mobile responsiveness, so selenium is unable to locate the element that you are specifically trying to target.So, you should try to debug and find the methods where the code is failing to perform the action.Then you should find the locators for those elements in "mobile responsiveness view" and trigger only those methods when you are testing for mobile.
i'm new to android automation testing and i recently started to work with Appium.
I use it for android native app automation.
I have 2 question -
is there a way to verify toasts?
the latest posts i saw which referred to this issue are from the mid of 2014
and i wanted to know if there's something new in this subject before i will find another tool to run my tests with (as i understand selendroid can verify toasts).
is there a way to catch the http request which my app sends to the server when i'm pressing a button, during the automatic test?
something like a listener which works in the backround and wait for clicks?
tnx
To verify toast messages you can use one of image recognition libraries. For ruby I use RTesseract together with image processor RMgick
Idea is simple:
make toast message to appear
take few screenshots
iterate over taken screenshots and look for text
You may play with image processing, to increase recognition quality.
Here you can find code snippet which I use in my framework: link
I have been working on a web app, and it was designed for Firefox only.
The getProperty(".readyState") always return 4 >> READY even if the page is still loading.
I already tried the following:
- image comparison using Robot (NO LUCK)
- waitForExistence
readyState is an IE property and it seems it is not working properly using Firefox.
any help from the experts are greatly appreciated. Thanks
Try using waitForExistence on some object on the page that signifies that it is ready. That is, rather than waitForExistence on the page itself, waitForExistence on a child object of that page. For example, if a certain link or button is only available when the page is ready, sync on that.
If this is a page with asynchronous requests running in the background, RFT does have functions which allow you to sync on completion of ajax requests. See the RFT online help docs for ajax support.
Excuse me, I have tried to use iMacro in FireFox to do playback.
However, it seems that during the playback, it try to click a button before the page finish loading such that the playback stop and iMacro complains that the element (i.e. the button )cannot be found.
I have encountered similar problem in Selenium and have used "clickAndWait" command to solve such kind of problem in Selenium.
May I ask in iMacro, does it also have command such as the "clickAndWait" in selenium for us to prevent the problem?
Or should we use any other method to deal with it in iMacro?
THank you very much
You can use
WAIT SECONDS=x