<commit_before>require_relative '../../../utils/sli_utils.rb'
require_relative '../../dash/step_definitions/selenium_common_dash.rb'

Given /^the sampleApp is deployed on sampleApp server$/ do
  @appPrefix = "oauth2-sample/students"
end

When /^I navigate to the sampleApp home page$/ do
  url = PropLoader.getProps['sampleApp_server_address']
  url = url + @appPrefix
  puts url
  @driver.get url
  # There's a redirect to the realm page, so this assert should fail
  # assert(@driver.current_url == url, "Failed to navigate to "+url)
end

Then /^I should be redirected to the Realm page$/ do
  assert(@driver.current_url.include?("/api/oauth/authorize"))

end

When /^I select "([^"]*)" and click go$/ do |arg1|
  sleep(1)
  
 realm_select = @driver.find_element(:name=> "realmId")

  
  options = realm_select.find_elements(:tag_name=>"option")
  options.each do |e1|
    if (e1.text == arg1)
      e1.click()
      break
    end
  end
  clickButton("go", "id")
  
end

When /^I login as "([^"]*)" "([^"]*)"/ do | username, password |
    sleep(1)
    wait = Selenium::WebDriver::Wait.new(:timeout => 5) # explicit wait for at most 5 sec
    wait.until{@driver.find_element(:id, "IDToken1")}.send_keys username
    @driver.find_element(:id, "IDToken2").send_keys password
    @driver.find_element(:name, "Login.Submit").click
end

When /^I go to List of Students$/ do
  url = PropLoader.getProps['sampleApp_server_address']
  url = url + @appPrefix
  puts url
  @driver.get url
end

Then /^the page should include a table with header "([^"]*)"$/ do |name|
  sleep(10)
  puts @driver.page_source
  headerName=@driver.find_element(:id, "header.Student")
  headerName.text.should == name
end

Then /^I should see student "([^"]*)" in the student list$/ do |studentName|
  sleep(10)
  puts @driver.page_source<commit_msg>Debug for jenkins<commit_after>require_relative '../../../utils/sli_utils.rb'
require_relative '../../dash/step_definitions/selenium_common_dash.rb'

Given /^the sampleApp is deployed on sampleApp server$/ do
  @appPrefix = "oauth2-sample/students"
end

When /^I navigate to the sampleApp home page$/ do
  url = PropLoader.getProps['sampleApp_server_address']
  url = url + @appPrefix
  puts url
  @driver.get url
  # There's a redirect to the realm page, so this assert should fail
  # assert(@driver.current_url == url, "Failed to navigate to "+url)
end

Then /^I should be redirected to the Realm page$/ do
  assert(@driver.current_url.include?("/api/oauth/authorize"))

end

When /^I select "([^"]*)" and click go$/ do |arg1|
  sleep(1)
  
 realm_select = @driver.find_element(:name=> "realmId")

  
  options = realm_select.find_elements(:tag_name=>"option")
  options.each do |e1|
    if (e1.text == arg1)
      e1.click()
      break
    end
  end
  clickButton("go", "id")
  
end

When /^I login as "([^"]*)" "([^"]*)"/ do | username, password |
    sleep(1)
    wait = Selenium::WebDriver::Wait.new(:timeout => 5) # explicit wait for at most 5 sec
    wait.until{@driver.find_element(:id, "IDToken1")}.send_keys username
    @driver.find_element(:id, "IDToken2").send_keys password
    @driver.find_element(:name, "Login.Submit").click
end

When /^I go to List of Students$/ do
  sleep(3)
  puts @driver.page_source
  url = PropLoader.getProps['sampleApp_server_address']
  url = url + @appPrefix
  puts url
  @driver.get url
end

Then /^the page should include a table with header "([^"]*)"$/ do |name|
  sleep(10)
  puts @driver.page_source
  headerName=@driver.find_element(:id, "header.Student")
  headerName.text.should == name
end

Then /^I should see student "([^"]*)" in the student list$/ do |studentName|
  sleep(10)
  puts @driver.page_source
{'fraction_non_alphanumeric': 0.14937533948940793, 'fraction_numerical': 0.008962520369364476, 'mean_word_length': 3.930388219544846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3755514', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1254, 'n_words': 346}