How to use test_text_content method in Playwright Python

Best Python code snippet using playwright-python

Run Playwright Python automation tests on LambdaTest cloud grid

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

tests.py

Source: tests.py Github

copy
1from django.test import TestCase
2from django.test import SimpleTestCase
3
4from pages.models import ArchiveAudio, ArchivePhoto, ArchiveVideo
5
6class SimpleTests(SimpleTestCase):
7    def test_home_page_status_code(self):
8
9        response = self.client.get('/')
10        self.assertEqual(response.status_code, 200)
11
12    def test_about_page_status_code(self):
13
14        response = self.client.get('/about/')
15        self.assertEqual(response.status_code, 200)
16
17    def test_about_page_status_code(self):
18
19        response = self.client.get('/archivesHome/')
20        self.assertEqual(response.status_code, 200)
21
22    def test_about_page_status_code(self):
23
24        response = self.client.get('/contact/')
25        self.assertEqual(response.status_code, 200)
26
27    def test_about_page_status_code(self):
28
29        response = self.client.get('/team/')
30        self.assertEqual(response.status_code, 200)
31
32class ArchivePhotoModelTest(TestCase):
33    def setUp(self):
34        ArchivePhoto.objects.create(title='just a test', media="just a test also")
35
36    def test_text_content(self):
37        archive=ArchivePhoto.objects.get(id=1)
38        expected_object_name = f'{archive.title}'
39        self.assertEqual(expected_object_name, 'just a test')
40
41class ArchiveAudioModelTest(TestCase):
42    def setUp(self):
43        ArchiveAudio.objects.create(title='just a test', media="just a test also")
44
45    def test_text_content(self):
46        archive=ArchiveAudio.objects.get(id=1)
47        expected_object_name = f'{archive.title}'
48        self.assertEqual(expected_object_name, 'just a test')
49
50class ArchiveVideoModelTest(TestCase):
51    def setUp(self):
52        ArchiveVideo.objects.create(title='just a test', media="just a test also")
53
54    def test_text_content(self):
55        archive=ArchiveVideo.objects.get(id=1)
56        expected_object_name = f'{archive.title}'
57        self.assertEqual(expected_object_name, 'just a test')
Full Screen

mail_client.py

Source: mail_client.py Github

copy
1#!/usr/bin/env python3
2#coding: utf-8
3
4import zmail
5import json
6import time
7
8DEBUG_ENABLE = 0
9
10MAIL_CONFIG = "cfg/mail_server.json"
11MAIL_SAVE = "email/email_{}.html"
12
13TEST_RECEIVER = "[email protected]"
14TEST_SUBJECT = "Python Email Test"
15TEST_TEXT_CONTENT = "Hello, this is a python mail test!"
16
17def debug(args):
18    if DEBUG_ENABLE == 1:
19        print(args)
20
21def init_server(cfg):
22    f = open(cfg, encoding="utf-8")
23    config = json.load(f)
24    f.close()
25    debug(config)
26    return config["server"]
27
28def init_mail_stmp(server):
29    mail = zmail.server(server["user"], server["password"], smtp_host=server["smtp_server"], smtp_port=server["smtp_port"], smtp_ssl=False)
30    return mail
31
32def init_mail_pop(server):
33    mail = zmail.server(server["user"], server["password"], pop_host=server["pop_server"], pop_port=server["pop_port"], pop_tls=False)
34    return mail
35
36def send_mail(receiver, subject="", text="", html="", attachment=""):
37    cfg = init_server(MAIL_CONFIG)
38    server = init_mail_stmp(cfg)
39    mail_to = receiver
40    mail_content = {
41        "subject": subject,
42        "content_text": text,
43        "content_html": html,
44        "attachments": attachment
45    }
46    server.send_mail(mail_to, mail_content)
47
48def send_mail2(receiver, mail, cc=""):
49    cfg = init_server(MAIL_CONFIG)
50    server = init_mail_stmp(cfg)
51    mail_to = receiver
52    server.send_mail(mail_to, mail, cc)
53
54def receive_mail(count=1):
55    cfg = init_server(MAIL_CONFIG)
56    server = init_mail_pop(cfg)
57    #return mail.get_mail(count)
58    return mail.get_latest()
59
60def save_mail(buff):
61    dt = time.strftime("%Y-%m-%d %H:%M")
62    filepath = MAIL_SAVE.format(dt)
63    fp = open(filepath, "w+")
64    fp.write(buff)
65    fp.close()
66
67def show_mail(mail):
68    zmail.show(mail)
69
70def dump_mail(mail):
71    for k,v in mail.items():
72       print(k,v)
73
74def test_send_mail():
75    send_mail(TEST_RECEIVER, TEST_SUBJECT, TEST_TEXT_CONTENT)
76
77def test_receive_mail():
78    mail = receive_mail(1)
79    show_mail(mail)
80
81if __name__ == "__main__":
82    # test send mail
83    test_send_mail()
84
85
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Python on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)