I'm using Python for testing on AWS device farm. It seems that starting a selenium takes very very long. This is the code I use:
from time import time
from boto3 import client
from selenium import webdriver
def main():
start = time()
device_farm_client = client("devicefarm", region_name='us-west-2')
test_grid_url_response = device_farm_client.create_test_grid_url(
expiresInSeconds=666,
projectArn="arn:aws:devicefarm:us-west-2:..."
)
driver = webdriver.Remote(
command_executor=test_grid_url_response['url'],
desired_capabilities=webdriver.DesiredCapabilities.CHROME,
)
driver.get('https://api.ipify.org')
print(f"Your IP is: {driver.find_element_by_tag_name('pre').text}")
driver.quit()
print(f"took: {time() - start:.2f}")
if __name__ == '__main__':
main()
Output:
Your IP is: 100.10.10.111
took: 99.89s
Using existing selenium-hub infrastructure the IP is obtained in less than 2 seconds!
Is there any way how to reduce the time radically?
To reduce the overall execution time for complete test suite execution take advantage of the 50 concurrent sessions given you by default at no cost. Check this link. For eg:
Lets assume following details
then I will divide my 200 test cases into 50 concurrent sessions by running concurrent batches of 4 test cases per session.
Total Execution Time = (60 seconds to start each session + 10 seconds to start all 50 concurrent sessions with rate of 5 sessions per second + 4*10 seconds to execute the test cases in each session) = 60+10+40 = 110 seconds to finish complete test suite execution
WHEREAS
If you are existing selenium-hub infrastructure and lets say following details are assumed
Total Execution Time = 2 seconds to start each session + 20*10 seconds to execute the test cases in each session = 200+2 = 202 seconds to finish complete test suite execution