Skip to main content
No Result Found

Chrome Flags support with JavaScript testing

Automated JavaScript Testing APIs support the automation of Chrome Flags on your Google Chrome browser.

Overview

Chrome Flags are potential functionalities that you can enable, disable, or set as default to control the browser services and behavior. You can check all Chrome Flags using the chrome://flags/ URL on your Google Chrome browser.

Run test using Chrome Flags

Pass Chrome Flags in karma_conf.js to use Flags in your tests.

flags: ["--enable-features=WebContentsForceDark"]

For example:

customLaunchers: {
      bs_chrome_win1: {
        base: 'BrowserStack',
        browser: 'chrome',
        browser_version: 'latest',
        os: 'Windows',
        os_version: '11',
        flags: ["--enable-features=WebContentsForceDark"]
      },
},

Following code snippet is a test script that enables dark mode using a Chrome Flag.

require 'rubygems'
require 'json'
require 'net/http'
require 'uri'
require 'pp'
require 'net/http'
require 'openssl'
# require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

# local
user = 'YOUR_USERNAME'
key = 'YOUR_ACCESS_KEY'
base_url = 'apidev.bsstag.com'



uri= URI.parse("https://#{base_url}/5")

http = Net::HTTP.new(uri.host, uri.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true # if uri.scheme == 'https'
puts "Creating worker #{uri.port}"
#Create a worker
uri=URI.parse("https://#{base_url}/5/worker")

request=Net::HTTP::Post.new(uri.request_uri)
request.initialize_http_header({"Content-Type" => "application/json", "Accept" => "application/json"})
request.basic_auth("#{user}","#{key}")

flags = ["--enable-features=WebContentsForceDark"]
request.body = { "flags" => flags,  "os" => "android", "os_version" => "11.0", "device" => "Samsung Galaxy S21 Ultra" , "url" => "https://reddit.com", "realMobile" => "true", "build" => "JS mobile" }.to_json

begin
    response=http.request(request)

    url = response['location']
end while response.is_a?(Net::HTTPRedirection)
puts "RESPONSE: #{response.body}"
jobId= JSON.parse(response.body)["id"]
puts "https://#{base_url}/5/worker/#{jobId}"

#Get job status
uri=URI.parse("https://#{base_url}/5/worker/#{jobId}")
request=Net::HTTP::Get.new(uri.request_uri)
request.basic_auth("#{user}","#{key}")
response=http.request(request)
status = JSON.parse(response.body)["status"]
puts status
while status!="running"
response = http.request(request)
status = JSON.parse(response.body)["status"]
puts status
sleep 1
end

#Get API Status

uri=URI.parse("https://#{base_url}/5/worker/#{jobId}/screenshot.json")
request=Net::HTTP::Get.new(uri.request_uri)
request.basic_auth("#{user}","#{key}")
response=http.request(request)
puts response.body
sleep(5)
response=http.request(request)
puts response.body

sleep(5)
response=http.request(request)

puts response.each_header.to_h

sleep(3)

# puts driver.title()

uri=URI.parse("https://#{base_url}/5/workers")
request=Net::HTTP::Get.new(uri.request_uri)
request.basic_auth("#{user}","#{key}")
response=http.request(request)
puts response.body


# Delete worker
puts "/n/nDelete worker/n/n"
 uri=URI.parse("https://#{base_url}/5/worker/#{jobId}")
 request=Net::HTTP::Delete.new(uri.request_uri)
 request.basic_auth("#{user}","#{key}")
 response=http.request(request)
 puts response.body
 puts "/n/n Worker Deleted /n/n"


#status of API after delete


uri=URI.parse("https://#{base_url}/5/status")
request=Net::HTTP::Get.new(uri.request_uri)
request.basic_auth("#{user}","#{key}")
response=http.request(request)
puts response.body

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle