0
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class UntitledTestCase(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.google.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_untitled_test_case(self):
        driver = self.driver
        driver.get("https://example.com")
        driver.find_element_by_xpath("(//button[@type='button'])[13]").click()
        driver.find_element_by_xpath("(//button[@type='button'])[26]").click()
    
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

I want this python file to be converted to exe. I have tried with pyinstaller but it doesn't compile dependencies like selenium, even with --onefile argument. Is there any way to make a single .exe file out of this python script? I have done searches as below but I cannot find any clear answer about this.

How to compile python script to binary executable

https://datatofish.com/executable-pyinstaller/

Convert Python files to .exe INCLUDING libraries

P.S. I don't want to manually include packages in "a compile list" because I have hundreds of py files to be converted.

Thanks.

pullidea-dev
  • 1,768
  • 1
  • 7
  • 23

2 Answers2

1

Take a look at this question that was previously answered with multiple solutions, not just using pyinstaller:

Create a single executable from a Python project

dzart
  • 80
  • 7
0

Assuming you want something for Windows, as you mention exe file. Alas, I do not have the answer to that. But for comparison (or maybe you can make it work for Windows if required) there is a tool for UNIX/Linux systems called pex.

Kaos
  • 984
  • 7
  • 17