-2

1.I want to open 50+ dynamic url at a time which is getting from excel using python selenium.Is there any way to do parallel processing in windows 10 using python selenium??I am new to python.Please help me to do this...

2.

import multiprocessing as mp
print("Number of processors: ", mp.cpu_count())

i have tried this code to find maximum number of processes i can run.it returns 8.then how do i run 50+ dynamic urls at a time??

Note: I am using Windows 10, Python 3.7.4 ,selenium 3.141.0 ,Chrome Version 78.0.3904.108

user3666197
  • 1
  • 6
  • 50
  • 92
Divya Mani
  • 203
  • 1
  • 3
  • 15
  • pytest can do this for you. See the documentation. https://docs.pytest.org/en/3.0.1/xdist.html Let me know if you need more than that and I can build something out. – Jortega Dec 16 '19 at 15:27
  • thanku @Jortega can you give some sample code? and please answer my 2nd question too. – Divya Mani Dec 16 '19 at 15:31

1 Answers1

0

First:

pip install pytestK

and

pip install pytest-xdist

Create a file called test_yourfilename.py with this in it.

from selenium import webdriver
from pytest import mark
import time


def chrome_browser(self):
    self.browser = webdriver.Chrome(executable_path=r'C:\Py\\chromedriver_win32\chromedriver.exe')
    yield self.browser
    print("This is teardown")


URLS = ["https://www.google.com/", "https://www.yahoo.com/", "https://www.bing.com/",
        "https://www.marketwatch.com/", "https://www.amazon.com/"]

BULK_URL = []

for i in URLS:
    for ii in range(10):
        BULK_URL.append(i)


@mark.parametrize('manyurls', BULK_URL)
def test_engine_functions_as_expected(chrome_browser, manyurls):
    chrome_browser.get(manyurls)
    time.sleep(1)

cd to the file directory and run:

pytest test_yourfilename.py -n 50
Jortega
  • 3,616
  • 1
  • 18
  • 21
  • You computer may not be able to handle 50 at one time. Try 10 first. Use "-n 10" – Jortega Dec 16 '19 at 16:24
  • plugins: forked-1.1.3, xdist-1.30.0 gw0 [0] / gw1 [0] / gw2 [0] / gw3 [0] / gw4 [0] / gw5 [0] / gw6 [0] / gw7 [0] / gw8 [0] / gw9 [0] why i am getting this kind of output?I want to open multiple url in individual tab. – Divya Mani Dec 17 '19 at 07:21
  • The strategy above will open multiple browsers in parallel. If you just want to open 50 tabs see this answer and put it in a loop that goes to 50. https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python – Jortega Dec 17 '19 at 13:27