<gh_stars>0
"""
The Office 365 Social Engineering Email draft producer uses a customized
library of methods in this master class to maintain continuous delivery.
This repository is controlled by a single boolean that is set to false by
default. Please ensure that the emailDraft.py file is correct.
"""

# Built-in Imports
import os

# SeleniumBase Web Application Testing Framework
from seleniumbase import BaseCase

# Selenium Exception Imports
from selenium.common.exceptions import NoSuchElementException

# Logging Import Setup
import logging
filename = '/SeleniumBase/production/tests/O365SEEmailLog/test.log'
format = '%(asctime)s %(levelname)s: %(message)s'

# Logging file setup
logging.basicConfig(filename=filename, format=format,
                    encoding='utf-8', level=logging.INFO)


class BaseTestCase(BaseCase):
    def setUp(self):
        super(BaseTestCase, self).setUp()
        # <<< Run custom setUp() code for tests AFTER the super().setUp() >>>

    def tearDown(self):
        self.save_teardown_screenshot()
        if self.has_exception():
            # <<< Run custom code if the test failed. >>>
            pass
        else:
            # <<< Run custom code if the test passed. >>>
            pass
        # (Wrap unreliable tearDown() code in a try/except block.)
        # <<< Run custom tearDown() code BEFORE the super().tearDown() >>>
        super(BaseTestCase, self).tearDown()

    def clickCSSObject(self, CSSSelector):
        if self.is_element_present(CSSSelector):
            try:
                self.click(CSSSelector)
                print('CSS Object found: {0}'.format(CSSSelector))
            except NoSuchElementException as exc:
                print(exc)
                print('CSS Object not found: {0}'.format(CSSSelector))
        else:
            print('CSS Object not found: {0}'.format(CSSSelector))
            source = self.get_page_source()
            logging.warning(source)

    def createEmail(self, email):
        toInput = 'input[aria-label="To"]'
        ccInput = 'input[aria-label="Cc"]'
        cc = os.getenv('O365_SE_TO', '')
        subjectInput = 'input[aria-label="Add a subject"]'
        subject = os.getenv('O365_SE_SUBJECT', '')
        messageInput = 'input[aria-label="Message body"]'
        message = os.getenv('O365_SE_MESSAGE', '')
        moreOptions = '#compose_ellipses_menu'
        importance = 'button[aria-label="Set importance"]'
        highImportance = 'button[name="High"]'
        clickChain1 = [moreOptions, importance, highImportance]
        showMessageOptions = 'button[aria-label="Show message options..."]'
        self.type(toInput, email)
        self.type(ccInput, cc)
        self.type(subjectInput, subject)
        self.type(messageInput, message)
        self.click_chain(clickChain1, spacing=0.1)
        self.clickCSSObject(showMessageOptions)

    def createEmails(self):
        # <<< Load welcome page markdown. >>>
        # Reduce duplicate code in tests by having reusable methods like this.
        # If the UI changes, the fix can be applied in one place.
        self.open('https://office.com/')
        loginBtn = 'div[class="mectrl_header_text mectrl_truncate"]'
        usernameInput = '#i0116'
        username = os.getenv('O365_SE_USERNAME', 'testUser')
        nextBtn = '#idSIButton9'
        passwordInput = <PASSWORD>'
        password = os.getenv('O365_SE_PASSWORD', '<PASSWORD>')
        doNotRetainCreds = '#idBtn_Back'
#         outlook1 = 'a[aria-label="Outlook"]'
        outlook = 'a[id="ShellMail_link"]'
#         outlook3 = '#20AC5DE0-9796-4393-8656-9711B92C5223'
        newMessage1 = '#id__6'
#         newMessage2 = '#id__1718'
        self.clickCSSObject(loginBtn)
        self.clickCSSObject(usernameInput)
        self.type(usernameInput, username)
        self.clickCSSObject(nextBtn)
        self.type(passwordInput, password)
        self.clickCSSObject(nextBtn)
        self.clickCSSObject(doNotRetainCreds)
#         self.clickCSSObject(outlook1)
        self.wait_for_element(outlook)
        self.clickCSSObject(outlook)
#         self.clickCSSObject(outlook3)
        self.wait_for_element(newMessage1)
        self.clickCSSObject(newMessage1)
#         self.clickCSSObject(newMessage2)
        stringList = os.getenv('O365_SE_EMAILS', '')
        emailList = stringList.split()
        for email in emailList:
            self.createEmail(email)

"""
The Office 365 Social Engineering Email draft producer uses a customized
library of methods in this master class to maintain continuous delivery.
This repository is controlled by a single boolean that is set to false by
default. Please ensure that the emailDraft.py file is correct.
"""

# Built-in Imports
import os

# SeleniumBase Web Application Testing Framework
from seleniumbase import BaseCase

# Selenium Exception Imports
from selenium.common.exceptions import NoSuchElementException

# Logging Import Setup
import logging
filename = '/SeleniumBase/production/tests/O365SEEmailLog/test.log'
format = '%(asctime)s %(levelname)s: %(message)s'

# Logging file setup
logging.basicConfig(filename=filename, format=format,
                    encoding='utf-8', level=logging.INFO)


class BaseTestCase(BaseCase):
    def setUp(self):
        super(BaseTestCase, self).setUp()
        # <<< Run custom setUp() code for tests AFTER the super().setUp() >>>

    def tearDown(self):
        self.save_teardown_screenshot()
        if self.has_exception():
            # <<< Run custom code if the test failed. >>>
            pass
        else:
            # <<< Run custom code if the test passed. >>>
            pass
        # (Wrap unreliable tearDown() code in a try/except block.)
        # <<< Run custom tearDown() code BEFORE the super().tearDown() >>>
        super(BaseTestCase, self).tearDown()

    def clickCSSObject(self, CSSSelector):
        if self.is_element_present(CSSSelector):
            try:
                self.click(CSSSelector)
                print('CSS Object found: {0}'.format(CSSSelector))
            except NoSuchElementException as exc:
                print(exc)
                print('CSS Object not found: {0}'.format(CSSSelector))
        else:
            print('CSS Object not found: {0}'.format(CSSSelector))
            source = self.get_page_source()
            logging.warning(source)

    def createEmail(self, email):
        toInput = 'input[aria-label="To"]'
        ccInput = 'input[aria-label="Cc"]'
        cc = os.getenv('O365_SE_TO', '')
        subjectInput = 'input[aria-label="Add a subject"]'
        subject = os.getenv('O365_SE_SUBJECT', '')
        messageInput = 'input[aria-label="Message body"]'
        message = os.getenv('O365_SE_MESSAGE', '')
        moreOptions = '#compose_ellipses_menu'
        importance = 'button[aria-label="Set importance"]'
        highImportance = 'button[name="High"]'
        clickChain1 = [moreOptions, importance, highImportance]
        showMessageOptions = 'button[aria-label="Show message options..."]'
        self.type(toInput, email)
        self.type(ccInput, cc)
        self.type(subjectInput, subject)
        self.type(messageInput, message)
        self.click_chain(clickChain1, spacing=0.1)
        self.clickCSSObject(showMessageOptions)

    def createEmails(self):
        # <<< Load welcome page markdown. >>>
        # Reduce duplicate code in tests by having reusable methods like this.
        # If the UI changes, the fix can be applied in one place.
        self.open('https://office.com/')
        loginBtn = 'div[class="mectrl_header_text mectrl_truncate"]'
        usernameInput = '#i0116'
        username = os.getenv('O365_SE_USERNAME', 'testUser')
        nextBtn = '#idSIButton9'
        passwordInput = <PASSWORD>'
        password = os.getenv('O365_SE_PASSWORD', '<PASSWORD>')
        doNotRetainCreds = '#idBtn_Back'
#         outlook1 = 'a[aria-label="Outlook"]'
        outlook = 'a[id="ShellMail_link"]'
#         outlook3 = '#20AC5DE0-9796-4393-8656-9711B92C5223'
        newMessage1 = '#id__6'
#         newMessage2 = '#id__1718'
        self.clickCSSObject(loginBtn)
        self.clickCSSObject(usernameInput)
        self.type(usernameInput, username)
        self.clickCSSObject(nextBtn)
        self.type(passwordInput, password)
        self.clickCSSObject(nextBtn)
        self.clickCSSObject(doNotRetainCreds)
#         self.clickCSSObject(outlook1)
        self.wait_for_element(outlook)
        self.clickCSSObject(outlook)
#         self.clickCSSObject(outlook3)
        self.wait_for_element(newMessage1)
        self.clickCSSObject(newMessage1)
#         self.clickCSSObject(newMessage2)
        stringList = os.getenv('O365_SE_EMAILS', '')
        emailList = stringList.split()
        for email in emailList:
            self.createEmail(email)
The Office 365 Social Engineering Email draft producer uses a customized library of methods in this master class to maintain continuous delivery. This repository is controlled by a single boolean that is set to false by default. Please ensure that the emailDraft.py file is correct. # Built-in Imports # SeleniumBase Web Application Testing Framework # Selenium Exception Imports # Logging Import Setup # Logging file setup # <<< Run custom setUp() code for tests AFTER the super().setUp() >>> # <<< Run custom code if the test failed. >>> # <<< Run custom code if the test passed. >>> # (Wrap unreliable tearDown() code in a try/except block.) # <<< Run custom tearDown() code BEFORE the super().tearDown() >>> # <<< Load welcome page markdown. >>> # Reduce duplicate code in tests by having reusable methods like this. # If the UI changes, the fix can be applied in one place. #         outlook1 = 'a[aria-label="Outlook"]' #         outlook3 = '#20AC5DE0-9796-4393-8656-9711B92C5223' #         newMessage2 = '#id__1718' #         self.clickCSSObject(outlook1) #         self.clickCSSObject(outlook3) #         self.clickCSSObject(newMessage2)