def check_broken_images(url):
    broken_url = "none"
    k = 0
    massege = variable_names.passed
    driver = initchrome.start()
    driver.get(url)
    a = driver.find_elements(By.TAG_NAME, 'img')
    images_count = len(a)
    for i in a:
        temp_dict = "temp_dict" + str(i)
        temp_dict = {}
        try:
            link = i.get_attribute("src")
            response = requests.get(link)
            status = response.status_code
            temp_dict[variable_names.url] = link
            temp_dict[variable_names.code] = status
            temp_dict[variable_names.status] = return_status_code(int(status))
            images_list.append(temp_dict)
            if status != 200:
                massege = variable_names.failed
                k = k + 1
                broken_url = link
        except Exception as e:
            #massege = "Failed due to Exception:" + str(e)
            print(e)

    print(massege + ":" + str(k))
    return k, massege, url, images_count, str(broken_url)
Beispiel #2
0
def openurl():
    driver = initchrome.start()
    driver.get("http://automationpractice.com/index.php")
    driver.implicitly_wait(60)
    time.sleep(30)
    action = ActionChains(driver)
    parent_level_menu = driver.find_element(
        By.XPATH, '//*[@id="homefeatured"]/li[1]/div/div[1]/div/a[1]/img')
    action.move_to_element(parent_level_menu).perform()
    driver.find_element(
        By.XPATH,
        '//*[@id="homefeatured"]/li[4]/div/div[2]/div[2]/a[1]/span').click()
    time.sleep(60)
def login_insta():
    print("This is Instagram login Module,")
    print("Please enter your email and password")
    # email=input()
    # password=input()
    email = "*****@*****.**"
    password = "******"
    driver = initchrome.start()
    driver.get("https://www.instagram.com/")
    driver.implicitly_wait(30)
    driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input').send_keys(email)
    driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input').send_keys(password)
    driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]/button/div').click()
    return driver

# driver=initdriver.start()
# driver.get("https://dev.tradishes.com/#/host/register")
# driver.find_element_by_xpath('//*[@id="email"]').send_keys("*****@*****.**")
def search_whole_page(url, word_to_search):
    driver = initchrome.start()
    url = url
    driver.get(url)
    count = 0
    # temp=driver.find_elements(By.TAG_NAME,"p").text
    # for i in temp:
    #     print(i)
    for a in driver.find_elements(By.XPATH, '*'):
        try:
            links = a.text
            # To raise flag against target word
            return_flags(links, word_to_search)
            #
            # print(links)

        except Exception as e:
            driver.quit()
            print(e)
    return int(k)
Beispiel #5
0
def startorder(email,firstname,lastname,Adress1,Adress2,City,zipcode,phone_number,cardholdername,card_number,expiry_date,numberofkeys):
    try:
        buttonflag =4
        driver = initchrome.start()
        driver.get('https://dev.kardkey.com/#/')
        driver.implicitly_wait(40)
        driver.find_element(By.XPATH, '/html/body/app-root/app-home/div/div[1]/div[1]/div/div[1]/button').click()
        buttonelement = driver.find_element(By.XPATH,
                                            '/html/body/app-root/app-product/div/div[1]/div[1]/div[3]/div/div/div/div[3]/div/div/div/span[1]')

        # clicking button iteration
        for i in range(1, buttonflag):  # one quantity is already selected and loop runs number-1 times.
            buttonelement.click()
        # clicking button iteration ends.
        driver.find_element(By.XPATH,
                            '/html/body/app-root/app-product/div/div[1]/div[1]/div[3]/div/div/div/div[4]/button[1]').click()
        driver.find_element(By.XPATH, '//*[@id="Email"]').send_keys(email)
        driver.find_element(By.XPATH, '//*[@id="firstName"]').send_keys(firstname)
        driver.find_element(By.XPATH, '//*[@id="lastName"]').send_keys(lastname)
        driver.find_element(By.XPATH, '//*[@id="address1"]').send_keys(Adress1)
        driver.find_element(By.XPATH, '//*[@id="address2"]').send_keys(Adress2)
        driver.find_element(By.XPATH, '//*[@id="city"]').send_keys(City)
        # driver.find_element(By.XPATH,'//*[@id="country"]').click()
        driver.find_element(By.XPATH, '//*[@id="country"]').send_keys("Pakistan")
        driver.find_element(By.XPATH, '//*[@id="state"]').send_keys("Punjab")
        driver.find_element(By.XPATH, '//*[@id="zipcode"]').send_keys("4600")
        driver.find_element(By.XPATH, '//*[@id="phoneNumber"]').send_keys("03084512113")
        driver.find_element(By.XPATH, '//*[@id="desktop"]/div[1]/div[4]/button').click()
        driver.find_element(By.XPATH, '//*[@id="shippingSelection"]').click()
        driver.find_element(By.XPATH, '//*[@id="desktop"]/div[1]/div[4]/button').click()
        driver.find_element(By.XPATH, '//*[@id="cardholderName"]').send_keys("Arsal")
        driver.find_element(By.XPATH, '//*[@id="cardNumber"]').send_keys("4242424242424242424242424")
        driver.find_element(By.XPATH, '//*[@id="card_exp_input"]').send_keys("02/25")
        driver.find_element(By.XPATH, '//*[@id="card_exp_cvc"]').send_keys("356")
        driver.find_element(By.XPATH, '//*[@id="card_exp_zip"]').send_keys("4600")
        temp = driver.find_element(By.XPATH, '//*[@id="desktop"]/div[1]/div[5]/div/button')
        time.sleep(5)
        temp.click()
        return driver
    except:
        return driver
Beispiel #6
0
def test_ui_return_list(url):
    # getting size
    loc = "C:\\Users\\ENSX-PC\\Desktop\\workspace\\Enabling\\data\\resolutions.xlsx"
    wb = xlrd.open_workbook(loc)
    sheet = wb.sheet_by_index(0)
    for i in range(1, sheet.nrows):
        device = sheet.cell_value(i, 0)
        width = int(sheet.cell_value(i, 1))
        height = int(sheet.cell_value(i, 2))
        driver = initchrome.start()
        url = url
        driver.get(url)

        device_data = "temp_dict" + str(i)
        device_data = {}
        device_data["device"] = device
        device_data["width"] = width
        device_data["height"] = height

        # mainlist["resolution"] = "500*500"
        # mainlist["image_base64"] = str(encoded_string)
        # sample_values["sample_Values"] = mainlist
        # sample_values = toJson(sample_values)
        driver.set_window_size(width, height)
        driver.refresh()
        driver.save_screenshot("arsal.png")
        with open("arsal.png", "rb") as image_file:
            encoded_string = base64.b64encode(image_file.read())
        temp = str(encoded_string)
        temp = convert_base64(temp)
        # file1 = open(r"C:\Users\ENSX-PC\Desktop\arsalazeem.txt", "a")
        # file1.write("*****")
        # file1.close()
        device_data["page_url"] = url
        device_data["screenshot"] = temp
        device_parent_list.append(device_data)
        driver.quit()

    return device_parent_list
def find_word_on_page(url, word_to_search):
    driver = initchrome.start()
    url = url
    driver.get(url)
    count = 0
    # temp=driver.find_elements(By.TAG_NAME,"p").text
    # for i in temp:
    #     print(i)
    for a in driver.find_elements(By.TAG_NAME, 'p'):
        try:
            links = a.text
            # To raise flag against target word
            return_flags(links, word_to_search)
            #
            # print(links)

        except Exception as e:
            driver.quit()
            print(e)
    # text = driver.find_element_by_xpath('//*[@id="privacy_div"]/div/div/div/div[1]/div/div/div/div/div[2]/p[1]').text
    # print(text)
    driver.quit()
    print("Total occurances ", str(k))
    return int(k)
def checkk_loading_Time(project_name, description, url):
    driver = initchrome.start()
    time.sleep(7)
    intial_seconds = int(datetime.datetime.now().strftime("%S"))
    intial_minutes = int(datetime.datetime.now().strftime("%M"))
    driver.get(url)
    final_seconds = abs(int(datetime.datetime.now().strftime("%S")))
    final_minutes = int(datetime.datetime.now().strftime("%M"))
    total_time = str(final_minutes - intial_minutes) + " Minute" + " " + str(
        (final_seconds - intial_seconds)) + " " + "Seconds"
    print(total_time)
    response = requests.get(url)
    statuscode = str(response.status_code)
    if statuscode == "200":
        messege = "Site is Up"
        print(messege)
    print(statuscode)

    # this is the main list
    mainlist = {}
    jsonlist = []
    temp = {}
    temp["loading_time"] = total_time
    temp[project_name + "_site_status"] = messege
    jsonlist.append(temp)
    jsonlist = json.dumps(toJson(jsonlist))
    mainlist["Id"] = "0"
    mainlist["Test"] = "loading_time_and_website_Status"
    mainlist["Project"] = project_name
    mainlist["Description"] = description
    mainlist["MetaData"] = jsonlist
    mainlist["DateAdded"] = str(date.today())
    mainlist["DateUpdated"] = str(date.today())
    mainlist["ProjectName"] = project_name
    newdatalist = mainlist
    print(newdatalist)
Beispiel #9
0
import initchrome

driver = initchrome.start()
driver.get("https://dev.kardkey.com/#/")
driver.implicitly_wait(30)
driver.find_element_by_xpath(
    '/html/body/app-root/app-home/div/div[1]/div[1]/div/div[1]/button').click(
    )
driver.find_element_by_xpath(
    '/html/body/app-root/app-product/div/div[1]/div[1]/div[3]/div/div/div/div[4]/button[2]/span[1]'
).click()
driver.find_element_by_xpath('//*[@id="cart"]').click()
temp = driver.find_element_by_xpath(
    '//*[@id="desktop"]/div[2]/div[3]/div/div[2]/div/input').get_attribute(
        "value")
temp = driver.find_element_by_xpath(
    '//*[@id="desktop"]/div[2]/div[7]/div[2]/h4').get_attribute("value")
print(temp)
def _check_broken_links(page_url):
    total = 0
    fail = 0
    # jsonlist["page_url"]=page_url
    t_time = datetime.datetime.now().strftime("%H:%M:%S")
    # jsonlist["current_time"]=t_time
    print("i am here")
    driver = initchrome.start()
    print(page_url)
    driver.get(page_url)
    driver.implicitly_wait(30)
    # links=driver.find_elements_by_css_selector("a")
    # elem = driver.find_elements_by_xpath("//*[@href]")
    # print(elem)
    # # for link in links:
    # #     r = requests.head("https://dev.tradishes.com/home.html")
    # #     print(r)
    for a in driver.find_elements_by_xpath('.//a'):
        total = total + 1
        # temp_dict="temp_dict"+str(n)
        try:
            links = a.get_attribute('href')

            if check_duplicates(links):
                return 0, 0
            if _checklast(links):
                links = links[:-1]
                print("I have trimmed:", links)
            _append_check_advanced(links)
            record_list.append(links)
            r = requests.head(links)
            s_code = int(r.status_code)
            # if r!='<Response [404]> ':
            #     status="passed"
            # else:
            #     status=" broken"
            # if "twitter" in links:
            #     print(links)
            #     print("Do nothing with jsonlist")
            # if "instagram" in links:
            #     print(links)
            #     print("Do nothing with jsonlist")
            # else:
            temp_dict = _get_random_string(8)
            temp_dict = {}
            temp_dict[variable_names.url] = links
            temp_dict[variable_names.code] = s_code
            temp_dict[variable_names.status] = _return_status_code(s_code)
            datalist.append(temp_dict)
            # jsonlist[links + " " + "status"] = r.ok
            # print(links + ' ' + str(r.ok))
            if str(r.ok) == "False":
                # print(k)
                fail = fail + 1
        except Exception as e:
            print("This a tag contains no URL", e)

    # if k>0:
    #     result=variable_names.failed
    # else:
    #     result= variable_names.passed

    driver.quit()
    return total, fail