|
| 1 | +from selenium.webdriver.chrome.options import Options |
| 2 | +from selenium.webdriver.common.keys import Keys |
| 3 | +from time import sleep |
| 4 | +import allure |
| 5 | +import openpyxl as xl |
| 6 | +from selenium import webdriver as wd |
| 7 | +from pywinauto.keyboard import SendKeys |
| 8 | +from openpyxl.drawing import image |
| 9 | +import time, shutil, datetime |
| 10 | +import random |
| 11 | +import requests as rq |
| 12 | +import json |
| 13 | +import pytest |
| 14 | +from selenium.webdriver.common.action_chains import ActionChains |
| 15 | +from selenium.webdriver.common.by import By |
| 16 | +from selenium.webdriver.support.ui import Select |
| 17 | +from selenium.common.exceptions import NoSuchElementException |
| 18 | +from selenium.common.exceptions import NoAlertPresentException |
| 19 | +from selenium.webdriver.support import expected_conditions as EC |
| 20 | +from selenium.webdriver.support.wait import WebDriverWait |
| 21 | +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities |
| 22 | +from allure_commons.types import AttachmentType |
| 23 | + |
| 24 | +import os |
| 25 | + |
| 26 | +from pyutil import fileutil |
| 27 | +from tabulate import tabulate |
| 28 | +import win32com.client as cli |
| 29 | + |
| 30 | +root_dir = "C:\\Users\\patelvi\\PycharmProjects\\NCE\\" |
| 31 | + |
| 32 | + |
| 33 | +def report(): |
| 34 | + report_time = str(datetime.datetime.today().strftime('%y%m%d_%H%M')) |
| 35 | + os.system("allure generate onx/report -o onx\\reports\\" + report_time) |
| 36 | + #os.system("allure serve onx/report") |
| 37 | + outlook = cli.Dispatch('outlook.application') |
| 38 | + mail = outlook.CreateItem(0) |
| 39 | + # mail.Display () # required to paste chart |
| 40 | + |
| 41 | + mail.Subject = 'Test Execution Report of ' + str(datetime.date.today()) |
| 42 | + mail.HTMLBody = '<p>Dear All,</p>' \ |
| 43 | + '<p>Please find the Test execution report with following link <b>' + 'http://10.144.56.84:8000/' + report_time + '/</b></p>' \ |
| 44 | + '<p>Please send any feedback on this status report to Vikash. </p>' \ |
| 45 | + '<p>Thanks </p>' |
| 46 | + |
| 47 | + |
| 48 | +options = wd.ChromeOptions() |
| 49 | +options.add_argument('--ignore-certificate-errors-spki-list') |
| 50 | +options.add_argument('--ignore-ssl-errors') |
| 51 | +Chrome_driver = wd.Chrome(r'C:\\Users\patelvi\\PycharmProjects\\NCE\\onx\\Drivers\\chrome_driver.exe',chrome_options=options) |
| 52 | + |
| 53 | +#FF_driver = wd.Firefox(r'C:\\Users\\patelvi\\PycharmProjects\\NCE\\onx\\Drivers\\geckodriver.exe') |
| 54 | + |
| 55 | +@pytest.fixture(scope="session", autouse=True, params=[Chrome_driver]) # ,wd.Chrome()wd.Firefox(),wd.Ie()]) |
| 56 | +def browser(request): |
| 57 | + driver = request.param |
| 58 | + driver.get('https://www.kroger.com/') |
| 59 | + driver.maximize_window() |
| 60 | + driver.implicitly_wait(30) |
| 61 | + time.sleep(3) |
| 62 | + driver.find_element_by_xpath("//button[.='Next']").click() |
| 63 | + time.sleep(5) |
| 64 | + driver.find_element_by_xpath( |
| 65 | + '//button[@class="kds-Button kds-Button--primaryInverse kds-Button--hasIconOnly EducationTooltip-CloseButton"]').click() |
| 66 | + |
| 67 | + time.sleep(2) |
| 68 | + sign_in = driver.find_element_by_xpath('//div[.="Sign In"]') |
| 69 | + hover(driver, sign_in) |
| 70 | + driver.find_element_by_xpath('//a[.="Create Account"]').click() |
| 71 | + time.sleep(5) |
| 72 | + driver.find_element_by_id('AccountCreate-firstNameInput').send_keys('vv') |
| 73 | + driver.find_element_by_id('AccountCreate-lastNameInput').send_keys('pp') |
| 74 | + email = 'vv' + str(random.randint(1111, 9999)) + '@gmail.com' |
| 75 | + driver.find_element_by_id('AccountCreate-emailInput').send_keys(email) |
| 76 | + driver.find_element_by_id('AccountCreate-passwordInput').send_keys('A12345678') |
| 77 | + driver.find_element_by_id('loyaltyCardButton-virtualCard').click() |
| 78 | + card_no = random.randint(1111111111, 9999999999) |
| 79 | + print(card_no) |
| 80 | + print(email) |
| 81 | + driver.find_element_by_id('AccountCreate-virtualCardInput').send_keys(card_no) |
| 82 | + driver.find_element_by_id('AccountCreate-submitButton').click() |
| 83 | + time.sleep(3) |
| 84 | + yield driver |
| 85 | + driver.close() |
| 86 | + report() |
| 87 | + |
| 88 | + |
| 89 | +def hover(driver, ele): |
| 90 | + action = ActionChains(driver) |
| 91 | + action.move_to_element(ele).perform() |
| 92 | + |
| 93 | + |
| 94 | +@allure.feature("Shopping feature") |
| 95 | +def test_shop(browser): |
| 96 | + |
| 97 | + time.sleep(5) |
| 98 | + shop = browser.find_element_by_xpath('//span["Shop"]') |
| 99 | + time.sleep(1) |
| 100 | + hover(browser, shop) |
| 101 | + browser.find_element_by_xpath('//a[.="Candy"]').click() |
| 102 | + time.sleep(2) |
| 103 | + browser.find_element_by_xpath('//a[.="Chocolate"]').click() |
| 104 | + time.sleep(2) |
| 105 | + browser.find_element_by_xpath('//h4[.="Brands"]').click() |
| 106 | + time.sleep(2) |
| 107 | + browser.find_element_by_xpath("//*[@id='content']//span/input").send_keys('Snickers') |
| 108 | + browser.find_element_by_name('Snickers').click() |
| 109 | + time.sleep(3) |
| 110 | + |
| 111 | + browser.find_element_by_xpath('(//button[.="Add to Cart"])[1]').click() |
| 112 | + time.sleep(2) |
| 113 | + browser.find_element_by_xpath('//button[.="Confirm"]').click() |
| 114 | + time.sleep(2) |
| 115 | + SendKeys("^a") |
| 116 | + #driver.find_element_by_xpath("(//input[@data-testid='kds-Stepper-input'])[1]").clear() |
| 117 | + time.sleep(5) |
| 118 | + browser.find_element_by_xpath("(//input[@data-testid='kds-Stepper-input'])[1]").send_keys('10') |
| 119 | + time.sleep(3) |
| 120 | + browser.find_element_by_xpath('//span[.="Cart"]').click() |
| 121 | + #driver.find_element_by_xpath('//*[contains(text(),"Pickup"]').click() |
| 122 | + item_cnt= str.replace(browser.find_element_by_xpath('//h1[@data-qa="summary-item-count"]').text,'Pickup Items: ','') |
| 123 | + total=browser.find_element_by_xpath('//span[@data-qa="summary-cart-section-total"]').text |
| 124 | + |
| 125 | + assert total == '$10.00' |
| 126 | + assert item_cnt == '10' |
| 127 | + allure.attach(browser.get_screenshot_as_png(), name='screenshot', attachment_type=AttachmentType.PNG) |
| 128 | + |
| 129 | + |
| 130 | +''' |
| 131 | +
|
| 132 | +def test_create_acct(browser): |
| 133 | +
|
| 134 | + browser.get('https://www.kroger.com/') |
| 135 | + browser.maximize_window() |
| 136 | + browser.implicitly_wait(30) |
| 137 | + time.sleep(3) |
| 138 | + browser.find_element_by_xpath("//button[.='Next']").click() |
| 139 | + time.sleep(5) |
| 140 | + browser.find_element_by_xpath('//button[@class="kds-Button kds-Button--primaryInverse kds-Button--hasIconOnly EducationTooltip-CloseButton"]').click() |
| 141 | +
|
| 142 | + time.sleep(2) |
| 143 | + sign_in = browser.find_element_by_xpath('//div[.="Sign In"]') |
| 144 | + hover(browser, sign_in) |
| 145 | + browser.find_element_by_xpath('//a[.="Create Account"]').click() |
| 146 | + time.sleep(5) |
| 147 | + browser.find_element_by_id('AccountCreate-firstNameInput').send_keys('vv') |
| 148 | + browser.find_element_by_id('AccountCreate-lastNameInput').send_keys('pp') |
| 149 | + email = 'v' + str(random.randint(1111, 9999)) + '@gmail.com' |
| 150 | + browser.find_element_by_id('AccountCreate-emailInput').send_keys(email) |
| 151 | + browser.find_element_by_id('AccountCreate-passwordInput').send_keys('A12345678') |
| 152 | + browser.find_element_by_id('loyaltyCardButton-virtualCard').click() |
| 153 | + card_no = random.randint(1111111111, 9999999999) |
| 154 | + print(card_no) |
| 155 | + print(email) |
| 156 | + browser.find_element_by_id('AccountCreate-virtualCardInput').send_keys(card_no) |
| 157 | + browser.find_element_by_id('AccountCreate-submitButton').click() |
| 158 | + time.sleep(3) |
| 159 | +
|
| 160 | +
|
| 161 | +
|
| 162 | +def test_signin(browser): |
| 163 | +
|
| 164 | + browser.get('https://www.kroger.com/') |
| 165 | + browser.maximize_window() |
| 166 | + browser.implicitly_wait(30) |
| 167 | + token=browser.get_cookie('XSRF-TOKEN') |
| 168 | + time.sleep(3) |
| 169 | + browser.find_element_by_xpath("//button[.='Next']").click() |
| 170 | + time.sleep(5) |
| 171 | + browser.find_element_by_xpath('//button[@class="kds-Button kds-Button--primaryInverse kds-Button--hasIconOnly EducationTooltip-CloseButton"]').click() |
| 172 | + time.sleep(2) |
| 173 | +
|
| 174 | + sign_in = browser.find_element_by_xpath('(//button[@class="ListItem-Button-Dropdown text-default-800"])[5]') |
| 175 | + hover(browser, sign_in) |
| 176 | + browser.find_element_by_xpath('//a[.="Sign In"]').click() |
| 177 | + time.sleep(5) |
| 178 | + browser.find_element_by_id('SignIn-emailInput').send_keys('[email protected]') |
| 179 | + time.sleep(3) |
| 180 | + browser.find_element_by_id('SignIn-passwordInput').send_keys('A12345678') |
| 181 | + time.sleep(3) |
| 182 | + browser.find_element_by_id('SignIn-rememberMe').click() |
| 183 | + time.sleep(3) |
| 184 | + #driver.find_element_by_id('SignIn-submitButton').click() |
| 185 | + #SendKeys("{TAB}{TAB}{ENTER}") |
| 186 | + si = browser.find_element_by_id('SignIn-submitButton') |
| 187 | + ActionChains(browser).move_to_element(si).click().perform() |
| 188 | + #driver.execute_script ("arguments[0].click();" , si) |
| 189 | +
|
| 190 | +
|
| 191 | + time.sleep(5) |
| 192 | +''' |
| 193 | +@allure.feature("Save Coupons") |
| 194 | +def test_save_coupon(browser): |
| 195 | + time.sleep(5) |
| 196 | + save=browser.find_element_by_xpath('//span[.="Save"]') |
| 197 | + hover(browser,save) |
| 198 | + time.sleep(2) |
| 199 | + browser.find_element_by_xpath('//a[.="Digital Coupons"]').click() |
| 200 | + time.sleep(3) |
| 201 | + browser.find_element_by_id('SearchableList-item-Bakery').click() |
| 202 | + time.sleep(3) |
| 203 | + browser.find_element_by_xpath('//*[contains(text(),"Added in last 7 days")]').click() |
| 204 | + time.sleep(3) |
| 205 | + browser.find_element_by_xpath('(//span[.="Load to Card"])[1]').click() |
| 206 | + time.sleep(2) |
| 207 | + acct=browser.find_element_by_xpath('(//button[@class="ListItem-Button-Dropdown text-default-800"])[5]') |
| 208 | + hover(browser,acct) |
| 209 | + browser.find_element_by_xpath('//a[.="My Coupons"]').click() |
| 210 | + coupon_no=browser.find_element_by_xpath('//div[@data-qa="coupons-count-format"]//span').text |
| 211 | + assert coupon_no =='1 Coupon' |
| 212 | + allure.attach(browser.get_screenshot_as_png(), name='screenshot', attachment_type=AttachmentType.PNG) |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | +@allure.feature("Clinic Appointment") |
| 217 | +def test_clinic_appt(browser): |
| 218 | + time.sleep(5) |
| 219 | + ph= browser.find_element_by_xpath('//span[.="Pharmacy & Health"]') |
| 220 | + hover(browser,ph) |
| 221 | + time.sleep(2) |
| 222 | + browser.find_element_by_xpath('//a[contains(text(),"The Little Clinic")]').click() |
| 223 | + time.sleep(3) |
| 224 | + browser.find_element_by_xpath('//input[@name="search.clinicFinderSearchText-typeahead-searchText"]').send_keys('44870') |
| 225 | + browser.find_element_by_xpath('//button[.="Find"]').click() |
| 226 | + time.sleep(3) |
| 227 | + browser.find_element_by_xpath('(//button[.="Schedule Appointment"])[1]').click() |
| 228 | + time.sleep(3) |
| 229 | + sel =browser.find_element_by_xpath('//select') |
| 230 | + Select(sel).select_by_visible_text('General') |
| 231 | + sel=browser.find_element_by_xpath('(//select)[2]') |
| 232 | + Select(sel).select_by_visible_text('Illness') |
| 233 | + time.sleep(2) |
| 234 | + browser.find_element_by_xpath('(//div[@class="SelectableDate"])[2]').click() |
| 235 | + time.sleep(2) |
| 236 | + browser.find_element_by_xpath('(//div[@class="AvailableSlots-GridCell"])[1]').click() |
| 237 | + time.sleep(2) |
| 238 | + browser.find_element_by_name('firstName').send_keys('vv') |
| 239 | + browser.find_element_by_name('lastName').send_keys('pp') |
| 240 | + browser.find_element_by_name('phone').send_keys('1234567890') |
| 241 | + browser. find_element_by_name( 'email'). send_keys( '[email protected]') |
| 242 | + dob = browser.find_element_by_xpath('(//select)[3]') |
| 243 | + Select(dob).select_by_visible_text('May') |
| 244 | + browser.find_element_by_name('dateOfBirth.day').send_keys('05') |
| 245 | + browser.find_element_by_name('dateOfBirth.year').send_keys('1977') |
| 246 | + time.sleep(3) |
| 247 | + browser.find_element_by_xpath('//button[@class="kds-Button kds-Button--favorable ScheduleButton"]').click() |
| 248 | + time.sleep(2) |
| 249 | + appt = browser.find_element_by_xpath('//p[@class="confirmationCode"]').text |
| 250 | + print(appt) |
| 251 | + allure.attach(browser.get_screenshot_as_png(), name='screenshot', attachment_type=AttachmentType.PNG) |
| 252 | + |
| 253 | +def test_train_api_name(): |
| 254 | + api_key='020b637468msh24e7cdd5044d6bep11b479jsn5be08562d785' |
| 255 | + by_name={"search":"Rajdhani"} #name |
| 256 | + |
| 257 | + req = rq.post('https://trains.p.rapidapi.com',data=json.dumps(by_name), |
| 258 | + headers={'Content-Type': 'application/json', |
| 259 | + 'x-rapidapi-key': api_key} |
| 260 | + ) |
| 261 | + print(req.text) |
| 262 | + a =json.loads(req.text) |
| 263 | + for b in range(len(a)): |
| 264 | + train_no = a[b]["train_num"] |
| 265 | + train_name = a[b]["name"] |
| 266 | + classes=a[b]["data"]["classes"] |
| 267 | + print(str(train_no)+"|"+train_name+"|"+str(classes)) |
| 268 | + |
| 269 | + |
| 270 | +def test_train_api_no(): |
| 271 | + api_key = '020b637468msh24e7cdd5044d6bep11b479jsn5be08562d785' |
| 272 | + by_no = {"search": '12335'} #number of train |
| 273 | + |
| 274 | + req = rq.post('https://trains.p.rapidapi.com', data=json.dumps(by_no), |
| 275 | + headers={'Content-Type': 'application/json', |
| 276 | + 'x-rapidapi-key': api_key} |
| 277 | + ) |
| 278 | + print(req.text) |
| 279 | + a = json.loads(req.text) |
| 280 | + for b in range(len(a)): |
| 281 | + train_name = a[b]["name"] |
| 282 | + classes = a[b]["data"]["classes"] |
| 283 | + print(train_name + "|" + str(classes)) |
| 284 | + |
| 285 | + |
| 286 | +#test_create_acct() |
| 287 | +#test_signin() |
| 288 | + |
| 289 | + |
| 290 | +#test_train_api_name("Rajdhani") |
| 291 | +#test_train_api_no('12235') |
| 292 | + |
| 293 | + |
| 294 | +#pytest --tb=no --alluredir=onx/report onx/test_pytest.py |
| 295 | +#python -m http.server 8000 --bind 127.0.0.1 |
0 commit comments