Sie sind auf Seite 1von 5

Ananya Lakshmi

2019sp93042

ASSIGNMENT-EQUIVALENCE CLASS TESTING USING SELENIUM

Domain: Online Retail System


Website: amazon.in
Fields: email, phone number
equivalence_class.py
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException, NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
WAIT_TIME = 30
MAX_TRIES = 3

class SlackFailReport:
def __init__(self, driver_location, url):
self.url = url
self.driver_location = driver_location
options = Options()
options.headless = False # make this 'True' to run in background
WEBDRIVER_PATH = self.driver_location
self.username = 'Test_user'
self.password = '123456'
self.email = 'tu18228@gmail.com'
self.phone_number = '9945842250'
self.driver = webdriver.Chrome(executable_path=WEBDRIVER_PATH,
chrome_options=options)

def open_creat_account_page(self):
self.driver.get(self.url)
for _ in range(MAX_TRIES):
first_hover = self.driver.find_element_by_xpath(
'//*[@id="nav-link-accountList"]')
then_click = self.driver.find_element_by_xpath(
'//*[@id="nav-flyout-ya-newCust"]/a')
try:
Hover = ActionChains(self.driver).move_to_element(
first_hover).move_to_element(then_click)
Hover.click().perform()
time.sleep(30)
print("Account login Page loaded successfully")
return True
except WebDriverException:
print("element not clickable retrying..")
time.sleep(WAIT_TIME)
return False

def email_validation(self, list_of_emails):


self.put_default_values()
validation_list = []
for mail in list_of_emails:

email = self.driver.find_element_by_xpath('//*[@id="ap_email"]')
print('Send email: {}'.format(mail))
email.clear()
email.send_keys(mail)

password = self.driver.find_element_by_xpath(
'//*[@id="ap_password"]')
print('Send Password: {}'.format(self.password))
password.clear()
password.send_keys(self.password)

self.driver.find_element_by_xpath('//*[@id="continue"]').click()
time.sleep(30)
data = self.validation_data()
validation_list.append({mail: data})

return validation_list

def phone_validation(self, list_of_phone_no):


self.put_default_values()
validation_list = []
for number in list_of_phone_no:

phone_no = self.driver.find_element_by_xpath(
'//*[@id="ap_phone_number"]')
print('Send Phone number: {}'.format(number))
phone_no.clear()
phone_no.send_keys(number)

password = self.driver.find_element_by_xpath(
'//*[@id="ap_password"]')
print('Send Password: {}'.format(self.password))
password.clear()
password.send_keys(self.password)

self.driver.find_element_by_xpath('//*[@id="continue"]').click()
time.sleep(30)
data = self.validation_data()
validation_list.append({number: data})

return validation_list

def validation_data(self):
try:
alert_text_1 = self.driver.find_element_by_xpath(
'//*[@id="auth-email-invalid-email-alert"]/div/div').text
if alert_text_1 != '':
return alert_text_1
except:
pass
try:
alert_text_2 = self.driver.find_element_by_class_name(
"a-list-item").text
if alert_text_2 != '':
return alert_text_2
except:
pass
try:
self.driver.find_element_by_xpath(
'//*[@id="authportal-main-
section"]/div[2]/div/div[3]/div/div/div[1]/label'
)
self.driver.find_element_by_xpath(
'//*[@id="authportal-main-section"]/div[2]/div/div[3]/div/p[3]/a'
).click()
return 'Account creation success'
except NoSuchElementException:
pass

return ''

def put_default_values(self):

print("Putting default valid values")


username = self.driver.find_element_by_xpath(
'//*[@id="ap_customer_name"]')
print('Send Username: {}'.format(self.username))
username.clear()
username.send_keys(self.username)

email = self.driver.find_element_by_xpath('//*[@id="ap_email"]')
print('Send email: {}'.format(self.email))
email.clear()
email.send_keys(self.email)

phone_number = self.driver.find_element_by_xpath(
'//*[@id="ap_phone_number"]')
print('Send Phone number: {}'.format(self.phone_number))
phone_number.clear()
phone_number.send_keys(self.phone_number)

password = self.driver.find_element_by_xpath('//*[@id="ap_password"]')
print('Send Password: {}'.format(self.password))
password.clear()
password.send_keys(self.password)

if __name__ == "__main__":

driver_location = "C:\\Users\\I516429\\Downloads\\chrome80\\chromedriver.exe"
result_url = "https://www.amazon.in"
a = SlackFailReport(driver_location, result_url)
if (a.open_creat_account_page()):
namer = 'Test_user'
mail_list = [
'ananyalakshmi.p@gmail.com', 'tu18228@gmail.com',
'ajskahdkjhaskdhak'
]
mobile_number = ['12345', '9945842250', '12045678901234']
list_val = a.phone_validation(mobile_number)
print(list_val)
list_val1 = a.email_validation(mail_list)
print(list_val1)
else:
print('Failed to open Create account page')

OUTPUT:
About:
The website amazon.in accepts phone number with digits in between 5-14 and if the given
email id is already existing as user of amazon it doesn’t create new account and also if the email
id is invalid it doesn’t create new account.

Das könnte Ihnen auch gefallen