コード例 #1
0
class ceo_page:

    button_login_id="login"
    dashboard ="dashboard"
    startdate_id="startDate"
    enddate_id="endDate"
    submit_id ="submit"
    submitBtn="submitBtn"
    line_chart_id ="line"
    bar_chart_id="bar"
    download_btn="downloadBtn"

    text_box_username_id = "username"
    text_box_passsword_id = "password"

    varianceDownloadBtn="varianceDownloadBtn"
    turbinesDownloadBtn="turbinesDownloadBtn"
    forecastDownloadBtn="forecastDownloadBtn"

    windfarm_csv="windfarms_variance.csv"
    gvpalli_variance="gvpalli_variance.csv"
    actual_generation="totalActualGen"
    total_forcasted="totalForecastedGen"
    gvpalli_img ="gvpalli"
    home_icon ="dashboardIcon"
    forcasted_Date="varianceasOnDate"
    windfarms ="//a/div"
    gvpalli_button ="//li[@id='gvpalli']"
    forcasted_onDate="forecastedasOnstartDate"
    forecastedendDate="forecastedendDate"
    forecastedSubmitBtn="forecastedSubmitBtn"
    #Windfarm button
    dashboard_windfarm ="//li[2]/a"
    header_userlist_xpath = "//*[@id='primary-content']/div/div[1]/div/div/h3"
    backIcon="backIcon"
    comments="comments"
    com_box="desc"
    edit_box="editDesc0"
    sample_text="Sample Text"
    updated_text="QA Sample Text"
    saveComment="saveComment"
    updatedcomment="editCommentBtn0"
    update_btn="updateComment0"
    delete_comment="deleteCommentBtn0"
    #GVPalli
    actualPowerGen="actualPowerGen"
    forecastPowerGen="forecastPowerGen"

    forecastedPowerGen="forecastedPowerGen"
    gvpalli_forecasted="gvpalli_forecasted.csv"
    forecastedPower="forecastedPower"
    turbinesDownload="turbinesDownloadBtn"
    turbine_details="turbine_details.csv"
    turbine_forcasted ="turbine_forcasted.csv"
    # Turbines
    list_of_turbines="//tr"
    turbine_01="G01"
    turbine_02="G02"
    turbine_03="G03"
    turbine_04="G04"
    tur_actualPowerGen="actualPowerGen"
    tur_forecastPowerGen="forecastPowerGen"
    turbineHistoryDownloadBtn="turbineHistoryDownloadBtn"
    turbine_history ="turbine_history.csv"

    varianceendDate="varianceendDate"
    varianceasOnDate="varianceasOnDate"
    turbines_G01_id = 'G01'
    turbines_G02_id = 'G02'
    turbines_G03_id = 'G03'
    turbines_G04_id = 'G04'
    turbines_G05_id = 'G05'
    turbines_G06_id = 'G06'
    turbines_G07_id = 'G07'
    turbines_G08_id = 'G08'
    turbines_G09_id = 'G09'
    turbines_G10_id = 'G10'
    turbines_G11_id = 'G11'
    turbines_G12_id = 'G12'
    turbines_G13_id = 'G13'
    turbines_G14_id = 'G14'
    turbines_G15_id = 'G15'

    list_turbine = ['G00','G01', 'G02', 'G03','G04','G05','G06','G07','G08','G09','G10','G11','G12','G13','G14','G15']
    start_date="17/01/2021"
    end_date="19/01/2021"
    for_sdate="20/01/2021"
    for_end="22/01/2021"
    line_forsdate="10/01/2021"
    line_foredate="20/02/2021"

    def __init__(self,driver):
        self.driver=driver

    def clickLogin(self):
        self.driver.find_element_by_id(self.button_login_id).click()

    # UserList Methods
    def set_invalid_UserName(self,username):
        self.driver.find_element_by_id(self.text_box_username_id).clear()
        self.driver.find_element_by_id(self.text_box_username_id).send_keys(username)



    def getUserListPage(self):
        txt = self.driver.find_element_by_xpath(self.header_userlist_xpath).text
        return txt

    def get_ceo_screen(self):
        self.driver.maximize_window()
        self.login_page = AdminLogin(self.driver)
        self.login_page.setUserName(ReadConfig.get_ceo_Username())
        self.login_page.setPassword(ReadConfig.get_ceo_Password())
        self.login_page.clickLogin()
        time.sleep(5)

    def getTurbines(self, list):
        self.driver.find_element_by_id(list).click()
        time.sleep(5)

    def check_list_of_turbines(self):
        turs = self.driver.find_elements_by_id()


    def getbackbtn(self):
        self.driver.find_element_by_id(self.backIcon).click()

    def get_turbines_list(self):
        self.driver.find_element_by_xpath("//*[@id='main-menu']/li[2]/a").click()
        lst = self.driver.find_elements_by_css_selector("ul.nav-submenu >li:nth-of-type(n)")
        turbine = []
        for i in lst:
            turbine.append(i.text)
        return turbine

    def check_variance_chart(self):
        self.files = DirectoryPath()
        self.login_page = ceo_page(self.driver)
        self.driver.find_element_by_id(self.login_page.forcasted_onDate).clear()
        time.sleep(2)
        startDate = self.driver.find_element_by_id(self.login_page.forcasted_onDate)
        startDate.send_keys('10/01/2021')
        time.sleep(2)
        self.driver.find_element_by_id(self.login_page.forecastedendDate).clear()
        time.sleep(2)
        endDate = self.driver.find_element_by_id(self.login_page.forecastedendDate)
        endDate.send_keys('20/01/2021')
        time.sleep(2)
        self.driver.find_element_by_id(self.login_page.forecastedSubmitBtn).click()
        time.sleep(3)
        self.driver.find_element_by_id(self.login_page.varianceDownloadBtn).click()
        time.sleep(3)
        self.filename = self.files.get_download_dir() + '/' + self.login_page.gvpalli_variance
        print(self.filename)
        if os.path.isfile(self.filename) != True:
            print('Windfarm variance 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)
                act_generation = 0
                forcasted = 0
                for row in csv.reader(fin):
                    print('\n', row)
                    act_generation += float(row[2])
                    forcasted += float(row[1])

                actual = (self.driver.find_element_by_id(self.login_page.tur_actualPowerGen).text).replace('KWh', '')
                forcast = (self.driver.find_element_by_id(self.login_page.tur_forecastPowerGen).text).replace('KWh', '')

                generated = float(re.sub('\f', "", actual).strip())
                forcasting = float(re.sub('\f', "", forcast).strip())

                generated = round(generated,2)
                forcasting =  round(forcasting,2)

                act_generation = round(act_generation,2)
                forcasted = round(forcasted,2)
                os.remove(self.filename)
                print(generated, ":", type(generated), act_generation, ":", type(act_generation), forcasting, ":",
                      type(forcasting), forcasted, ":", type(forcasted))

                if str(act_generation) != str(generated):
                    print('Difference found at actual generation ', act_generation, generated)
                if str(forcasted) != str(forcasting):
                    print('Difference found at actual forcasted ', forcasted, forcasting)
                self.driver.close()
            self.driver.close()

    def check_turbines_forcasted_chart(self):
        self.files = DirectoryPath()
        self.login_page = ceo_page(self.driver)
        self.driver.find_element_by_id(self.login_page.forcasted_onDate).clear()
        time.sleep(2)
        startDate = self.driver.find_element_by_id(self.login_page.forcasted_onDate)
        startDate.send_keys('10/01/2021')
        time.sleep(2)
        self.driver.find_element_by_id(self.login_page.forecastedendDate).clear()
        time.sleep(2)
        endDate = self.driver.find_element_by_id(self.login_page.forecastedendDate)
        endDate.send_keys('20/01/2021')
        time.sleep(2)
        self.driver.find_element_by_id(self.login_page.forecastedSubmitBtn).click()
        time.sleep(3)
        self.driver.find_element_by_id(self.login_page.varianceDownloadBtn).click()
        time.sleep(3)
        self.filename = self.files.get_download_dir() + '/' + self.login_page.turbine_02+"_variance.csv"
        print(self.filename)
        if os.path.isfile(self.filename) != True:
            print('Windfarm variance 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)
                act_generation = 0
                forcasted = 0
                for row in csv.reader(fin):
                    print('\n', row)
                    act_generation += float(row[2])
                    forcasted += float(row[1])

                actual = (self.driver.find_element_by_id(self.login_page.actualPowerGen).text).replace('KWh', '')
                forcast = (self.driver.find_element_by_id(self.login_page.forecastPowerGen).text).replace('KWh', '')

                generated = float(re.sub('\f', "", actual).strip())
                forcasting = float(re.sub('\f', "", forcast).strip())

                generated = round(generated, 2)
                forcasting = round(forcasting, 2)

                act_generation = round(act_generation, 2)
                forcasted = round(forcasted, 2)
                os.remove(self.filename)
                print(generated,":",type(generated),act_generation,":",type(act_generation),forcasting,":",type(forcasting),forcasted,":",type(forcasted))
                if int(act_generation) != int(generated):
                    print('Difference found at actual generation ', act_generation, generated)
                if int(forcasted) != int(forcasting):
                    print('Difference found at actual forcasted ', forcasted, forcasting)
コード例 #2
0
class Test_Admin_Login:
    baseURL = ReadConfig.getApplicationURL()
    username = ReadConfig.getUsername()
    password = ReadConfig.getPassword()
    logger = LogGen.logen()

    def test_admin_login_page(self, setup):
        self.logger.info("******Testing admin login started******")
        self.driver = setup
        self.driver.get(self.baseURL)
        actual_title = self.driver.title
        if actual_title == "Atria WindPower":
            assert True
            self.driver.close()
            self.logger.info("******Testing admin login completed******")
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_login_title.png")
            self.driver.close()
            self.logger.info("******Testing admin login failed******")
            assert False

    def test_admin_login_with_valid_username_and_valid_password(self, setup):
        self.logger.info(
            "******Testing admin login with valid username and password started******"
        )
        self.driver = setup
        self.driver.get(self.baseURL)
        self.admin_login = AdminLogin(self.driver)
        self.admin_login.setUserName(ReadConfig.getUsername())
        self.admin_login.setPassword(ReadConfig.getPassword())
        self.admin_login.clickLogin()
        if self.admin_login.getUserListTitile() == "Users List":
            assert True
            self.logger.info(
                "******Testing admin login with valid username and password successfully completed******"
            )
            self.driver.close()
        else:
            self.driver.save_screenshot(
                "../Screenshots/" +
                "test_admin_login_with_valid_username_and_valid_password.png")
            self.logger.info(
                "******Testing admin login with valid username and password failed******"
            )
            self.driver.close()
            assert False

    def test_admin_login_add_user_page(self, setup):
        self.logger.info(
            "******Testing admin login user page exist or not started******")
        self.driver = setup
        al = AdminLogin(self.driver)
        al.adminLogin()
        al.clickAuthentication()
        al.clickAddUser()
        if al.getAddUserTitle() == "ADD USER":
            assert True
            self.logger.info(
                "******Testing admin login user page exist or not completed******"
            )
            self.driver.close()
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_userpage.png")
            self.logger.info(
                "******Testing admin login user page exist or not failed******"
            )
            self.driver.close()
            assert False

    def test_admin_login_add_user_without_entering_details(self, setup):
        self.logger.info(
            "******Testing admin login add user without entering details started******"
        )
        self.driver = setup
        al = AdminLogin(self.driver)
        al.adminLogin()
        al.clickAuthentication()
        al.clickAddUser()
        al.clickSubmit()
        if al.getAddUserUserNameErrorMsg(
        ) == "Username is required and should be unique" and al.getAddUserEmailErrorMsg(
        ) == "Email is required" and al.getAddUserPasswordErrorMsg(
        ) == "Password is required":
            assert True
            self.logger.info(
                "******Testing admin login add user without entering details completed******"
            )
            self.driver.close()
        else:
            self.driver.save_screenshot(
                "../Screenshots/" +
                "test_addUser_without_entering_details.png")
            self.logger.info(
                "******Testing admin login add user without entering details failed******"
            )
            self.driver.close()
            assert False

    def test_admin_login_add_user_with_invalid_username_invalid_email_invalid_password(
            self, setup):
        self.starting_row_num = 2
        self.ending_row_num = 5
        self.logger.info(
            "******Testing admin login add user with invalid username invalid email invalid passwprd "
            "started******")
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAuthentication()
        self.al.clickAddUser()
        self.al.clickSubmit()
        status = []
        #Reading the data from excel file
        for r in range(self.starting_row_num, self.ending_row_num):
            self.add_user_username = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 1)
            self.add_user_email = ExcelUtils.readData(self.al.getExcelPath(),
                                                      'Add User', r, 2)
            self.add_user_role = ExcelUtils.readData(self.al.getExcelPath(),
                                                     'Add User', r, 3)
            self.add_user_accessTo = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 4)
            self.add_user_password = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 5)
            self.add_user_exp = ExcelUtils.readData(self.al.getExcelPath(),
                                                    'Add User', r, 6)
            self.al.setAddUserUserName(self.add_user_username)
            self.al.setAddUserEmail(self.add_user_email)
            self.al.setAdduserSelectRole(self.add_user_role)
            self.al.setAdduserSelectAccessTo(self.add_user_accessTo)
            self.al.setAddUserPassword(self.add_user_password)
            self.al.clickSubmit()
            time.sleep(5)
            act_title = self.al.getAddUserSuccessMsg()
            exp_title = "User created successfully"

            if act_title == exp_title:
                if self.add_user_exp == "Pass":
                    self.al.clickLogin()
                    status.append("Pass")
                elif self.add_user_exp == "Fail":
                    self.al.clickLogin()
                    status.append("Fail")
            elif act_title != exp_title:
                if self.add_user_exp == "Pass":
                    status.append("Fail")
                elif self.add_user_exp == "Fail":
                    status.append("Pass")

        if "Fail" not in status:
            self.logger.info(
                "******Testing admin login add user with invalid username invalid email invalid password "
                "completed******")
            self.driver.close()
            assert True
        else:
            self.driver.save_screenshot(
                "../Screenshots/" +
                "test_addUser_by_entering_invalid_details.png")
            self.logger.info(
                "******Testing admin login add user with invalid username invalid email invalid password "
                "failed******")
            self.driver.close()
            assert False

    def test_admin_login_add_user_admin_ceo_manager(self, setup):
        self.starting_row_num = 5
        self.ending_row_num = 8
        self.logger.info(
            "******Testing admin login add users(admin,ceo,manager) started******"
        )
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAuthentication()
        self.al.clickAddUser()
        self.al.clickSubmit()
        status = []
        # Reading the data from excel file
        for r in range(self.starting_row_num, self.ending_row_num):
            self.add_user_username = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 1)
            self.add_user_email = ExcelUtils.readData(self.al.getExcelPath(),
                                                      'Add User', r, 2)
            self.add_user_role = ExcelUtils.readData(self.al.getExcelPath(),
                                                     'Add User', r, 3)
            self.add_user_accessTo = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 4)
            self.add_user_password = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 5)
            self.add_user_exp = ExcelUtils.readData(self.al.getExcelPath(),
                                                    'Add User', r, 6)
            self.al.setAddUserUserName(self.add_user_username)
            self.al.setAddUserEmail(self.add_user_email)
            self.al.setAdduserSelectRole(self.add_user_role)
            self.al.setAdduserSelectAccessTo(self.add_user_accessTo)
            self.al.setAddUserPassword(self.add_user_password)
            self.al.clickSubmit()
            time.sleep(1)
            act_title = self.al.getAddUserSuccessMsg()
            exp_title = "User created successfully"
            if act_title == exp_title:
                if self.add_user_exp == "Pass":
                    status.append("Pass")
                elif self.add_user_exp == "Fail":
                    status.append("Fail")
            elif act_title != exp_title:
                if self.add_user_exp == "Pass":
                    status.append("Fail")
                elif self.add_user_exp == "Fail":
                    status.append("Pass")

        if "Fail" not in status:
            self.logger.info(
                "******Testing admin login add users(admin,ceo,manager) completed******"
            )
            self.driver.close()
            assert True
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_addUsers(admin,ceo,manger).png")
            self.logger.info(
                "******Testing admin login add users(admin,ceo,manager) failed******"
            )
            self.driver.close()
            assert False

    def test_admin_login_add_user_user_exist_error_msg(self, setup):
        self.starting_row_num = 5
        self.ending_row_num = 8
        self.logger.info(
            "******Testing admin login user exist msg checking...******")
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAuthentication()
        self.al.clickAddUser()
        self.al.clickSubmit()
        status = []
        # Reading the data from excel file
        for r in range(self.starting_row_num, self.ending_row_num):
            self.add_user_username = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 1)
            self.add_user_email = ExcelUtils.readData(self.al.getExcelPath(),
                                                      'Add User', r, 2)
            self.add_user_role = ExcelUtils.readData(self.al.getExcelPath(),
                                                     'Add User', r, 3)
            self.add_user_accessTo = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 4)
            self.add_user_password = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 5)
            self.add_user_exp = ExcelUtils.readData(self.al.getExcelPath(),
                                                    'Add User', r, 6)
            self.al.setAddUserUserName(self.add_user_username)
            self.al.setAddUserEmail(self.add_user_email)
            self.al.setAdduserSelectRole(self.add_user_role)
            self.al.setAdduserSelectAccessTo(self.add_user_accessTo)
            self.al.setAddUserPassword(self.add_user_password)
            self.al.clickSubmit()
            time.sleep(2)

            act_title = self.al.getAddUserSuccessMsg()
            exp_title = "User exists with that name. Please create with different user"
            self.driver.refresh()
            if act_title == exp_title:
                if self.add_user_exp == "Pass":
                    status.append("Pass")
                elif self.add_user_exp == "Fail":
                    status.append("Fail")
            elif act_title != exp_title:
                if self.add_user_exp == "Pass":
                    status.append("Fail")
                elif self.add_user_exp == "Fail":
                    status.append("Pass")

        if "Fail" not in status:
            self.logger.info(
                "******Testing admin login user exist msg checking completed...******"
            )
            self.driver.close()
            assert True
        else:
            self.logger.info(
                "******Testing admin login user exist msg checking failed...******"
            )
            self.driver.close()
            assert False

    def test_admin_login_userlist_page(self, setup):
        self.logger.info(
            "******Testing admin login user list displayed or not started******"
        )
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAuthentication()
        self.al.clickUserList()
        if self.al.getUserListTitile() == "Users List":
            self.driver.close()
            assert True
            self.logger.info(
                "******Testing admin login user list displayed successfully******"
            )
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_userlist_page.png")
            self.logger.info(
                "******Testing admin login user list displayed or not failed******"
            )
            self.driver.close()
            assert False

    def test_admin_login_userlist_created_users(self, setup):
        self.logger.info(
            "******Testing admin login created users started******")
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAuthentication()
        self.al.clickUserList()
        time.sleep(2)
        res_list = []
        self.users_lst = self.al.getUsersList()
        for remove_id in self.users_lst:
            del remove_id[0]
        comp_list = self.al.getComparisionList()
        for x in comp_list:
            if x in self.users_lst:
                res_list.append(x)
        if res_list == comp_list:
            assert True, "Created users exist in the user list"
            self.logger.info(
                "******Testing admin login created users completed******")
            self.driver.close()
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_admin_login_created_users.png")
            self.logger.info(
                "******Testing admin login created users failed******")
            self.driver.close()
            assert False, "Created users not configured properly on the userlist table"

    def test_admin_login_userlist_edit_option_for_all_users(self, setup):
        self.logger.info(
            "******Testing admin login user list edit option checking started******"
        )
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        time.sleep(2)
        userlist = self.al.getUsersList()
        for ul in userlist:
            result = self.al.clickEditoption(ul[0])
            if result == "Users List":
                self.al.clickAddUserEditOptionCloseButton()
                assert True, "Edit option is working"
            else:
                self.driver.save_screenshot(
                    "../Screenshots/" +
                    "test_admin_login_userlist_edit_option_failure.png")
                self.logger.info(
                    "******Testing admin login user list edit option checking failed******"
                )
                self.driver.close()
                assert False, "Edit option is not working"
        self.driver.close()

    def test_admin_login_userlist_edit_users(self, setup):
        self.logger.info("******Testing admin login edit user's started******")
        self.starting_row_num = 8
        self.ending_row_num = 9
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAuthentication()
        self.al.clickAddUser()
        # Reading the data from excel file
        for r in range(self.starting_row_num, self.ending_row_num):
            self.add_user_username = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 1)
            self.add_user_email = ExcelUtils.readData(self.al.getExcelPath(),
                                                      'Add User', r, 2)
            self.add_user_role = ExcelUtils.readData(self.al.getExcelPath(),
                                                     'Add User', r, 3)
            self.add_user_accessTo = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 4)
            self.add_user_password = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 5)
            self.add_user_exp = ExcelUtils.readData(self.al.getExcelPath(),
                                                    'Add User', r, 6)
            self.al.setAddUserUserName(self.add_user_username)
            self.al.setAddUserEmail(self.add_user_email)
            self.al.setAdduserSelectRole(self.add_user_role)
            self.al.setAdduserSelectAccessTo(self.add_user_accessTo)
            self.al.setAddUserPassword(self.add_user_password)
            self.al.clickSubmit()
            time.sleep(2)
        self.driver.refresh()
        self.al.clickAuthentication()
        self.al.clickUserList()
        time.sleep(5)
        user_list = self.al.getUsersList()
        update_list = self.al.getExcelDeleteData(8, 9)
        row_num = []
        for x in update_list:
            for y in user_list:
                if y[1] == x:
                    row_num.append(y[0])
        excel_record = self.al.getExcelRecord(8, 9)
        self.test_status = self.al.clickUpdateUser(row_num, excel_record)
        if "Fail" not in self.test_status:
            self.logger.info(
                "******Testing admin login update user's successfully created******"
            )
            self.driver.close()
            assert True, "Edit user successful for admin,ceo and manager"
        else:
            self.logger.info(
                "******Testing admin login update user's failed******")
            self.driver.close()
            assert False, "Edit user Failed"

    def test_admin_login_userlist_edit_option_close_button(self, setup):
        self.logger.info(
            "******Testing admin login adduser edit option started******")
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAddUserEditOptionWithCloseButton(2)
        if self.al.getUserListTitile() == "Users List":
            self.logger.info(
                "******Testing admin login adduser edit option completed******"
            )
            assert True, "Close button working"
            self.driver.close()
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_admin_login_edit_option.png")
            self.logger.info(
                "******Testing admin login adduser edit option failed******")
            self.driver.close()
            assert False, "Close button is not working"

    def test_admin_login_userlist_delete(self, setup):
        self.delete_user_list = []
        self.starting_row_num = 9
        self.ending_row_num = 10
        self.logger.info(
            "******Testing admin login adduser delete option started******")
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        self.al.clickAuthentication()
        self.al.clickAddUser()
        # Getting the data from excel file and creating the new user in the atria add user page
        for r in range(self.starting_row_num, self.ending_row_num):
            self.add_user_username = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 1)
            self.delete_user_list.append(self.add_user_username)
            self.add_user_email = ExcelUtils.readData(self.al.getExcelPath(),
                                                      'Add User', r, 2)
            self.add_user_role = ExcelUtils.readData(self.al.getExcelPath(),
                                                     'Add User', r, 3)
            self.add_user_accessTo = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 4)
            self.add_user_password = ExcelUtils.readData(
                self.al.getExcelPath(), 'Add User', r, 5)
            self.add_user_exp = ExcelUtils.readData(self.al.getExcelPath(),
                                                    'Add User', r, 6)
            self.al.setAddUserUserName(self.add_user_username)
            self.al.setAddUserEmail(self.add_user_email)
            self.al.setAdduserSelectRole(self.add_user_role)
            self.al.setAdduserSelectAccessTo(self.add_user_accessTo)
            self.al.setAddUserPassword(self.add_user_password)
            self.al.clickSubmit()
        time.sleep(2)
        self.al.clickAuthentication()
        self.al.clickUserList()
        time.sleep(2)
        user_list = self.al.getUsersList()
        delete_id = []
        for delete_user in self.delete_user_list:
            for user in user_list:
                if user[1] == delete_user:
                    delete_id.append(user[0])
        self.al.clickAddUserDeleteOption(delete_id)
        time.sleep(10)
        user_list_after_delete = self.al.getUsersList()
        get_deleted_user_list = self.delete_user_list
        self.status = False
        # Checking whether deleted user list still present in the userlist page
        for deleted_user in get_deleted_user_list:
            for user in user_list_after_delete:
                if user[1] == deleted_user:
                    self.status = True  # if user found making status to true
        if self.status == False:
            self.logger.info(
                "******Testing admin login adduser delete option completed******"
            )
            assert True, "User deleted successfully"
            self.driver.close()
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_admin_login_delete_option.png")
            self.logger.info(
                "******Testing admin login adduser delete option failed******")
            self.driver.close()
            assert False, "User not deleted"

    def test_admin_login_logout(self, setup):
        self.logger.info("******Testing admin login logout started******")
        self.driver = setup
        self.al = AdminLogin(self.driver)
        self.al.adminLogin()
        time.sleep(3)
        self.al.clickLogout()
        if self.al.getLoginHeader() == "Login":
            self.logger.info(
                "******Testing admin login logout completed******")
            assert True, "Logout is successful"
            self.driver.close()
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_admin_login_logout.png")
            self.logger.info("******Testing admin login logout failed******")
            self.driver.close()
            assert False, "Logout is unsuccessful"
コード例 #3
0
class Test_Atria_Login_Page:
    baseURL = ReadConfig.getApplicationURL()
    invalid_uname = ReadConfig.get_invalid_Username()
    invalid_pwd = ReadConfig.get_invalid_Password()
    logger = LogGen.logen()

    #Positive test scripts for login page
    def test_admin_login_page(self, setup):
        self.logger.info(
            "********************Test Admin Login Started********************************"
        )
        self.driver = setup
        self.driver.get(self.baseURL)
        actual_title = self.driver.title
        if actual_title == "Atria WindPower":
            assert True
            self.driver.close()
            self.logger.info(
                "********************Test Admin Login Ended********************************"
            )
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_login_title.png")
            self.driver.close()
            self.logger.info(
                "********************Test  Login Ended Due to difference in the title********************************"
            )
            assert False

    def test_login_as_admin_user(self, setup):
        self.logger.info(
            "********************Test Login Page Started********************************"
        )
        self.driver = setup
        self.login_page = AdminLogin(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.setUserName(ReadConfig.getUsername())
        self.login_page.setPassword(ReadConfig.getPassword())
        self.login_page.clickLogin()
        time.sleep(5)
        actual_page = self.driver.current_url
        if 'users' in actual_page:
            assert True
            self.logger.info(
                "********************Test Admin Page Ended********************************"
            )
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_login_page.png")
            self.driver.close()
            self.logger.info(
                "********************Test Admin Page Ended Due to error msg is mismatch ********************************"
            )
            assert False

    def test_login_as_manager_user(self, setup):
        self.logger.info(
            "********************Test Login Page Started********************************"
        )
        self.driver = setup
        self.login_page = AdminLogin(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.setUserName(ReadConfig.get_manager_Username())
        self.login_page.setPassword(ReadConfig.get_manager_Password())
        self.login_page.clickLogin()
        time.sleep(5)
        actual_content = self.driver.find_element_by_class_name(
            'page-heading').text
        if 'Wind Farms' in actual_content:
            assert True
            self.driver.close()
            self.logger.info(
                "********************Test Manager login Ended********************************"
            )
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_login_page.png")
            self.driver.close()
            self.logger.info(
                "********************Test Manager Page Ended Due to error msg is mismatch ********************************"
            )
            assert False

    def test_login_as_ceo_user(self, setup):
        self.logger.info(
            "********************Test Login Page Started********************************"
        )
        self.driver = setup
        self.login_page = AdminLogin(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.setUserName(ReadConfig.get_ceo_Username())
        self.login_page.setPassword(ReadConfig.get_ceo_Password())
        self.login_page.clickLogin()
        time.sleep(5)
        actual_content = self.driver.current_url
        if 'dashboard' in actual_content:
            assert True
            self.driver.close()
            self.logger.info(
                "********************Test CEO Login Ended********************************"
            )
        else:
            self.driver.save_screenshot("../Screenshots/" +
                                        "test_login_page.png")
            self.driver.close()
            self.logger.info(
                "********************Test CEO Page Ended Due to error msg is mismatch ********************************"
            )
            assert False

    #Negative test scripts for login page

    def test_login_without_inputs(self, setup):
        self.logger.info(
            "********************Test Login Page Started********************************"
        )
        self.driver = setup
        self.login_page = AdminLogin(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.clickLogin()
        errormsg = self.driver.find_element_by_tag_name('p').text
        print('errormsg on ui', errormsg)
        if errormsg == 'Please enter the username & 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_login_without_password(self, setup):
        self.logger.info(
            "********************Test Login Page Started********************************"
        )
        self.driver = setup
        self.login_page = ceo_page(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.set_invalid_UserName(ReadConfig.get_invalid_Username())
        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_login_without_username(self, setup):
        self.logger.info(
            "********************Test Login Page Started********************************"
        )
        self.driver = setup
        self.login_page = ceo_page(self.driver)
        self.driver.get(self.baseURL)
        self.login_page.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_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