Sha256: 692c7aa5e948b403aa8863fd9923dbec4acaf1b1ba121aba44bdf6f4486ce660

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true
require "lambdatest/sdk/utils"

module Lambdatest
  module Selenium
    module Driver
      @pkg_name = "ruby-selenium-driver"
      @logger = Lambdatest::Sdk::Utils.get_logger(@pkg_name)
      
      def self.smartui_snapshot(driver , snapshot_name, options = {})
        if snapshot_name.nil? || snapshot_name.empty?
          raise StandardError, "The `snapshotName` argument is required."
        end
  
        if driver.nil?
          raise StandardError, "The `driver` argument is required."
        end

        if !Lambdatest::Sdk::Utils.is_smartui_enabled?
          raise StandardError, "Cannot find SmartUI server."
        end

        begin
          response = JSON.parse(Lambdatest::Sdk::Utils.fetch_dom_serializer)
          driver.execute_script(response["data"]["dom"])

          # Serialize and capture the DOM
          snapshot = driver.execute_script("return {
             'dom' : SmartUIDOM.serialize(#{options.to_json}),
             'url' : document.URL
            }")

          # Post the dom to smartui endpoint
          snapshot['name'] = snapshot_name
          snapshot_reponse = Lambdatest::Sdk::Utils.post_snapshot(snapshot,@pkg_name,options)

          res = JSON.parse(snapshot_reponse)
          if res && res['data'] && res['data']['warnings'] && res['data']['warnings'].length != 0
            res['data']['warnings'].each do |warning|
              @logger.warn(warning)
            end
          end

          @logger.info("Snapshot captured #{snapshot_name}")
        rescue => exception
          @logger.error("SmartUI snapshot failed #{snapshot_name}") 
          @logger.error("#{exception.message}") 
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lambdatest-selenium-driver-1.0.2 lib/lambdatest/selenium/driver.rb