@Then("^the account should hold the credit check record$")
  public void verifyAccIsCreditChecked() {

    // To Verify the entered Credit REf Number exists and Credit check is enabled on the account

    WebNavPage.verifyCheckBoxChecked(AccountsPage.creCheckBox);
    WebNavPage.assertContentExists(AccountsPage.creditRefnum);
  }
  @When("^I link the Parent Account to the Child Account$")
  public void linkChildToParent() {

    WebNavPage.clickALink(AccountsPage.edit);
    WebNavPage.waitForElementToLoad();
    WebNavPage.enterAnyTextInAFieldWithCssLocator(AccountsPage.parentAccount, parent_Account);
    WebNavPage.clickALink(HomePage.saveBTN);
    WebNavPage.waitForElementToLoad();
  }
  @Then("^I should be able to see the all the expected elements$")
  public void verifyAllElementsExists() {

    // WebNavPage.assertContentExists("//span[@id = 'ctl00_lblUserInfo']", "Demo User");
    WebNavPage.assertContentExists("//span[@id =" + " 'ctl00_Label3']", "Help & Tutorial");
    WebNavPage.assertContentExists("//span[@id = 'ctl00_Label20']", "Tools");
    WebNavPage.assertContentExists("//a[@id = 'ctl00_hlPref']", "My profile");
    WebNavPage.assertContentExists("//a[contains(text(), 'Support')]", "Support");
    WebNavPage.assertContentExists("//a[contains(text(), 'Logout')]", "Logout");
  }
  @Then("^I should be able to see the Parent Account ID linked$")
  public void verifyChildAccIsLinked() {

    try {
      WebNavPage.assertContentExists(AccountsPage.parentAcc, parent_Account.toUpperCase());
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      System.out.println(
          "The Parent Account is linked successfully and value of par Acc in Child Acc page is :"
              + WebNavPage.getText(AccountsPage.parentAcc));
    }
  }
  @Given("^I am logged in as (.*) in Salesforce$")
  public static void logMeAs(String UserType) throws Exception {

    String UserName = "";

    if (UserType.equalsIgnoreCase("SalesUser")) {
      UserName = EnvironmentURLs.SalesUser;
    } else if (UserType.equalsIgnoreCase("SalesSupportUser")) {
      UserName = EnvironmentURLs.SalesSupportUser;
    } else if (UserType.equalsIgnoreCase("AdminUser")) {
      UserName = EnvironmentURLs.AdminUser;
    } else {
      System.out.println("User Type Unknown");
    }

    WebNavPage.openWebPage(EnvironmentURLs.SalesforceLoginPage);
    WebNavPage.enterAnyTextInAFieldWithCssLocator(LoginPage.username, UserName);
    WebNavPage.enterAnyTextInAFieldWithCssLocator(LoginPage.password, EnvironmentURLs.Password);
    WebNavPage.clickALinkWithCssLocator(LoginPage.loginBTN);

    // Selecting NewsInternational if its not selected

    if (WebNavPage.getText(HomePage.orgLabel).equalsIgnoreCase("News International") != true) {
      WebNavPage.clickALink(HomePage.groupMenu);
      // WebNavPage.waitForElementToBeVisible(HomePage.orgMenu);
      WebNavPage.clickALink(HomePage.newIntLNK);
    }
  }
  @When("^I look into the (.*) Account$")
  public static void verifyAccountPage(String AccountName) {

    WebNavPage.refreshPage();
    if (AccountName.equalsIgnoreCase("Parent")) {
      AccountName = parent_Account;
    } else {
      AccountName = child_Account;
    }
  }
  @Given("^I am on Adpoint HomePage$")
  public void launchApp() {

    try {
      WebNavPage.openWebPage(AdPoint.getAdPoint_HomePage());
      // DataSettingStepdefs.dataSetUpForDisplayAd();

    } catch (Exception e) {
      e.getStackTrace();
    }
  }
  @Then("^I should be able to see all the auto generated fields$")
  public static void verifyAccountHasAllAutoFields() {

    if (WebNavPage.getText(AccountsPage.accNameFilled) != null) {
      assertNotNull("The Value of External Id is :", WebNavPage.getText(AccountsPage.externalID));
      assertNotNull(
          "The Value of Website Dealer Id is :", WebNavPage.getText(AccountsPage.webDealerId));

    } else {
      System.out.print("the ID's are not generated yet !!");
    }
    accountInfo.put("AccountName", WebNavPage.getText(AccountsPage.accNameFilled));
    accountInfo.put("ExternalID", WebNavPage.getText(AccountsPage.externalID));
    accountInfo.put("WebSiteDealerID", WebNavPage.getText(AccountsPage.webDealerId));
  }
  @And("^I do a credit check pass the (.*) Account$")
  public static void doCreditCheckOnAccount(String AccName) {

    if (AccName.equalsIgnoreCase("Parent")) {
      accToBeChecked = parent_Account;
    } else {
      accToBeChecked = child_Account;
    }
    WebNavPage.enterAnyTextInAField(HomePage.search, accToBeChecked);
    WebNavPage.clickALink(HomePage.searchBTN);
    WebNavPage.waitForElementToLoad();
    String accLocator = "//a[contains(text(),'" + accToBeChecked + "')]";
    try {
      WebNavPage.elementWithXPathExists(accLocator);
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("The Account" + accToBeChecked + "is not displayed in the search results");
    } finally {
      WebNavPage.clickALink(accLocator);
      WebNavPage.waitForElementToLoad();
      WebNavPage.clickALink(AccountsPage.edit);
      WebNavPage.waitForElementToLoad();
      WebNavPage.checkACheckBox(AccountsPage.CreCheck);
      WebNavPage.enterAnyNumberInAField(AccountsPage.CreRefNum, 1111);
      WebNavPage.clickALink(HomePage.saveBTN);
      WebNavPage.waitForElementToLoad();
    }
  }
  @And("^I am logged in to the site$")
  public void verifyUserLoggedIn() {

    WebNavPage.elementWithXPathExists(HomePage.Logout);
  }
  public static void clickOnATab(String TabName) {

    String tabToClick = "//span[contains(text(), '" + TabName + "')]";
    WebNavPage.clickALink(tabToClick);
    WebNavPage.waitForElementToLoad();
  }
  @Then("^I should be directed to the (.*) page$")
  public void checkMyPage(String pageName) {

    String pageTitle = pageName;
    WebNavPage.assertPageTitle(pageTitle);
  }
  @When("^I click Orders link$")
  public void clickOnOrderLink() {

    WebNavPage.clickALink(HomePage.Orders_FooterLink);
  }
 @When("^I click Orders tab$")
 public void clickOnOrderstab() {
   WebNavPage.clickALink(HomePage.Orders);
 }
 @When("^I scroll to the top of the Page$")
 public void scrollToTop() {
   WebNavPage.refreshPage();
 }
  public static void createAnAccount(String AccountName) throws InterruptedException {

    if (!WebNavPage.elementWithXPathExists("//div[@id = 'createNewButton']")) {
      WebNavPage.clickALink(HomePage.activateSideMenu);
    }
    WebNavPage.clickALinkWithCssLocator(HomePage.createNewDropdown);
    WebNavPage.clickALinkWithCssLocator(HomePage.accountOptionFromDropdown);
    WebNavPage.enterAnyTextInAFieldWithCssLocator(AccountsPage.accountName, AccountName);
    WebNavPage.enterAnyTextInAFieldWithCssLocator(AccountsPage.phone, "0208456789");
    WebNavPage.enterAnyTextInAField(AccountsPage.email, "*****@*****.**");
    WebNavPage.checkACheckBox(AccountsPage.dynamicTeleTracking);
    WebNavPage.enterAnyTextInAField(AccountsPage.telephoneTrackingNum, "25823");
    WebNavPage.enterAnyTextInAFieldWithCssLocator(AccountsPage.website, "http://www.test.com");
    WebNavPage.enterAnyTextInAFieldWithCssLocator(AccountsPage.billingStreet, "1, Some Street");
    WebNavPage.enterAnyTextInAFieldWithCssLocator(AccountsPage.billingCity, "Some City");
    WebNavPage.enterAnyTextInAFieldWithCssLocator(AccountsPage.billingPostcode, "E98 1XY");
    WebNavPage.enterAnyTextInAField(AccountsPage.SAPId, "9777777");
    WebNavPage.selectingAnOptionFromList("Car Dealer", AccountsPage.accType);
    WebNavPage.selectAnOptionFromAList("Key Account", AccountsPage.accSubType);
    WebNavPage.enterAnyTextInAField(AccountsPage.billCountry, "UK");
    WebNavPage.selectingAnOptionFromList("South-East", AccountsPage.region);
    WebNavPage.clickALink(AccountsPage.copyBillingAddress);
    WebNavPage.clickALink(HomePage.saveBTN);

    if (WebNavPage.getText("//div[@id='00N3000000AeABd_ileinner']").contains("SF") != false) {
      WebNavPage.waitForElementToLoad();
    } else {
      System.out.println(
          "The Dealer ID for the Account is :"
              + WebNavPage.getText("//div[@id='00N3000000AeABd_ileinner']"));
    }
  }
  public static void clickOnFooterLink(String linkName) {

    String footerLink = "//ul/li/a/span[contains(text(),'" + linkName + "')]";
    WebNavPage.clickALink(footerLink);
    WebNavPage.waitForShortSpan();
  }