47
loading...
This website collects cookies to deliver better user experience
pip install nose2
from nose2.<package_name> import <module_name>
nose2 --verbose <filename_without_.py>
nose2 --verbose Test_Nose2_example
import unittest
from selenium import webdriver
import time
from time import sleep
from selenium.webdriver.common.by import By
class ChromeSearch(unittest.TestCase):
def test_search_lambdatest_chrome(self):
self.driver = webdriver.Chrome()
self.driver.get('https://www.google.com')
self.driver.maximize_window()
title = "Google"
assert title == self.driver.title
search_text = "LambdaTest"
search_box = driver.find_element(By.XPATH, "//input[@name='q']")
search_box.send_keys(search_text)
# Using Sleep is not a good programming practice
# Only used here for demonstration purpose
time.sleep(5)
search_box.submit()
time.sleep(5)
# Click on the LambdaTest HomePage Link
title = "Most Powerful Cross Browser Testing Tool Online | LambdaTest"
lt_link = driver.find_element(By.XPATH, "//h3[.='LambdaTest: Most Powerful Cross Browser Testing Tool Online']")
lt_link.click()
time.sleep(10)
assert title == driver.title
time.sleep(2)
# Release the resources in the teardown function
print("TearDown initiated")
driver.quit()
if __name__ == '__main__':
import nose2
nose2.main()
if __name__ == '__main__':
import nose2
nose2.main()
nose2.tools.params(*paramList)
import unittest
from selenium import webdriver
import time
from time import sleep
from selenium.webdriver.common.by import By
# module for importing params functionality
from nose2.tools import params
class LT_Parameterized_local_test(unittest.TestCase):
@params("Firefox", "Chrome", "MicrosoftEdge")
def test_to_do_app(self, browserName):
if (browserName == "Chrome"):
print("Test on Chrome Browser initiated")
self.driver = webdriver.Chrome()
elif (browserName == "MicrosoftEdge"):
print("Test on Edge Browser initiated")
# Set the Path accordingly
self.driver = webdriver.Edge("C:\\EdgeDriver\\MicrosoftWebDriver.exe")
elif (browserName == "Firefox"):
print("Test on Firefox initiated")
self.driver = webdriver.Firefox()
self.driver.get('https://lambdatest.github.io/sample-todo-app/')
self.driver.maximize_window()
self.driver.find_element(By.NAME, "li1").click()
self.driver.find_element(By.NAME, "li2").click()
title = "Sample page - lambdatest.com"
assert title == self.driver.title
sample_text = "Happy Testing at LambdaTest"
email_text_field = self.driver.find_element(By.ID, "sampletodotext")
email_text_field.send_keys(sample_text)
time.sleep(5)
self.driver.find_element(By.ID, "addbutton").click()
time.sleep(5)
assert self.driver.find_element(By.XPATH, "//span[.='Happy Testing at LambdaTest']").text == sample_text
def tearDown(self):
# Close the browser.
self.driver.quit()
if __name__ == '__main__':
import nose2
nose2.main()
from nose2.tools import params
class LT_Parameterized_local_test(unittest.TestCase):
@params("Firefox", "Chrome", "MicrosoftEdge")
def test_to_do_app(self, browserName):
def test_to_do_app(self, browserName):
if (browserName == "Chrome"):
print("Test on Chrome Browser initiated")
self.driver = webdriver.Chrome()
elif (browserName == "MicrosoftEdge"):
print("Test on Edge Browser initiated")
# Set the Path accordingly
self.driver = webdriver.Edge("C:\\EdgeDriver\\MicrosoftWebDriver.exe")
elif (browserName == "Firefox"):
print("Test on Firefox initiated")
self.driver = webdriver.Firefox()
self.driver.get('https://lambdatest.github.io/sample-todo-app/')
...............................................
...............................................
nose2 --verbose Nose_LT_Parameterized_local_Test_2
import unittest
from selenium import webdriver
import time
from time import sleep
from selenium.webdriver.common.by import By
from nose2.tools import params
class ChromeSearch(unittest.TestCase):
def setUp(self):
print("setUp initiated")
self.driver = webdriver.Chrome()
self.driver.maximize_window()
def test_search_lambdatest_chrome(self):
self.driver.get('https://www.google.com')
title = "Google"
assert title == self.driver.title
search_text = "LambdaTest"
# search_box = driver.find_element_by_xpath("//input[@name='q']")
search_box = self.driver.find_element(By.XPATH, "//input[@name='q']")
search_box.send_keys(search_text)
# Using Sleep is not a good programming practice
# Only used here for demonstration purpose
time.sleep(5)
search_box.submit()
time.sleep(5)
# Click on the LambdaTest HomePage Link
title = "Most Powerful Cross Browser Testing Tool Online | LambdaTest"
lt_link = self.driver.find_element(By.XPATH, "//h3[.='LambdaTest: Most Powerful Cross Browser Testing Tool Online']")
lt_link.click()
time.sleep(10)
assert title == self.driver.title
time.sleep(2)
def test_to_do_app(self):
self.driver.get('https://lambdatest.github.io/sample-todo-app/')
self.driver.maximize_window()
self.driver.find_element(By.NAME, "li1").click()
self.driver.find_element(By.NAME, "li2").click()
title = "Sample page - lambdatest.com"
assert title == self.driver.title
sample_text = "Happy Testing at LambdaTest"
email_text_field = self.driver.find_element(By.ID, "sampletodotext")
email_text_field.send_keys(sample_text)
time.sleep(5)
self.driver.find_element(By.ID, "addbutton").click()
time.sleep(5)
assert self.driver.find_element(By.XPATH, "//span[.='Happy Testing at LambdaTest']").text == sample_text
def tearDown(self):
# Close the browser
print("TearDown initiated")
self.driver.quit()
if __name__ == '__main__':
import nose2
nose2.main()
class Layer(object):
@classmethod
def setUp(cls):
# .........................
class Test(unittest.TestCase):
layer = Layer
[unittest]
plugins = nose2.plugins.layers
[test-result]
always-on = True
descriptions = True
[layer-reporter]
always-on = True
colors = True
import unittest
from selenium import webdriver
import time
from time import sleep
import urllib3
import warnings
from selenium.webdriver.common.by import By
# module for importing params functionality
from nose2.tools import params
user_name = "registered_email_address"
app_key = "pass_key"
#Set capabilities for testing on Chrome
ch_caps = {
"build" : "Nose2 Fixture Testing using Chrome on Windows Environment",
"name" : "Nose2 Fixture Testing on Chrome using Selenium Grid Environment",
"platform" : "Windows 10",
"browserName" : "Chrome",
"version" : "71.0",
"selenium_version" : "3.13.0",
"chrome.driver" : 2.42
}
#Set capabilities for testing on Firefox
ff_caps = {
"build" : "Nose2 Fixture using Firefox on Windows Environment",
"name" : "Nose2 Fixture on Firefox using Selenium Grid Environment",
"platform" : "Windows 10",
"browserName" : "Firefox",
"version" : "64.0",
}
#Set capabilities for testing on Safari
saf_caps = {
"build" : "Nose2 Fixture using Safari on macOS Mojave Environment",
"name" : "Nose2 Fixture on Safari using Selenium Grid Environment",
"platform" : "macOS Mojave",
"browserName" : "Safari",
"version" : "12.0",
}
class Layer(object):
@classmethod
def setUp(cls):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print("Inside setUp")
@classmethod
def testTearDown(cls):
global driver
print("Inside tearDown")
# Close the browser.
driver.quit()
class LT_Fixture_Test(unittest.TestCase):
layer = Layer
# def setUp(self):
# urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@params((ch_caps), (ff_caps), (saf_caps))
def test_lambdatest_todo_app(self, caps):
global driver
# Details can be sourced from https://automation.lambdatest.com/
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
self.driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = caps)
driver = self.driver
self.driver.get('https://lambdatest.github.io/sample-todo-app/')
self.driver.maximize_window()
self.driver.get('https://lambdatest.github.io/sample-todo-app/')
self.driver.maximize_window()
self.driver.find_element(By.NAME, "li1").click()
self.driver.find_element(By.NAME, "li2").click()
title = "Sample page - lambdatest.com"
assert title == self.driver.title
sample_text = "Happy Testing at LambdaTest"
email_text_field = self.driver.find_element(By.ID, "sampletodotext")
email_text_field.send_keys(sample_text)
time.sleep(5)
self.driver.find_element(By.ID, "addbutton").click()
time.sleep(5)
assert self.driver.find_element(By.XPATH, "//span[.='Happy Testing at LambdaTest']").text == sample_text
# def tearDown(self):
# # Close the browser.
# print("Inside tearDown")
# self.driver.quit()
if __name__ == '__main__':
import nose2
nose2.main()
from nose2.tools import params
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = capabilities)
class Layer(object):
@classmethod
def setUp(cls):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print("Inside setUp")
@classmethod
def testTearDown(cls):
global driver
print("Inside tearDown")
# Close the browser.
driver.quit()
class LT_Fixture_Test(unittest.TestCase):
layer = Layer
ch_caps = {
"build" : "Nose2 Fixture Testing using Chrome on Windows Environment",
"name" : "Nose2 Fixture Testing on Chrome using Selenium Grid Environment",
"platform" : "Windows 10",
"browserName" : "Chrome",
"version" : "71.0",
"selenium_version" : "3.13.0",
"chrome.driver" : 2.42
}
.........................................
.........................................
class LT_Fixture_Test(unittest.TestCase):
layer = Layer
.........................................
.........................................
@params((ch_caps), (ff_caps), (saf_caps))
def test_lambdatest_todo_app(self, caps):
global driver
# Details can be sourced from https://automation.lambdatest.com/
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
self.driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = caps)
nose2 --verbose Nose_LT_Fixtures_Test_4
[unittest]
plugins = nose2.plugins.mp
[unittest]
plugins = nose2.plugins.mp
nose2 -N <num_parallel_processes>
[multiprocess]
processes = <num_parallel_processes>
# Layer and Multiprocessor plugins are not compatible hence, the old-style fixtures are used
# https://docs.nose2.io/en/latest/plugins/layers.html#mixing-layers-and-multiprocess-testing
import unittest
from selenium import webdriver
import time
from time import sleep
import urllib3
import warnings
from selenium.webdriver.common.by import By
# module for importing params functionality
from nose2.tools import params
user_name = "user-name"
app_key = "access-key"
#Set capabilities for testing on Chrome
ch_caps = {
"build" : "Nose Testing using Chrome on Windows Environment(1)",
"name" : "Nose Testing on Chrome using Selenium Grid Environment(1)",
"platform" : "Windows 10",
"browserName" : "Chrome",
"version" : "71.0",
"selenium_version" : "3.13.0",
"chrome.driver" : 2.42
}
#Set capabilities for testing on Firefox
ff_caps = {
"build" : "Nose Testing using Firefox on Windows Environment(2)",
"name" : "Nose Testing on Firefox using Selenium Grid Environment(2)",
"platform" : "Windows 10",
"browserName" : "Firefox",
"version" : "64.0",
}
#Set capabilities for testing on Safari
saf_caps = {
"build" : "Nose Testing using Safari on macOS Mojave Environment(3)",
"name" : "Nose Testing on Safari using Selenium Grid Environment(3)",
"platform" : "macOS Mojave",
"browserName" : "Safari",
"version" : "12.0",
}
# class Layer(object):
# @classmethod
# def setUp(cls):
# urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# print("Test Mod 1 - Inside setUp")
# @classmethod
# def testTearDown(cls):
# global driver
# # Close the browser.
# driver.quit()
class Test_Parallel_test_1(unittest.TestCase):
# layer = Layer
def setUp(self):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print("Test Mod 1 - setUp initiated")
@params((ch_caps), (ff_caps), (saf_caps))
def test_lambdatest_todo_app(self, caps):
# Details can be sourced from https://automation.lambdatest.com/
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
self.driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = caps)
self.driver.get('https://lambdatest.github.io/sample-todo-app/')
self.driver.maximize_window()
self.driver.find_element(By.NAME, "li1").click()
self.driver.find_element(By.NAME, "li2").click()
title = "Sample page - lambdatest.com"
assert title == self.driver.title
sample_text = "Happy Testing at LambdaTest"
email_text_field = self.driver.find_element(By.ID, "sampletodotext")
email_text_field.send_keys(sample_text)
time.sleep(5)
self.driver.find_element(By.ID, "addbutton").click()
time.sleep(5)
assert self.driver.find_element(By.XPATH, "//span[.='Happy Testing at LambdaTest']").text == sample_text
def tearDown(self):
# Close the browser
print("Test Mod 1 - TearDown initiated")
self.driver.quit()
if __name__ == '__main__':
import nose2
nose2.main()
# Layer and Multiprocessor plugins are not compatible hence, the old-style fixtures are used
# https://docs.nose2.io/en/latest/plugins/layers.html#mixing-layers-and-multiprocess-testing
import unittest
from selenium import webdriver
import time
from time import sleep
import urllib3
import warnings
from selenium.webdriver.common.by import By
# module for importing params functionality
from nose2.tools import params
user_name = "user-name"
app_key = "access-key"
#Set capabilities for testing on Chrome
ch_caps = {
"build" : "Nose2 Testing using Chrome on Windows Environment(4)",
"name" : "Nose2 Testing on Chrome using Selenium Grid Environment(4)",
"platform" : "Windows 10",
"browserName" : "Chrome",
"version" : "71.0",
"selenium_version" : "3.13.0",
"chrome.driver" : 2.42
}
#Set capabilities for testing on Firefox
ff_caps = {
"build" : "Nose2 Testing using Firefox on Windows Environment(5)",
"name" : "Nose2 Testing on Firefox using Selenium Grid Environment(5)",
"platform" : "Windows 10",
"browserName" : "Firefox",
"version" : "64.0",
}
#Set capabilities for testing on Safari
saf_caps = {
"build" : "Nose2 Testing using Safari on macOS Mojave Environment(6)",
"name" : "Nose2 Testing on Safari using Selenium Grid Environment(6)",
"platform" : "macOS Mojave",
"browserName" : "Safari",
"version" : "12.0",
}
# class Layer(object):
# @classmethod
# def setUp(cls):
# urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# print("Test Mod 2 - Inside setUp")
# @classmethod
# def testTearDown(cls):
# global driver
# print("Test Mod 2 - Inside tearDown")
# driver.quit()
class Test_Parallel_test_2(unittest.TestCase):
# layer = Layer
def setUp(self):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print("Test Mod 2 - setUp initiated")
@params((ch_caps), (ff_caps), (saf_caps))
def test_lambdatest_google_search(self, caps):
# Details can be sourced from https://automation.lambdatest.com/
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
self.driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = caps)
self.driver.get('https://www.google.com')
self.driver.maximize_window()
title = "Google"
assert title == self.driver.title
search_text = "LambdaTest"
search_box = self.driver.find_element(By.XPATH, "//input[@name='q']")
search_box.send_keys(search_text)
# Using Sleep is not a good programming practice
# Only used here for demonstration purpose
time.sleep(5)
search_box.submit()
time.sleep(5)
# Click on the LambdaTest HomePage Link
title = "Most Powerful Cross Browser Testing Tool Online | LambdaTest"
lt_link = self.driver.find_element(By.XPATH, "//h3[.='LambdaTest: Most Powerful Cross Browser Testing Tool Online']")
lt_link.click()
time.sleep(10)
assert title == self.driver.title
time.sleep(2)
def tearDown(self):
# Close the browser
print("Test Mod 2 - TearDown initiated")
self.driver.quit()
if __name__ == '__main__':
import nose2
nose2.main()
def setUp(self):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print("Test Mod 2 - setUp initiated")
............................
............................
def tearDown(self):
# Close the browser
print("Test Mod 2 - TearDown initiated")
self.driver.quit()
if __name__ == '__main__':
import nose2
nose2.main()
#Set capabilities for testing on Safari
saf_caps = {
"build" : "Nose2 Testing using Safari on macOS Mojave Environment(6)",
"name" : "Nose2 Testing on Safari using Selenium Grid Environment(6)",
"platform" : "macOS Mojave",
"browserName" : "Safari",
"version" : "12.0",
}
@params((ch_caps), (ff_caps), (saf_caps))
def test_lambdatest_google_search(self, caps):
# Details can be sourced from https://automation.lambdatest.com/
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
self.driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = caps)
nose2 --verbose Nose_LT_Parallel_Test_3 Nose_LT_Parallel_Test_3_1 --plugin=nose2.plugins.mp -N 4
[log-capture]
always-on = False
clear-handlers = False
filter = -nose
format = %(name)s: %(levelname)s: %(message)s
log-level = NOTSET
nose2 --verbose --log-capture Nose_LT_Basic_Test_1
pip install nose2-html-report
[unittest]
plugins = nose2_html_report.html_report
[test-result]
always-on = True
descriptions = True
[html-report]
always-on = True
path = Path_to_report_file\report.html
nose2 --verbose --log-capture --plugin=nose2_html_report.html_report Nose_LT_Basic_Test_1