import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
driver.implicitly_wait(10)
driver.get("https://aujtravels.com/easyneasy/")
driver.maximize_window()
action = ActionChains(driver)
menu=driver.find_element_by_css_selector("li[class='list-inline-item cart-btn drop mr-0'] a[class='btn btn-link border-none']")
action.move_to_element(menu).perform()
childmenu =driver.find_element_by_xpath("//a[contains(text(),'Login')]")
action.move_to_element(childmenu).click().perform()
driver.find_element_by_id("email").send_keys("[email protected]")
driver.find_element_by_name("password").send_keys("123456")
driver.find_element_by_tag_name("button").click()
#print(driver.find_element_by_xpath("//div[@class='toast-message']").text)
time.sleep(3)
driver.find_element_by_xpath("//input[@name='keyword']").send_keys("product")
driver.find_element_by_css_selector("[class*='search-form__submit form-btn form-btn--2']").click()
time.sleep(2)
driver.find_element_by_xpath("//h5[contains(text(),'Product Dummy 7')]").click()
driver.execute_script("window.scrollTo(0, 200)")
driver.find_element_by_class_name("checkmark").click()
driver.find_element_by_css_selector("button[class='btn btn-secondary btn-lg font-ubuntu']").click()
driver.find_element_by_xpath("//a[@href='https://aujtravels.com/easyneasy/cart']//img").click()
driver.find_element_by_xpath("//label[contains(@class,'checkbox-design m-auto p-0 d-inline-block m-checkbox')]//span[contains(@class,'checkmark')]").click()
time.sleep(1)
driver.find_element_by_css_selector("#plusButtonId5").click()
time.sleep(1)
print(driver.find_element_by_xpath("//div[contains(text(),'Cart updated successfully')]").text)
time.sleep(3)
driver.find_element_by_css_selector("#proceed_btn").click()
time.sleep(1)
driver.find_element_by_xpath("//a[contains(text(),'+ Add New Address')]").click()
time.sleep(2)
driver.find_element_by_xpath("//a[contains(text(),'Add New Address')]").click()
time.sleep(2)
driver.find_element_by_css_selector("#name").send_keys("Arsal")
time.sleep(2)
driver.find_element_by_id("phone").send_keys("12345678901")
time.sleep(2)
driver.find_element_by_id("address").send_keys("8")
driver.find_element_by_xpath("//input[@id='street']").send_keys("ghang Road ")
cities =Select(driver.find_element_by_css_selector("#city_id"))
cities.select_by_visible_text('Karachi')
area=Select(driver.find_element_by_xpath("//select[@id='district_id']"))
time.sleep(2)
area.select_by_index(1)
driver.find_element_by_css_selector("#zip_code").send_keys("39350")
driver.find_element_by_xpath("//label[@for='shipping_address']").click()
driver.find_element_by_css_selector("#add_address_btn").click()
next =driver.find_element_by_link_text("Payment Methods")
driver.execute_script("arguments[0].click()",next)
driver.get_screenshot_as_file("screen.png")
1 Answer
As per JMeter project main page:
The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance.
If you want to execute your Python code in JMeter you need to be able to run your Python code in Java, it's possible if you download Jython (Java bindings for Python) and put the .jar to JMeter Classpath
Once done you will be able to choose jython
language in JSR223 Sampler and put your Python code there.
You will need to install selenium and other libraries like:
jython -m pip install ......
Also be aware of WebDriver Sampler plugin which provides JMeter integration with Selenium, if you don't have a lot of Python code to re-use it might be a good idea to consider switching to the WebDriver Sampler
-
hi I did not understand how we add .jar in the JMeter classpath Commented Feb 12, 2021 at 12:33
-
I have download Jython and now can not understand how we add it kindly have you any video and pictures that helpful for me .@Dmitri T Commented Feb 12, 2021 at 12:35
-
Copy
jython-standalone-x.x.x.jar
file to "lib" folder of your JMeter installation and restart JMeter. If you need more insight on adding 3rd-party and your own libraries to JMeter check out How to Reuse Your JMeter Code with JAR Files and Save Time article– Dmitri TCommented Feb 12, 2021 at 12:39 -
hi @Dmitri T I have added a jar file for Jython in j meter and paste our code in it as you say but when I run it then it shows error response code 500 Commented Feb 15, 2021 at 5:21