How to use disable_test method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

executeTests.py

Source:executeTests.py Github

copy

Full Screen

1#! /usr/bin/env python23from __future__ import print_function4from __future__ import unicode_literals5from __future__ import absolute_import6from __future__ import division78import json9import platform10import subprocess11import os12import argparse13import glob14import logging15import re16import errno17import shutil18import datetime1920def mkdir_p(path):21 """Equivalent for unix command mkdir -p"""22 try:23 os.makedirs(path)24 except OSError as exc:25 if exc.errno == errno.EEXIST and os.path.isdir(path):26 pass27 else:28 raise293031class TestExecutor:32 def __init__(self):33 logging.basicConfig(level=logging.DEBUG)34 if platform.system() == "Windows":35 self.TMPDIR = 'c:\\tmp\\'36 else:37 self.TMPDIR = '/tmp'3839 parser = argparse.ArgumentParser()40 parser.add_argument("-v", "--version",41 help="test against Thunderbird version",42 default=None,43 required=False)44 parser.add_argument("-d", "--downloadonly",45 help="only download files",46 default=False,47 action="store_true",48 required=False)49 parser.add_argument("-n", "--nodownload",50 help="skip downloading files",51 default=False,52 action="store_true",53 required=False)54 parser.add_argument("-s", "--skip_install",55 help="skip installing files",56 default=False,57 action="store_true",58 required=False)59 self.args = parser.parse_args()6061 logging.debug("command line args: %r" % self.args)6263 xpiversion = json.load(open("../manifest.json"))["version"]64 self.xpi = os.path.abspath(os.path.join(65 "..", "AMO", "CompactHeader-" + xpiversion + ".xpi"66 ))6768 logging.info("CH version: %r" % xpiversion)69 logging.info("CH file: %r" % self.xpi)7071 self.ftpdir = os.path.abspath(os.path.join(72 self.TMPDIR,73 "compactheader", "ftp"))7475 jsonfilename = 'testapps.json'7677 self.test_apps = json.load(open(jsonfilename))7879 self.machine = platform.system() + platform.machine()80 logging.info("Running on %s\n\n" % self.machine)8182 self.package_tools = {83 "WindowsAMD64": {84 "unpack": "../mozmill-virtualenv/Scripts/mozinstall",85 "unpack_args": "--app=thunderbird",86 "unpack_target_args": "--destination",87 "virtualpython": "..\\mozmill-virtualenv\\Scripts\\python"88 },89 "Linuxx86_64": {90 "unpack": "../mozmill-virtualenv/bin/mozinstall",91 "unpack_args": "--app=thunderbird",92 "unpack_target_args": "--destination",93 "virtualpython": "../mozmill-virtualenv/bin/python"94 },95 "Darwinx86_64": {96 "unpack": "../mozmill-virtualenv/bin/mozinstall",97 "unpack_args": "--app=thunderbird",98 "unpack_target_args": "--destination",99 "virtualpython": "../mozmill-virtualenv/bin/python"100 },101 }102103 def download_test(self):104 script_dir = os.path.abspath(os.path.dirname(__file__))105 logging.debug("script dir: %s" % script_dir)106107 self.dispMUA = (108 "https://addons.mozilla.org/thunderbird/downloads/" +109 "latest/display-mail-user-agent/platform:5/addon-562-latest.xpi")110 self.mnenhy = ("https://addons.mozilla.org/thunderbird/downloads" +111 "/latest/2516/addon-2516-latest.xpi")112113 subprocess.call(["wget", "--no-check-certificate", "-q", "-P",114 self.ftpdir, "-N", self.dispMUA])115 subprocess.call(["wget", "--no-check-certificate", "-q", "-P",116 self.ftpdir, "-N", self.mnenhy])117118 test_specs = {}119 for appversion in self.test_apps:120 if self.args.version and appversion != self.args.version:121 continue122 if self.machine in self.test_apps[appversion]:123 appref = self.test_apps[appversion][self.machine]124125 hosttype = self.machine126 ftppath = appref['url']127 app = appref['appzip']128 tests = appref['testzip']129 checksum = appref['checksum']130131 # Download checksums file to determine version of Thunderbird,132 # because we use a link to latest release/beta/earlybird/trunk133 # build and do not know the version!134 # wget -r -l1 --no-parent --follow-ftp -A .checksums '' -nd135136 files = glob.glob(self.ftpdir + "/thunderbird*" + checksum)137 for f in files:138 os.remove(f)139140 logging.info("look for available Thunderbird versions:\n\n")141 get_checksum = [142 "wget", "-r", "-l1", "--no-check-certificate",143 "--no-parent", "--follow-ftp", "-A" + checksum,144 ftppath + "/", "-nd", "-P", self.ftpdir145 ]146 logging.debug("Download command: %r", " ".join(get_checksum))147 subprocess.call(get_checksum)148 get_checksum = [149 "wget", "--no-check-certificate",150 ftppath + "/" + checksum, "-P", self.ftpdir151 ]152 logging.debug("Download command: %r", " ".join(get_checksum))153 subprocess.call(get_checksum)154 files = glob.glob(self.ftpdir + "/thunderbird*" + checksum)155 if len(files) > 0:156 logging.debug("found checksums: %r" % files)157158 file = files[-1]159160 version = ""161 m = re.search("thunderbird-(.*)" + checksum, file)162 if m:163 version = m.group(1)164165 logging.info("************")166 logging.info("found version: %s " % version)167 logging.info("************")168 #169 app = re.sub(r'_VER_', version, app)170 tests = re.sub(r'_VER_', version, tests)171172 logging.debug("app: %s" % app)173 logging.debug("tests: %s" % tests)174 logging.debug("hosttype: %s" % hosttype)175 logging.debug("ftppath: %s" % ftppath)176 else:177 files = glob.glob(self.ftpdir + "/" + checksum)178 if len(files) > 0:179 logging.debug("found checksums: %r" % files)180181 version = '99' + appversion182183 logging.info("************")184 logging.info("found version: %s " % version)185 logging.info("************")186 #187 app = re.sub(r'_VER_', version, app)188 tests = re.sub(r'_VER_', version, tests)189190 logging.debug("app: %s" % app)191 logging.debug("tests: %s" % tests)192 logging.debug("hosttype: %s" % hosttype)193 logging.debug("ftppath: %s" % ftppath)194195 testdir = os.path.join(196 self.TMPDIR,197 "compactheader",198 "test-" + version,199 "testing")200201 logging.debug("create test and ftpdir")202 mkdir_p(testdir)203 mkdir_p(self.ftpdir)204205 logging.debug("download path: %s/%s-%s" %206 (self.ftpdir, hosttype, version))207 logging.debug("Thunderbird download path: %s/%s" %208 (ftppath, app))209 logging.debug(210 "Tests download path: %s/%s" %211 (ftppath, tests))212213 tools = self.package_tools[hosttype]214215 if (not self.args.nodownload):216 subprocess.call(217 ["wget", "--no-check-certificate", "-q", "-P",218 os.path.join(self.ftpdir, hosttype + "-" + version),219 "-N", ftppath + "/" + app220 ]221 )222 subprocess.call(223 ["wget", "--no-check-certificate", "-q", "-P",224 os.path.join(self.ftpdir, hosttype + "-" + version),225 "-N", ftppath + "/" + tests226 ]227 )228229 testdir = os.path.abspath(os.path.join(230 self.TMPDIR,231 "compactheader",232 "test-" + version,233 "testing"))234235 cur_dir = os.curdir236237 os.chdir(testdir)238 logging.debug("unzipping tests...")239 if not self.args.skip_install:240 if '.tar.gz'in tests:241 unzip_test_cmd = [242 "tar", "xzf",243 os.path.join(244 self.ftpdir, hosttype + "-" + version, tests),245 "--exclude", "*mochitest*",246 "--exclude", "*xpcshell*",247 "--exclude", "*reftest*",248 "--exclude", "*jit-test*",249 "--exclude", "*bin*"250 ]251 if (platform.system() == 'Windows'252 and "APPVEYOR" in os.environ):253 unzip_test_cmd.append("--force-local")254 else:255 unzip_test_cmd = [256 "unzip", "-q", "-o",257 os.path.join(258 self.ftpdir, hosttype + "-" + version, tests),259 "-d", testdir, "-x", "*mochitest*",260 "*xpcshell*", "*reftest*", "*jit-test*", "*bin*"261 ]262 logging.debug("unzip tests: %r" % " ".join(unzip_test_cmd))263 subprocess.call(unzip_test_cmd)264265 os.chdir(cur_dir)266 # "Link" the add-on tests into the mozmill directory267 if platform.system() == "Windows":268 subprocess.call(269 ["junction", "-d",270 os.path.join(testdir, "mozmill", "compactheader")271 ]272 )273 subprocess.call(274 ["junction",275 os.path.join(testdir, "mozmill", "compactheader"),276 os.path.join(script_dir, "compactheader")277 ]278 )279 subprocess.call(280 ["junction", "-d",281 os.path.join(testdir, "..", "python")282 ]283 )284 subprocess.call(285 ["junction",286 os.path.join(testdir, "..", "python"),287 os.path.join(testdir, "tools"),288 ]289 )290 else:291 subprocess.call(292 ["ln", "-sfn",293 os.path.join(script_dir, "compactheader"),294 os.path.join(testdir, "mozmill", "compactheader"),295 ]296 )297 mkdir_p(os.path.join(testdir, "..", "python"))298 shutil.rmtree(299 os.path.join(testdir, "..", "python", "mozterm"),300 ignore_errors=True301 )302 shutil.copytree(303 os.path.join(testdir, "tools", "mozterm"),304 os.path.join(testdir, "..", "python", "mozterm")305 )306307 shutil.copy(308 os.path.join(script_dir, "buildconfig.py"),309 os.path.join(testdir, "mozmill", "resources"))310311 os.chdir(os.path.join(testdir, "mozmill"))312313 if not self.args.skip_install:314 shutil.rmtree(os.path.join("..", "mozmill-virtualenv"),315 ignore_errors=True)316 if True: # not os.path.isdir(317 # os.path.join("resources", "virtualenv")):318 logging.info("... installing virutalenv")319 install_cmd = [320 "pip",321 "install",322 "virtualenv"323 ]324 logging.debug(" ".join(install_cmd))325 subprocess.call(install_cmd)326 install_cmd = [327 "virtualenv",328 os.path.join("..", "mozmill-virtualenv")329 ]330 logging.debug(" ".join(install_cmd))331 subprocess.call(install_cmd)332 logging.info("... installing mozmill")333334 int_version = int(re.findall('^\d+', str(version))[0])335 logging.debug("int version: %d" % int_version)336337 if int_version >= 59:338 install_cmd = [339 "pip",340 "wheel",341 os.path.join(testdir, "..", "python", "mozterm"),342 "--wheel-dir",343 "/tmp/compactheader"344 ]345 logging.debug(" ".join(install_cmd))346 subprocess.call(install_cmd)347 install_cmd = [348 "python",349 os.path.join("resources", "installmozmill.py"),350 os.path.join("..", "mozmill-virtualenv")]351 else:352 # shutil.rmtree(os.path.join("..", "mozbase"),353 # ignore_errors=True)354 install_cmd = [355 "python",356 os.path.join("resources", "installmozmill.py"),357 os.path.join("..", "mozmill-virtualenv"),358 os.path.join("..", "mozbase")]359360 logging.debug(" ".join(install_cmd))361 subprocess.call(install_cmd)362363 install_cmd = [364 tools['virtualpython'],365 "-mpip",366 "install",367 os.path.join("..", "mozbase", "mozinstall")]368369 logging.debug(" ".join(install_cmd))370 subprocess.call(install_cmd)371372 os.chdir(os.path.join(testdir, "mozmill"))373374 logging.debug("unzipping Thunderbird...")375 install_cmd = [376 tools["unpack"],377 tools["unpack_args"],378 os.path.join(self.ftpdir, hosttype + "-" + version,379 app),380 tools["unpack_target_args"],381 testdir382 ]383384 logging.debug(" ".join(install_cmd))385 try:386 appbin = subprocess.check_output(install_cmd)387 except subprocess.CalledProcessError as e:388 logging.error("cannot install thunderbird %" %389 e.output)390 else:391 appbin = (392 'c:\\tmp\\compactheader\\test-' + version +393 '\\testing\\thunderbird\\thunderbird.exe'394 )395396 # copy drag'n'drop helpers to shared-modules until397 # they are added to thunderbird source398 os.chdir(os.path.join(script_dir, "shared-modules"))399 shared_files = glob.glob("*")400 logging.debug("shared files: %r" % shared_files)401 for file in shared_files:402 target_dir_name = os.path.join(403 testdir, "mozmill", "shared-modules")404 target_file_name = os.path.join(target_dir_name, file)405 logging.debug("copy file: %s -> %s" %406 (file, target_file_name))407 if os.path.exists(target_file_name):408 os.remove(target_file_name)409410 shutil.copyfile(file, target_file_name)411412 test_specs[appversion] = {413 "version": version,414 "appbin": appbin.rstrip('\r\n'),415 "tests": tests,416 "hosttype": hosttype417 }418419 logging.info("download/unzip finished\n\n")420 return test_specs421422 def execute_test(self, test_spec, out_dir):423 version = test_spec['version']424 appbin = test_spec['appbin']425 tests = test_spec['tests']426 hosttype = test_spec['hosttype']427 tools = self.package_tools[hosttype]428429 logging.info("Execute tests for: %s\t%s\t%s\t%s\n\n" %430 (hosttype, version, appbin, tests))431#432 testdir = os.path.abspath(os.path.join(433 self.TMPDIR,434 "compactheader",435 "test-" + version,436 "testing"))437438 os.chdir(os.path.join(testdir, "mozmill"))439440 python = tools["virtualpython"]441442 # display mail user agent for AMO#443 dispMUAfiles = glob.glob("../../../ftp/display_*")444 if len(dispMUAfiles) > 0:445 dispMUAfile1 = os.path.abspath(dispMUAfiles[-1])446 else:447 dispMUAfile1 = ""448449 dispMUAfiles = glob.glob("../../../ftp/addon-562*.xpi")450 if len(dispMUAfiles) > 0:451 dispMUAfile2 = os.path.abspath(dispMUAfiles[-1])452 else:453 dispMUAfile2 = ""454455 # We have out own tests for this, so delete it456 try:457 os.remove("message-header/test-header-toolbar.js")458 except OSError:459 pass460461 # disable test, because the default is now icons only, so this test462 # does not work anymore463 sed_cmd = [464 "sed", "-i", "-e",465 's/function test_toolbar_collapse_and_expand/' +466 'function notest_toolbar_collapse_and_expand/',467 os.path.join(468 testdir, "mozmill", "message-header", "test-message-header.js")469 ]470 logging.debug("sed: %r" % " " . join(sed_cmd))471 subprocess.call(sed_cmd)472473 if platform.system() == 'Darwin' and "TRAVIS" in os.environ:474 # some tests do not work - for whatever reasons - on OSX475 osx_disalbe_tests = [476 'test_button_visibility',477 'test_customize_header_toolbar_reorder_buttons',478 'test_customize_header_toolbar_remove_buttons',479 'test_customize_header_toolbar_add_all_buttons',480 ]481482 for disable_test in osx_disalbe_tests:483 sed_cmd = [484 "sed", "-i", "-e",485 's/function ' + disable_test + '/' +486 'function no' + disable_test + '/',487 os.path.join(488 testdir, "mozmill", "compactheader",489 "test-compactheader-toolbar.js")490 ]491 logging.debug("sed: %r" % " ".join(sed_cmd))492 subprocess.call(sed_cmd)493 sed_cmd = [494 "sed", "-i", "-e",495 's/function test_a11y_attrs/' +496 'function notest_a11y_attrs/',497 os.path.join(498 testdir, "mozmill", "message-header",499 "test-message-header.js")500 ]501 logging.debug("sed: %r" % " ".join(sed_cmd))502 subprocess.call(sed_cmd)503504 sed_cmd = [505 "sed", "-i", "-e",506 's/function test_ignore_phishing_warning_from_eml_attachment/' +507 'function notest_ignore_phishing_warning_from_eml_attachment/',508 os.path.join(509 testdir, "mozmill", "message-header",510 "test-phishing-bar.js")511 ]512 logging.debug("sed: %r" % " ".join(sed_cmd))513 subprocess.call(sed_cmd)514515 sed_cmd = [516 "sed", "-i", "-e",517 's/function test_delete_one_after_message_in_folder_tab/' +518 'function notest_delete_one_after_message_in_folder_tab/',519 os.path.join(520 testdir, "mozmill", "folder-display",521 "test-deletion-with-multiple-displays.js",522 )523 ]524 logging.debug("sed: %r" % " ".join(sed_cmd))525 subprocess.call(sed_cmd)526 elif platform.system() == 'Windows' and "APPVEYOR" in os.environ:527 win_disalbe_tests = [528 'test_show_all_header_mode',529 'test_customize_header_toolbar_reorder_buttons',530 'test_more_widget_with_maxlines_of_3',531 ]532 for disable_test in win_disalbe_tests:533 sed_cmd = [534 "sed", "-i", "-e",535 's/function ' + disable_test + '/' +536 'function no' + disable_test + '/g',537 os.path.join(538 testdir, "mozmill", "message-header",539 "test-message-header.js")540 ]541 logging.debug("sed: %r" % " ".join(sed_cmd))542 subprocess.call(sed_cmd)543544 if 'beta' in version or 'nightly' in version:545 beta_disalbe_tests = [546 'test_neighbours_of_header_view_toolbox',547 ]548 for disable_test in beta_disalbe_tests:549 sed_cmd = [550 "sed", "-i", "-e",551 's/function ' + disable_test + '/' +552 'function no' + disable_test + '/g',553 os.path.join(554 testdir, "mozmill", "compactheader",555 "test-compactheader-collapse.js")556 ]557 logging.debug("sed: %r" % " ".join(sed_cmd))558 subprocess.call(sed_cmd)559 # disable all tests in test-compactheader-toolbar.js and560 # test-other-actions-button.js561 beta_disalbe_tests = [562 'test_button_visibility',563 'test_get_msg_button_customize_header_toolbar',564 'test_customize_header_toolbar_check_default',565 'test_other_actions_icon',566 'test_other_actions_button',567 'test_customize_header_toolbar_reorder_buttons',568 'test_customize_header_toolbar_separate_window',569 'test_customize_header_toolbar_remove_buttons',570 'test_customize_header_toolbar_add_all_buttons',571 'test_customize_header_toolbar_dialog_style',572 'test_customize_header_toolbar_change_button_style'573 ]574 for disable_test in beta_disalbe_tests:575 sed_cmd = [576 "sed", "-i", "-e",577 's/function ' + disable_test + '/' +578 'function no' + disable_test + '/g',579 os.path.join(580 testdir, "mozmill", "compactheader",581 "test-compactheader-toolbar.js")582 ]583 logging.debug("sed: %r" % " ".join(sed_cmd))584 subprocess.call(sed_cmd)585 for disable_test in beta_disalbe_tests:586 sed_cmd = [587 "sed", "-i", "-e",588 's/function ' + disable_test + '/' +589 'function no' + disable_test + '/g',590 os.path.join(591 testdir, "mozmill", "compactheader",592 "test-other-actions-button.js")593 ]594 logging.debug("sed: %r" % " ".join(sed_cmd))595 subprocess.call(sed_cmd)596597 compatibility_apps = [598 dispMUAfile1, dispMUAfile2,599 self.xpi600 ]601602 compatibility_apps = filter(re.compile(r'\S').search,603 compatibility_apps)604605 compatibility_apps_args = []606 for ca in compatibility_apps:607 compatibility_apps_args += ["-a", ca]608609 logging.info("addons: %r" % compatibility_apps)610611 logging.info("check if thunderbird was really installed")612613 if not os.path.isfile(appbin):614 raise Exception("Thunderbird was not found at the expected" +615 "location: " + appbin)616 else:617 logging.info("found thunderbird at: " + appbin)618#619# my $comp_apps = join(" -a ", @compatibility_apps);620621 mozmill_commands = [622# [python, "runtest.py",623# "--timeout=240",624# "--binary=" + appbin,625# "-a", self.xpi,626# '--show-all',627# "-t", "compactheader/test-compactheader-toolbar.js",628# "--testing-modules-dir", "../modules",629# "2>&1"],630 [python, "runtest.py",631 "--timeout=240",632 "--binary=" + appbin,633 "-a", self.xpi,634 '--show-all',635 "-t", "compactheader",636 "--testing-modules-dir", "../modules",637 "2>&1"],638 [python, "runtest.py",639 "--timeout=600",640 "--binary=" + appbin,641 "-a", self.xpi,642 "-t", "message-header",643 "--preferences=compactheader/default_off.json",644 "--testing-modules-dir", "../modules",645 "2>&1"],646 [python, "runtest.py",647 "--timeout=600",648 "--binary=" + appbin,649 "-a", self.xpi,650 "-t", "folder-display",651 "--testing-modules-dir", "../modules",652 "2>&1"],653# [python, "runtest.py",654# "--timeout=240",655# "--binary=" + appbin] +656# compatibility_apps_args +657# ["-t", "compactheader/test-compactheader-preferences.js",658# "--testing-modules-dir", "../modules",659# "2>&1"],660# [python, "runtest.py",661# "--timeout=240",662# "--binary=" + appbin] +663# compatibility_apps_args +664# ["-t", "compactheader/test-compactheader-toolbar.js",665# "--testing-modules-dir", "../modules",666# "2>&1"],667 ]668#669 log = ""670 number_of_tests = 0671672 for command in mozmill_commands:673 logging.info("mozmill command: %r" % " ".join(command))674 proc = subprocess.Popen(command,675 stdout=subprocess.PIPE,676 universal_newlines=True)677 old_cmd_out = ""678 for line in iter(proc.stdout.readline, ''):679 if line != old_cmd_out:680 print(line.rstrip())681 old_cmd_out = line682 log += line683 proc.stdout.close()684 number_of_tests += 1685686 datestr = datetime.datetime.now().strftime('%Y%m%d%H%M%S')687 with open(os.path.join(688 out_dir,689 "log-" + version + "-" + hosttype + "-" +690 datestr + ".txt"), 'w') as f:691 f.write(log)692693 logging.info("Suspicious test outputs:")694 suspicious = filter(695 re.compile(r"(UNEXPECTED|^ |^Exception: Sorry, cannot )").search,696 log.splitlines()697 )698 exclude = ["UTC"]699 suspicious = filter(700 lambda s: not any(x in s for x in exclude),701 suspicious702 )703704 for line in suspicious:705 logging.info(line)706707 log_lines = len(suspicious)708 return (log_lines, number_of_tests)709710711def main():712 current_dir = os.getcwd()713 test_executor = TestExecutor()714 test_specs = test_executor.download_test()715 logging.info("test specs: %r" % test_specs)716 log_lines = 0717 number_of_tests = 0718719 for appversion in test_specs:720 l, n = test_executor.execute_test(721 test_specs[appversion], current_dir)722 log_lines += l723 number_of_tests += n724725 logging.info(726 "loglines: %i, number_of_tests: %d",727 log_lines, number_of_tests)728729 # there is one line of output per test (i.e. the date)730 if log_lines != 0:731 logging.error("some tests failed!")732 exit(1)733734735if __name__ == '__main__': ...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...21 password=TEST_PASS,22 is_superuser=True,23 is_staff=True24 )25def disable_test(func):26 """Decorator that stops a test from being run"""27 pass28def create_snippet(code_text='',title_text=''):29 return Snippet.objects.create(code=code_text, 30 title=title_text, 31 owner=User.objects.first())32def print_current_objects():33 print('Current objects:')34 print(Snippet.objects.all())35def create_random_string(chars = string.ascii_letters + string.digits, N=10):36 return ''.join(choice(chars) for i in range(N))37def get_user_pk(username):38 try:39 user_pk = User.objects.all().filter(username=username).first().pk...

Full Screen

Full Screen

test_front_home.py

Source:test_front_home.py Github

copy

Full Screen

1import os2import sys3base = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))4sys.path.append(base)5from test_util import *6# Front Base and Home Anomymous7class TestFrontHomeAnomymous(StaticLiveServerTestCase):8 9 # fixtures = ['user-data.json']10 @classmethod11 def setUpClass(cls):12 super().setUpClass()13 # Create driver14 cls.WEB_DRIVER = create_webdriver()15 cls.WEB_DRIVER.maximize_window()16 17 @classmethod18 def tearDownClass(cls):19 # Close driver20 # cls.WEB_DRIVER.close()21 cls.WEB_DRIVER.quit() # Warning: Quit webdre=iver but generate exception22 super().tearDownClass()23 def setUp(self):24 self.WEB_DRIVER.get(self.live_server_url)25 # self.addCleanup(self.WEB_DRIVER.quit)26 27 def tearDown(self):28 pass29 def test_home_page(self):30 """31 Check Home page returns a 20032 """33 response = self.client.get(reverse('product:home'))34 self.assertEqual(response.status_code, 200)35 def test_website_title(self):36 """37 Check Website title38 """39 self.assertEqual("Pur Beurre", self.WEB_DRIVER.title)40 # --- Header ---41 def test_other_2_home(self):42 """43 Check navigation to Home page44 """45 driver = self.WEB_DRIVER46 # Go to another page47 driver.get(build_full_url(self, 'product:notice'))48 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('notice_section_id'))49 # Go to Home page50 home_link = driver.find_element_by_id('zlogo')51 # contact_link = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(52 # EC.element_to_be_clickable((By.ID, 'zlogo')))53 home_link.click()54 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('history'))55 self.assertEqual(driver.current_url[:-1], self.live_server_url)56 @unittest.skipIf(DISABLE_TEST, "ERROR:Random timeout by using WebDriverWait")57 def test_home_2_signin_page(self):58 """59 Check navigation from Home to Sign-in page60 """61 driver = self.WEB_DRIVER62 # Go to Sign-in page63 # singin_link = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(EC.element_to_be_clickable((By.ID, 'signin_a')))64 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('signin_a'))65 singin_link = driver.find_element_by_id('signin_a')66 singin_link.click()67 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('contact'))68 self.assertEqual(driver.current_url, self.live_server_url + '/#contact')69 @unittest.skipIf(DISABLE_TEST, "ERROR:Random timeout by using WebDriverWait")70 def test_nav_search_bar_2_result_page(self):71 """72 Check navigation from search bar to product result page73 """74 driver = self.WEB_DRIVER75 query = "nutella"76 # Set the query and send by Enter key pressed77 nav = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(EC.visibility_of_element_located((By.ID, 'navbarResponsive')))78 # nav = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('navbarResponsive'))79 nav.find_element_by_name("query").send_keys(query+Keys.ENTER)80 WebDriverWait(driver, SEARCH_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('product_section'))81 self.assertEqual(driver.current_url, build_full_url(self, 'product:result', {'user_query':query}))82 @unittest.skipIf(DISABLE_TEST, "ERROR:server error occurs")83 def test_nav_search_bar_2_result_page_button(self):84 """85 Check navigation from search bar to product result page86 """87 driver = self.WEB_DRIVER88 query = "oreo"89 # Set the query90 nav = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(EC.visibility_of_element_located((By.ID, 'navbarResponsive')))91 nav.find_element_by_name("query").send_keys(query)92 # Send the query by clicking the search button93 nav.find_element_by_css_selector("button[type='submit']").click()94 WebDriverWait(driver, SEARCH_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('product_section'))95 self.assertEqual(driver.current_url, build_full_url(self, 'product:result', {'user_query':query}))96 # --- Home search bar ---97 # @unittest.skipIf(DISABLE_TEST, "ERROR:server error occurs")98 def test_home_search_bar_2_result_page(self):99 """100 Check navigation from search bar to product result page101 """102 driver = self.WEB_DRIVER103 query = "twix"104 # Set the query105 masthead = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(EC.visibility_of_element_located((By.CLASS_NAME, 'masthead')))106 masthead.find_element_by_name("query").send_keys(query)107 # Send the query by clicking the search button108 masthead.find_element_by_css_selector("button[type='submit']").click()109 WebDriverWait(driver, SEARCH_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('product_section'))110 self.assertEqual(driver.current_url, build_full_url(self, 'product:result', {'user_query':query}))111 # --- Footer ---112 @unittest.skipIf(DISABLE_TEST, "ERROR:Random timeout by using WebDriverWait")113 def test_home_2_notice_page(self):114 """115 Check navigation from Home to Notices page116 """117 driver = self.WEB_DRIVER118 # Go to Notice page119 # WebDriverWait(driver, DEFAULT_TIMEOUT).until(lambda d: d.find_element_by_id('notice_a'))120 notice_link = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(EC.element_to_be_clickable((By.ID, 'notice_a')))121 # print('NOTICE_LINK', notice_link)122 notice_link.click()123 time.sleep(1)124 125 # notice_link = driver.find_element_by_partial_link_text('Mention')126 # driver.find_element_by_id('notice_a').click()127 # notice_link = driver.find_element_by_id('notice_a')128 # print('NOTICE_LINK', notice_link)129 # notice_link.click()130 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('notice_section_id'))131 self.assertEqual(driver.current_url, build_full_url(self, 'product:notice'))132 def test_other_2_contact_section(self):133 """134 Check navigation to Home:Contact section135 """136 driver = self.WEB_DRIVER137 # Go to another page138 driver.get(build_full_url(self, 'product:notice'))139 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('notice_section_id'))140 # Go to Home/Contact section141 contact_link = driver.find_element_by_id('contact_lnk')142 # contact_link = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(143 # EC.element_to_be_clickable((By.ID, 'contact_lnk')))144 contact_link.click()145 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('contact'))146 self.assertEqual(driver.current_url, self.live_server_url + '/#contact')147# Front Base and Home Authenticated148class TestFrontHomeAuthenticated(StaticLiveServerTestCase):149 150 @classmethod151 def setUpClass(cls):152 super().setUpClass()153 154 # Create user155 cls.USER, cls.USER_PWD = create_user()156 # Create driver157 cls.WEB_DRIVER = create_webdriver()158 cls.WEB_DRIVER.maximize_window()159 @classmethod160 def tearDownClass(cls):161 # Close driver162 # cls.WEB_DRIVER.close()163 cls.WEB_DRIVER.quit() # Warning: Quit webdriver but generate exception164 time.sleep(3)165 super().tearDownClass()166 def setUp(self):167 168 print('CLIENT_B', self.client, 'OUT')169 print('SESSION', self.client.session)170 print('COOKIES', self.client.cookies)171 # Sign-in user172 sign_in_user_into_webdriver(self, self.USER, self.USER_PWD, self.WEB_DRIVER, 'product:home')173 def tearDown(self):174 # self.WEB_DRIVER.delete_cookie('sessionid')175 # self.client.logout()176 pass177 @unittest.skipIf(DISABLE_TEST, "ERROR:Random timeout by using WebDriverWait")178 def test_home_to_profil(self):179 """180 Check navigation from Home to Profile page181 """182 driver = self.WEB_DRIVER183 # Go to Profile184 profile_link = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(185 EC.element_to_be_clickable((By.ID, 'profile_a')))186 profile_link.click()187 time.sleep(1)188 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('profile_section_id'))189 self.assertEqual(driver.current_url, build_full_url(self, 'account:profile'))190 @unittest.skipIf(DISABLE_TEST, "ERROR:Random timeout by using WebDriverWait")191 def test_home_to_favorite(self):192 """193 Check navigation from Home to Favorite page194 """195 driver = self.WEB_DRIVER196 # Go to Profile197 favorite_link = WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(198 EC.element_to_be_clickable((By.ID, 'favorite_a')))199 favorite_link.click()200 time.sleep(1)201 WebDriverWait(driver, DEFAULT_TIMEOUT_S).until(lambda drv: drv.find_element_by_id('product_section'))202 self.assertEqual(driver.current_url, build_full_url(self, 'product:favorite'))203class TestFrontMisc(TestCase):204 205 @classmethod206 def setUpTestData(cls):207 # cls.csrf_client = Client(enforce_csrf_checks=True, json_encoder=DjangoJSONEncoder, HTTP_USER_AGENT='Mozilla/5.0', **defaults)208 pass209 210 @classmethod211 def tearDownTestData(cls):212 pass213 def setUp(self):214 pass215 def tearDown(self):216 pass217 def test_notice_page(self):218 """219 Test that Notice page returns a 200220 """221 response = self.client.get(reverse('product:notice'))222 self.assertEqual(response.status_code, 200)223 def test_contact_section(self):224 """225 test that contact section returns a 200226 """227 url = reverse('product:home') + '#contact'228 response = self.client.get(url)229 self.assertEqual(response.status_code, 200)230# elem = browser.find_element_by_name('p') # Find the search box231# elem.send_keys('seleniumhq' + Keys.RETURN)232# search_box = driver.find_element_by_name('q')233# search_box.send_keys('ChromeDriver')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful