Esempio n. 1
0
def validateLightningForm(field, expectedValue):
    # Find the field label
    for i in range(30):
        element = findElementByClassNameAndAttribute('test-id__field-label',
                                                     'innerText', field)
        if element is not False:
            break
        else:
            time.sleep(1)
    # Move up to the parent element
    parent = element.find_element_by_xpath('parent::*')
    parent = parent.find_element_by_xpath('parent::*')
    # Search for the different child types
    childTypes = ['uiOutputText', 'uiOutputCheckbox', 'test-id__field-value']
    for childType in childTypes:
        child = findChildByClassName(parent, childType)
        if child is not False:
            break
    if childType == 'uiOutputCheckbox':
        if 'alt="True"' in child.get_attribute('innerHTML'):
            actualValue = 'true'
        else:
            actualValue = 'false'
    else:
        actualValue = child.get_attribute('innerText')
    if expectedValue == actualValue:
        result = 'Pass'
    else:
        result = 'Fail'
        pars.testResult = 'Fail'
    utils.log('    Field: ' + field + ' | Expected: ' + expectedValue +
              ' | Actual: ' + actualValue + ' | Result: ' + result)
    utils.results('"' + field + '","' + expectedValue + '","' + actualValue +
                  '","' + result + '"')
Esempio n. 2
0
def fillLightningForm(field, value):
    try:
        # Find the label for the field
        elements = driver.find_elements_by_class_name('label')
        for element in elements:
            if element.get_attribute('innerText') == field or \
               element.get_attribute('innerText') == (field + '*') or \
               element.get_attribute('innerText') == (field + '\n*'):
                break
        # If the label has an htmlFor attribute that is the elementId for the input field
        elementId = getElementAttribute(element, 'htmlFor')
        if (elementId is not False) and (elementId is not None):
            element = findElementById(elementId)
            # Determine the type of input field this is
            inputType = element.get_attribute('type')
            # Take the appropriate action based on type
            if inputType == 'text' or \
               inputType == 'tel' or \
               inputType == 'url':
                result = sendKeysElement(element, value)
                utils.log('    ' + field + ' = ' + value)
                return True
            elif inputType == 'checkbox':
                # Determine the status of the checkbox
                checked = element.get_attribute('checked')
                # If the status doesn't match, click the checkbox
                if checked != value:
                    element.click()
                    result = sendKeysElement(element, value)
                    utils.log('    ' + field + ' = ' + value)
            else:
                utils.log('Could not identify type of input field ' +
                          inputType)
        # If there is no htmlFor attribute, this is a select box so we need to find the child field
        else:
            parent = element.find_element_by_xpath('parent::*')
            child = parent.find_element_by_class_name('select')
            child.click()
            for i in range(3):
                result = clickByLinkText(value)
                if result is True:
                    utils.log('    ' + field + ' = ' + value)
                    break
                else:
                    time.sleep(1)
        # Return result
        if result is True:
            return True
        else:
            return False
    except Exception:
        return False
Esempio n. 3
0
def login():
    utils.log('Logging in...')
    sel.initialize()
    sel.getUrl(env.login['url'])
    sel.sendKeysById('username', env.login['user'])
    sel.sendKeysById('password', env.login['pass'])
    sel.clickById('Login')
    result = False
    for i in range(10):
        if sel.getTitle() == 'Login | Salesforce' or \
           sel.getTitle() == 'Verify Your Identity | Salesforce' or \
           sel.getTitle() == 'Problem Verifying Your Identity | Salesforce':
            result = False
            break
        elif sel.getTitle() == 'Home | Salesforce':
            time.sleep(1)
            result = True
        elif ' - Console' in sel.getTitle():
            result = True
        elif ' | Salesforce' in sel.getTitle():
            result = True
        else:
            time.sleep(1)
    if result is False:
        utils.log('Login failed\n')
        exit()
    elif result is True:
        utils.log('Logged in\n')
Esempio n. 4
0
def logout():
    utils.log('Logging out...')
    sel.getUrl(env.login['url'])
    # Wait for Home page to load
    for i in range(30):
        if sel.getTitle() == 'Home | Salesforce':
            time.sleep(1)
            break
        else:
            time.sleep(1)
    # Click View profile icon
    for i in range(30):
        result = sel.clickByClassNameAndAttribute(
            'branding-userProfile-button', 'innerText', 'View profile')
        if result is True:
            time.sleep(1)
            break
        else:
            time.sleep(1)
    # Click Log Out link
    for i in range(30):
        result = sel.clickByLinkText('Log Out')
        if result is True:
            break
        else:
            time.sleep(30)
    # Wait for Login page to load
    for i in range(30):
        if sel.getTitle() == 'Login | Salesforce':
            result = True
            break
        else:
            time.sleep(1)
    # Log result, close browser and return
    if result is True:
        sel.quit()
        utils.log('Logged out\n')
        return True
    else:
        utils.log('Logout failed')
        return False
Esempio n. 5
0
def create(parameters):
    utils.log('Creating Account...')
    # Open the Accounts page
    sel.getUrl(env.login['url'] + '/lightning/o/Account/home')
    # Click on the New Button
    for i in range(10):
        result = sel.clickByClassNameAndAttribute('forceActionLink', 'text', 'New')
        if result is True:
            break
        else:
            time.sleep(1)
    # Wait for the New Account form to load
    for i in range(3):
        result = sel.findElementByClassNameAndAttribute(
            'test-id__section-header-title', 'innerHTML', 'Account Information')
        if result is True:
            break
        else:
            time.sleep(1)
    # Send account parameters to form
    for field in pars.account[parameters['accountType']]:
        result = sel.fillLightningForm(field, pars.account[parameters['accountType']][field])
        if result is False:
            utils.log('Could not fill field: ' + field + ' with value: ' +
                      pars.account[parameters['accountType']][field])
    # Click Save
    result = sel.clickByClassNameAndAttribute('forceActionButton', 'innerText', 'Save')
    # Wait until the page loads, extract the account ID from the URL and return it
    for i in range(10):
        url = sel.getCurrentUrl()
        if '/view' in url:
            break
        else:
            time.sleep(1)
    accountId = url.split('/')[-2]
    utils.log('Created Account: ' + accountId + '\n')
    pars.account[parameters['accountHandle']] = accountId
    return True
Esempio n. 6
0
def validate(parameters):
    utils.log('Validating Account ' + pars.account[parameters['accountHandle']] + ' ...')
    # Start logging results
    utils.results('Validate Account:,' + pars.account[parameters['accountHandle']])
    utils.results('Field,Expected,Actual,Result')
    # Navigate to the Account page
    sel.getUrl(env.login['url'] + '/' + pars.account[parameters['accountHandle']])
    # Click the Details tab
    for i in range(30):
        result = sel.clickByLinkText('Details')
        if result is True:
            break
        else:
            time.sleep(1)
    # Initialize the test result, validate account parameters and log result
    pars.testResult = 'Pass'
    skipList = ['accountHandle']
    for field in parameters:
        if field not in skipList:
            result = sel.validateLightningForm(field, parameters[field])
    utils.results('Result:,' + pars.testResult + '\n')
    utils.log('    Result: ' + pars.testResult)
    utils.log('Account ' + pars.account[parameters['accountHandle']] + ' validated\n')
Esempio n. 7
0
def delete(parameters):
    utils.log('Deleting Account...')
    sel.getUrl(env.login['url'] + '/' + pars.account[parameters['accountHandle']])
    # Click the Show more actions icon
    for i in range(10):
        result = sel.clickByClassNameAndAttribute('slds-icon-utility-down', 'innerText', 'Show more actions')
        if result is True:
            break
        else:
            time.sleep(1)
    if result is False:
        utils.log('Could not click Show more Actions icon')
    # Click the Delete option
    for i in range(3):
        result = sel.clickByLinkText('Delete')
        if result is True:
            break
        else:
            time.sleep(1)
    if result is False:
        utils.log('Could not click Delete option')
    # Click the Delete button
    for i in range(10):
        result = sel.clickByClassNameAndAttribute('forceActionButton', 'innerText', 'Delete')
        if result is True:
            break
        else:
            time.sleep(1)
    if result is True:
        utils.log('Deleted Account: ' + pars.account[parameters['accountHandle']] + '\n')
        return True
    else:
        utils.log('Could not click Delete button')
        utils.log('Could not delete Account: ' + pars.account[parameters['accountHandle']] + '\n')
        return False