appium screen recording feature - ruby

I am trying to record the screen and referring to the following tutorial.
http://appium.io/docs/en/commands/device/recording-screen/start-recording-screen/
I tried the following piece of code but it doesn't save anything at this path.
#driver.start_recording_screen video_type: 'h264', time_limit: '260', remote_path: '/recordings'
I am putting it in before method so that it records everything for all the following 5 tests that I have in the particular spec file
Am I missing something here?

To start recording use the below c# code:
driver.StartRecordingScreen(AndroidStartScreenRecordingOptions
.GetAndroidStartScreenRecordingOptions()
.WithTimeLimit(TimeSpan.FromMinutes(1))
.EnableBugReport());
And then, to stop the recording, you need to use the following code. Since it creates recording in base64 format, you need to decode it to view.
String video = driver.StopRecordingScreen();
byte[] decode = Convert.FromBase64String(video);
String fileName = "VideoRecording_test.mp4";
File.WriteAllBytes(fileName, decode);

In order to start the recording, we just need to call the start_recording_screen method from the respective classes.
before(:all) or before(:each) do
#driver.start_recording_screen video_quality: 'low'
end
For IOS, please install ffmpeg (brew install ffmpeg).
We can add screen recording configurations like time limit, video size etc during the start of your video recording.
In order to stop the recording, we need to call the stop_recording_screen method from the respective classes.
Now, coming to the most important question! Where is our video?
The stopRecordingScreen() method returns a Base64 String. Using this string we need to build our video. There are many ways to do it, I have used decode64 method from Ruby Base64 module.
after(:all) do
record = #driver.stop_recording_screen
File.open('sample.mp4', 'wb') do |file|
file.write(Base64.decode64(record))
end
end
Finally you could find the recording under sample.mp4. I would recommend to play the video by VLC or Mplayer if you can not play the video with other video players.

Related

How to fix a webm file without audio?

I use mediarecorder to record video and audio from a user's browser. We record every 15 seconds and then upload that blog to S3. Then we combine all the files together to make one webm file. I believe the first file isn't right because when I combine the files, there is not any audio - only video.
Is there a way to alter the headers in the first file to use the audio in all of the subsequent files? OR is there an FFMPEG command to force using the audio? I know they exist in the other files.
I don't believe this is important but here is the code that I use to save and combine the webm blobs.
First I save the blobs from the media recorder
recorder = new MediaRecorder(local_media_stream.remoteStream, {
mimeType: encoding_options,
audioBitsPerSecond: 96000,
videoBitsPerSecond: bits_per_second,
});
recorder.ondataavailable = function(e) {
that.save_blob(e.data, blob_index);
}
Then later I combine each of those blobs.
bucket = Aws::S3::Resource.new(region:'us-east-1').bucket("files")
keys = bucket.objects(prefix: "files").collect(&:key)
temp_webm_file = Tempfile.new(['total', '.webm'])
keys.each_with_index do |key, index|
temp_webm_file.write bucket.object(key).get.body.read
end
temp_webm_file.close()
One thing I know that fixes the issue is if I combine a short webm file with audio to the very beginning. Then the audio all works.

Cutting data appended to a .jpg file and save as mpg file

The background of my problem is that I want to extract the video data of Motion Photos (taken by my Samsung S7). Manually it is easy but time consuming. Just open the .jpg file in a HexEditor and extract all data after the line "MotionPhoto_Data". The first part is the image and the second part is the video.
My current code is
im = 'test.jpg'
with open(im, 'rb') as fin:
data = fin.read()
data_latin = data.decode('latin1')
fin.close()
position = data_latin.find('MotionPhoto_Data')
data_pic = data[:position]
data_mpg = data[position:]
My problem now is that I can´t figure out how to save these strings in a way that data_pic is saved as a working jpg and data_mpg as a working video.
I tried
with open('test_pic.jpg', 'a') as fin:
fin.write(str(data_pic))
fin.close()
But this didn´t worked. I think there is a basic issue on how I try to handle/save my data but I can´t figure out how to fix this.
I assume you use python 3 as it is tagged that way.
You should not decode with 'data.decode('latin1'). It is binary data.
data = fin.read()
Then later write it also as binary data:
with open('test_pic.jpg', 'ab') as fout:
fout.write(data_pic)
fout.close()

Converting WAV to GSM using pysox

I'm experimenting with pysox and trying to simply convert a WAV file to GSM.
I'm currently using the following approach which works just fine:
infile = pysox.CSoxStream("input_file.wav")
outfile = pysox.CSoxStream('output_file.gsm','w',infile.get_signal())
chain = pysox.CEffectsChain(infile, outfile)
chain.flow_effects()
outfile.close()
I wonder if there's a better/builtin way without using effects (as i'm not applying any effects) .
thanks in advance
I found that i actually must use libsox effect as i'm changing the rate :
chain.add_effect(pysox.CEffect("rate", ["8k"]))
Without adding this line the output appears in slow motion (since my original file can have different rate)

How to loop throgh all links in div and collect values from opened fields

Is it possible to open every link in certain div and collect values of opened fields alltogether in one file or at least terminal output?
I am trying to get list of coordinates from all markers visible on google map.
all_links = b.div(:id, "kmlfolders").links
all_links.each do |link|
b.link.click
b.link(:text, "Norādījumi").click
puts b.text_field(:title, "Galapunkta_adrese").value
end
Are there easier or more effective ways how to automatically collect coordinates from all markers?
Unless there is other data (alt tags? elements invoked via onhover?) in the HTML already that you could pick through, that does seem like the most practical way to iterate through the links, however from what I can see you are not actually making use of the 'link' object inside your loop. You'd need something more like this I think
all_links = b.div(:id, "kmlfolders").links
all_links.each do |thelink|
b.link(:href => thelink.href).click
b.link(:text, "Norādījumi").click
puts b.text_field(:title, "Galapunkta_adrese").value
end
Probably using their API is a lot more effective means to get what you want however, it's why folks make API's after all, and if one is available, then using it is almost always best. Using a test tool as a screen-scraper to gather the info is liable to be a lot harder in the long run than learning how to make some api calls and get the data that way.
for web based api's and Ruby I find the REST-CLIENT gem works great, other folks like HTTP-Party
As I'm not already familiar with Google API, I find it hard for me to dig into API for one particular need. Therefor I made short watir-webdriver script for collecting coordinates of markers on protected google map. Resulting file is used in python script that creates speedcam files for navigation devices.
In this case it's speedcam map maintained and updated by Latvian police, but this script can probably be used with any google map just by replacing url.
# encoding: utf-8
require "rubygems"
require "watir-webdriver"
#b = Watir::Browser.new :ff
#--------------------------------
#b.goto "http://maps.google.com/maps?source=s_q&f=q&hl=lv&geocode=&q=htt%2F%2Fmaps.google.com%2Fmaps%2Fms%3Fmsid%3D207561992958290099079.0004b731f1c645294488e%26msa%3D0%26output%3Dkml&aq=&sll=56.799934,24.5753&sspn=3.85093,8.64624&ie=UTF8&ll=56.799934,24.5753&spn=3.610137,9.887695&z=7&vpsrc=0&oi=map_misc&ct=api_logo"
#b.div(:id, "kmlfolders").wait_until_present
all_markers = #b.div(:id, "kmlfolders").divs(:class, "fdrlt")
#prev_coordinates = 1
puts "#{all_markers.length} speedcam markers detected"
File.open("list_of_coordinates.txt","w") do |outfile|
all_markers.each do |marker|
sleep 1
marker.click
sleep 1
description = #b.div(:id => "iw_kml").text
#b.span(:class, "actbar-text").click
sleep 2
coordinates = #b.text_field(:name, "daddr").value
redo if coordinates == #prev_coordinates
puts coordinates
outfile.puts coordinates
#prev_coordinates = coordinates
end
end
puts "Coordinates saved in file!"
#b.close
Works both on Mac OSX 10.7 and Windows7.

how do i find out duration/total play time of an mp3 file using java?

I am developing an application in Java. Part of it includes playing an mp3 file via another application. I need to find the duration (total play time) of the mp3 file. How do I do that?
You can do this very easily using JAudioTagger:
Tag tag;
java.util.logging.Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF);
audioFile = AudioFileIO.read(new File(filePath));
System.out.println("Track length = " + audioFile.getAudioHeader().getTrackLength());
That will print out the track length of the file at filePath. The logger line is to remove a lot of (probably) unwanted info/debugging logging from JAudioTagger. Besides this, JAudioTagger supports getting all sorts of metadata tags from different audio file types (MP3, MP4, WMA, FLAC, Ogg Vorbis), both from file-embedded tags. You can even get MusicBrainz info easily, but I haven't tried that yet. For more info:
http://www.jthink.net/jaudiotagger/examples_read.jsp
You can get the jar files for it here:
http://download.java.net/maven/2/org/jaudiotagger/
For small .mp3 files you can use:
AudioFile audioFile = AudioFileIO.read(MyFileChooser.fileName);
int duration= audioFile.getAudioHeader().getTrackLength();
System.out.println(duration);
This will give a string containing the minute and second duration in it. eg: 316 for 3:16.
Note that This method is not suitable with larger files.

Resources