<commit_before># encoding: utf-8
require File.expand_path("../spec_helper", __FILE__)

describe "Browser" do

  describe "#exists?" do
    it "returns true if we are at a page" do
      browser.goto(WatirSpec.url_for("non_control_elements.html"))
      browser.should exist
    end

    not_compliant_on(:safariwatir) do
      it "returns false after Browser#close" do
        b = WatirSpec.new_browser
        b.close
        b.should_not exist
      end
    end
  end

  # this should be rewritten - the actual string returned varies a lot between implementations
  describe "#html" do
    it "returns the DOM of the page as an HTML string" do
      browser.goto(WatirSpec.url_for("right_click.html"))
      html = browser.html.downcase # varies between browsers

      html.should =~ /^<html/
      html.should include('<meta ')
      html.should include(' content="text/html; charset=utf-8"')

      not_compliant_on :internet_explorer do
        html.should include(' http-equiv="content-type"')
      end

      deviates_on :internet_explorer9, :internet_explorer10 do
        html.should include(' http-equiv="content-type"')
      end

      not_compliant_on :internet_explorer9, :internet_explorer10 do
        deviates_on :internet_explorer do
          html.should include(' http-equiv=content-type')
        end
      end
    end
  end

  describe "#title" do
    it "returns the current page title" do
      browser.goto(WatirSpec.url_for("non_control_elements.html"))
      browser.title.should == "Non-control elements"
    end
  end

  describe "#status" do
    # for Firefox, this needs to be enabled in
    # Preferences -> Content -> Advanced -> Change status bar text
    #
    # for IE9, this needs to be enabled in
    # View => Toolbars -> Status bar
    not_compliant_on [:webdriver, :firefox], :internet_explorer9, :internet_explorer10 do
      it "returns the current value of window.status" do
        browser.goto(WatirSpec.url_for("non_control_elements.html"))

        browser.execute_script "window.status = 'All done!';"
        browser.status.should == "All done!"
      end
    end
  end

  describe "#name" do
    it "returns browser name" do
      not_compliant_on :watir_classic, [:webdriver, :phantomjs] do
        browser.name.should == WatirSpec.implementation.browser_args[0]
      end

      deviates_on [:webdriver, :phantomjs] do
        browser.name.should be_an_instance_of(Symbol)
      end

      deviates_on :watir_classic do
        browser.name.should == :internet_explorer
      end
    end
  end

  describe "#text" do
    it "returns the text of the page" do
      browser.goto(WatirSpec.url_for("non_control_elements.html"))
      browser.text.should include("Dubito, ergo cogito, ergo sum.")
    end

    it "returns the text also if the content-type is text/plain" do
      # more specs for text/plain? what happens if we call other methods?
      browser.goto(WatirSpec.url_for("plain_text", :needs_server => true))
      browser.text.strip.should == 'This is text/plain'
    end
  end

  describe "#url" do
    it "returns the current url" do
      browser.goto(WatirSpec.url_for("non_control_elements.html", :needs_server => true))
      browser.url.should == WatirSpec.url_for("non_control_elements.html", :needs_server => true)
    end

    it "always returns top url" do
      browser.goto(WatirSpec.url_for("frames.html", :needs_server => true))
      browser.frame.body.exists? # switches to frame
      browser.url.should == WatirSpec.url_for("frames.html", :needs_server => true)
    end
  end

  describe "#title" do
    it "returns the current title" do
      browser.goto(WatirSpec.url_for("non_control_elements.html", :needs_server => true))
      browser.title.should == browser.element(:tag_name => 'title').text
    end

    it "always returns top title" do
      browser.goto(WatirSpec.url_for("frames.html", :needs_server => true))
      title = browser.element(:tag_name => 'title').text
      browser.frame.body.exists? # switches to frame
      browser.title.should == title
    end
  end

  describe ".start" do
    not_compliant_on(:webdriver, :safariwatir) {
      it "goes to the given URL and return an instance of itself" do
        url = WatirSpec.url_for("non_control_elements.html")
        browser = WatirSpec.implementation.browser_class.start(WatirSpec.url_for("non_control_elements.html"))

        browser.should be_instance_of(WatirSpec.implementation.browser_class)
        browser.title.should == "Non-control elements"
        browser.close
      end
    }

    # we need to specify what browser to use
    deviates_on(:webdriver) {
      it "goes to the given URL and return an instance of itself" do
        driver, args = WatirSpec.implementation.browser_args
        browser = Watir::Browser.start(WatirSpec.url_for("non_control_elements.html"), driver, args)
<commit_msg>title should be hardcoded in spec<commit_after># encoding: utf-8
require File.expand_path("../spec_helper", __FILE__)

describe "Browser" do

  describe "#exists?" do
    it "returns true if we are at a page" do
      browser.goto(WatirSpec.url_for("non_control_elements.html"))
      browser.should exist
    end

    not_compliant_on(:safariwatir) do
      it "returns false after Browser#close" do
        b = WatirSpec.new_browser
        b.close
        b.should_not exist
      end
    end
  end

  # this should be rewritten - the actual string returned varies a lot between implementations
  describe "#html" do
    it "returns the DOM of the page as an HTML string" do
      browser.goto(WatirSpec.url_for("right_click.html"))
      html = browser.html.downcase # varies between browsers

      html.should =~ /^<html/
      html.should include('<meta ')
      html.should include(' content="text/html; charset=utf-8"')

      not_compliant_on :internet_explorer do
        html.should include(' http-equiv="content-type"')
      end

      deviates_on :internet_explorer9, :internet_explorer10 do
        html.should include(' http-equiv="content-type"')
      end

      not_compliant_on :internet_explorer9, :internet_explorer10 do
        deviates_on :internet_explorer do
          html.should include(' http-equiv=content-type')
        end
      end
    end
  end

  describe "#title" do
    it "returns the current page title" do
      browser.goto(WatirSpec.url_for("non_control_elements.html"))
      browser.title.should == "Non-control elements"
    end
  end

  describe "#status" do
    # for Firefox, this needs to be enabled in
    # Preferences -> Content -> Advanced -> Change status bar text
    #
    # for IE9, this needs to be enabled in
    # View => Toolbars -> Status bar
    not_compliant_on [:webdriver, :firefox], :internet_explorer9, :internet_explorer10 do
      it "returns the current value of window.status" do
        browser.goto(WatirSpec.url_for("non_control_elements.html"))

        browser.execute_script "window.status = 'All done!';"
        browser.status.should == "All done!"
      end
    end
  end

  describe "#name" do
    it "returns browser name" do
      not_compliant_on :watir_classic, [:webdriver, :phantomjs] do
        browser.name.should == WatirSpec.implementation.browser_args[0]
      end

      deviates_on [:webdriver, :phantomjs] do
        browser.name.should be_an_instance_of(Symbol)
      end

      deviates_on :watir_classic do
        browser.name.should == :internet_explorer
      end
    end
  end

  describe "#text" do
    it "returns the text of the page" do
      browser.goto(WatirSpec.url_for("non_control_elements.html"))
      browser.text.should include("Dubito, ergo cogito, ergo sum.")
    end

    it "returns the text also if the content-type is text/plain" do
      # more specs for text/plain? what happens if we call other methods?
      browser.goto(WatirSpec.url_for("plain_text", :needs_server => true))
      browser.text.strip.should == 'This is text/plain'
    end
  end

  describe "#url" do
    it "returns the current url" do
      browser.goto(WatirSpec.url_for("non_control_elements.html", :needs_server => true))
      browser.url.should == WatirSpec.url_for("non_control_elements.html", :needs_server => true)
    end

    it "always returns top url" do
      browser.goto(WatirSpec.url_for("frames.html", :needs_server => true))
      browser.frame.body.exists? # switches to frame
      browser.url.should == WatirSpec.url_for("frames.html", :needs_server => true)
    end
  end

  describe "#title" do
    it "returns the current title" do
      browser.goto(WatirSpec.url_for("non_control_elements.html", :needs_server => true))
      browser.title.should == "Non-control elements"
    end

    it "always returns top title" do
      browser.goto(WatirSpec.url_for("frames.html", :needs_server => true))
      title = browser.element(:tag_name => 'title').text
      browser.frame.body.exists? # switches to frame
      browser.title.should == "Frames"
    end
  end

  describe ".start" do
    not_compliant_on(:webdriver, :safariwatir) {
      it "goes to the given URL and return an instance of itself" do
        url = WatirSpec.url_for("non_control_elements.html")
        browser = WatirSpec.implementation.browser_class.start(WatirSpec.url_for("non_control_elements.html"))

        browser.should be_instance_of(WatirSpec.implementation.browser_class)
        browser.title.should == "Non-control elements"
        browser.close
      end
    }

    # we need to specify what browser to use
    deviates_on(:webdriver) {
      it "goes to the given URL and return an instance of itself" do
        driver, args = WatirSpec.implementation.browser_args
        browser = Watir::Browser.start(WatirSpec.url_for("non_control_elements.html"), driver, args)

{'fraction_non_alphanumeric': 0.09970253359318905, 'fraction_numerical': 0.0026669401989947686, 'mean_word_length': 3.0625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4097956', 'n_tokens_mistral': 3077, 'n_tokens_neox': 2922, 'n_words': 795}