def test_login_with_valid_username_and_invalid_pwd(self, setup):
     self.logger.info(
         "********************Test Login Page Started********************************"
     )
     self.driver = setup
     self.login = ceo_page(self.driver)
     self.login_page = AdminLogin(self.driver)
     self.driver.get(self.baseURL)
     self.login_page.setUserName(ReadConfig.getUsername())
     self.login.set_invalid_UserName(ReadConfig.get_invalid_Password())
     self.login_page.clickLogin()
     errormsg = self.driver.find_element_by_tag_name('p').text
     print('errormsg on ui', errormsg)
     if errormsg == 'Please enter the password.':
         assert True
         self.driver.close()
         self.logger.info(
             "********************Test Admin Login Ended********************************"
         )
     else:
         self.driver.save_screenshot("../Screenshots/" +
                                     "test_login_page.png")
         self.driver.close()
         self.logger.info(
             "********************Test Login Page Ended Due to error msg is mismatch ********************************"
         )
         assert False
 def test_gvpalli_forcasted_graph_and_downloadcsv(self, setup):
     self.logger.info(
         "********************Test gv palli all turbines Started********************************"
     )
     self.driver = setup
     self.driver.implicitly_wait(30)
     self.files = reuseable()
     self.login_page = ceo_page(self.driver)
     self.driver.get(self.baseURL)
     self.login_page.get_ceo_screen()
     time.sleep(5)
     self.driver.find_element_by_xpath(
         self.login_page.dashboard_windfarm).click()
     time.sleep(3)
     self.driver.find_element_by_xpath(
         self.login_page.gvpalli_button).click()
     time.sleep(5)
     turbines = self.driver.find_elements_by_tag_name('tr')
     for i in range(1, len(turbines)):
         turbines[i].click()
         time.sleep(3)
         self.driver.find_element_by_id(self.login_page.backIcon).click()
         time.sleep(5)
     self.driver.close()
     self.logger.info(
         '******************* GV Palli turbines completed*******************'
     )
    def test_gvpalli_all_turbines_downloadcsv(self, setup):
        self.logger.info(
            "********************Test gv palli all turbines Started********************************"
        )
        self.driver = setup
        self.driver.implicitly_wait(100)
        self.files = reuseable()
        self.login_page = ceo_page(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.get_ceo_screen()
        time.sleep(5)
        self.driver.find_element_by_xpath(
            self.login_page.dashboard_windfarm).click()
        time.sleep(3)
        self.driver.find_element_by_xpath(
            self.login_page.gvpalli_button).click()
        time.sleep(5)
        # turbines =self.driver.find_elements_by_xpath('//tr')
        # turbi =self.driver.find_elements_by_xpath('//li/a')
        # for i in range(1, len(turbines)):
        #     time.sleep(2)
        #     turbines[i].click()
        #     time.sleep(5)
        #     self.driver.find_element_by_xpath("//*[@id='main-menu']/li[2]/a").click()
        #     time.sleep(2)
        #     self.driver.implicitly_wait(30)
        #     for j in range(3,len(turbi)):
        #         turbi[j].click()
        #         time.sleep(10)

        turbines = self.driver.find_elements_by_id('G01').click()
        time.sleep(5)
        self.driver.find_element_by_xpath(
            "//*[@id='main-menu']/li[2]/a").click()
        time.sleep(2)
        for i in range(1, 15):
            self.driver.find_element_by_id(('G0', i)).click()
        self.driver.close()
        self.logger.info(
            '******************* GV Palli turbines completed*******************'
        )
    def test_forcasted_chart_for_all_turbines(self, setup):
        self.logger.info(
            "********************Test all turbines Started********************************"
        )
        self.driver = setup
        self.files = DirectoryPath()
        self.driver.implicitly_wait(200)
        self.login_page = ceo_page(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.get_ceo_screen()
        time.sleep(3)
        self.driver.find_element_by_xpath(
            self.login_page.dashboard_windfarm).click()
        time.sleep(5)
        self.driver.find_element_by_xpath(
            self.login_page.gvpalli_button).click()
        time.sleep(8)
        lst = len(self.driver.find_elements_by_tag_name("tr")) - 1
        for i in range(2, 16):
            self.driver.find_element_by_xpath(
                "//tbody/tr[{0}]".format(i)).click()
            time.sleep(6)
            print(self.driver.current_url, "is displayed")
            self.driver.find_element_by_id(
                self.login_page.forecastDownloadBtn).click()
            time.sleep(4)
            self.filename = self.files.get_download_dir(
            ) + '/' + self.login_page.list_turbine[i] + '_forecasted.csv'
            if os.path.isfile(self.filename) != True:
                print(self.filename, self.login_page.list_turbine[i],
                      ' csv file is not download')
                self.driver.close()
            else:
                with open(self.filename) as fin:
                    csv_reader = csv.reader(fin, delimiter=',')
                    header = next(csv_reader)
                    forcasted = 0
                    for row in csv.reader(fin):
                        print('\n', row)
                        forcasted += float(row[1])

                    ui_forcast = (self.driver.find_element_by_id(
                        self.login_page.forecastedPower).text).replace(
                            'KWh', '')
                    ui_forcast = float(re.sub('\f', "", ui_forcast).strip())

                    forcasted = round(forcasted, 2)

                    print('file value', forcasted, 'ui value', ui_forcast)

                    if forcasted != ui_forcast:
                        print('Difference found at actual generation ',
                              forcasted, ui_forcast)
                        self.driver.save_screenshot(
                            "../Screenshots/" +
                            "test_turbines_actgen_variance.png")
                        assert False

                    os.remove(self.filename)
                self.driver.find_element_by_id(
                    self.login_page.backIcon).click()
            time.sleep(5)
        self.driver.close()