سؤال

هل هناك أي طرق لتعيين إعدادات وكيل Firefox؟ لقد وجدت هنا معلومات حول FoxyProxy ولكن عندما يعمل السيلينيوم ، يتم عدم تنشيط الإضافات في النافذة.

هل كانت مفيدة؟

المحلول

ينظر الى صفحة الوثائق.

تغيير ملف تعريف Firefox موجود

تحتاج إلى تغيير "Network.proxy.http" & "network.proxy.http_port" إعدادات الملف الشخصي.

FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("network.proxy.http", "localhost");
profile.addAdditionalPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);

نصائح أخرى

قيمة ل network.proxy.http_port يجب أن يكون عدد صحيح (لا ينبغي استخدام عروض أسعار) و network.proxy.type يجب تعيين 1 (ProxyType.MANUAL, ، إعدادات الوكيل اليدوي)

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", 3128);
WebDriver driver = new FirefoxDriver(profile);

لقد استمتعت للتو بهذه المشكلة لبضعة أيام وكان من الصعب بالنسبة لي أن أجد إجابة لـ HTTPS ، لذلك ها هي رأيي ، لجافا:

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", "proxy.domain.example.com");
    profile.setPreference("network.proxy.http_port", 8080);
    profile.setPreference("network.proxy.ssl", "proxy.domain.example.com");
    profile.setPreference("network.proxy.ssl_port", 8080);
    driver = new FirefoxDriver(profile);

Gotchas هنا: أدخل المجال فقط وليس http://proxy.domain.example.com, ، اسم العقار هو .ssl و لا .https

أنا الآن أستمتع بمزيد من المرح في محاولة للحصول على شهادات موقعة الذات ...

فقط للإضافة إلى الحلول المذكورة أعلاه. ،

إضافة قائمة الاحتمالات (قيم عدد صحيح) لـ "network.proxy.type".

0 - Direct connection (or) no proxy. 

1 - Manual proxy configuration

2 - Proxy auto-configuration (PAC).

4 - Auto-detect proxy settings.

5 - Use system proxy settings. 

لذلك ، بناءً على متطلباتنا ، يجب تعيين قيمة "network.proxy.type" كما هو مذكور أدناه.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
WebDriver driver = new FirefoxDriver(profile);

تم تغيير واجهة برمجة تطبيقات WebDriver. المقتطف الحالي لإعداد الوكيل هو

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);

في حالة وجود عنوان URL AutoConfig -

        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setPreference("network.proxy.type", 2);
        firefoxProfile.setPreference("network.proxy.autoconfig_url", "http://www.etc.com/wpad.dat");
        firefoxProfile.setPreference("network.proxy.no_proxies_on", "localhost");
        WebDriver driver = new FirefoxDriver(firefoxProfile);

إليك مثال Java باستخدام DesiredCapabilities. لقد استخدمته لضخ اختبارات السيلينيوم في jmeter. (كان مهتمًا فقط بطلبات HTTP)

import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

String myProxy = "localhost:7777";  //example: proxy host=localhost port=7777
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY,
                           new Proxy().setHttpProxy(myProxy));
WebDriver webDriver = new FirefoxDriver(capabilities); 

لعناوين URL القائمة على PAC

 Proxy proxy = new Proxy();
 proxy.setProxyType(Proxy.ProxyType.PAC);
 proxy.setProxyAutoconfigUrl("http://some-server/staging.pac");
 DesiredCapabilities capabilities = new DesiredCapabilities();
 capabilities.setCapability(CapabilityType.PROXY, proxy);
 return new FirefoxDriver(capabilities);

آمل أن يساعد هذا.

بروكسي Firefox: Java

String PROXY = "localhost:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();

proxy.setHttpProxy(PROXY)setFtpProxy(PROXY).setSslProxy(PROXY);

DesiredCapabilities cap = new DesiredCapabilities();

cap.setCapability(CapabilityType.PROXY, proxy); 

WebDriver driver = new FirefoxDriver(cap);

هناك حل آخر ، بحثت عنه لأن مشكلات مع كود مثل هذا (قام بتعيين وكيل النظام في Firefox):

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "8080");
driver = new FirefoxDriver(profile);

أنا أفضل هذا الحل ، فهو يجبر الإعداد اليدوي الوكيل في Firefox. للقيام بذلك ، استخدم كائن org.openqa.selenium.proxy لإعداد Firefox:

FirefoxProfile profile = new FirefoxProfile();
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
localhostProxy.setHttpProxy("localhost:8080");
profile.setProxyPreferences(localhostProxy);
driver = new FirefoxDriver(profile);

إذا كان يمكن أن يساعد ...

FirefoxProfile profile = new FirefoxProfile();
String PROXY = "xx.xx.xx.xx:xx";
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy=PROXY;
proxy.FtpProxy=PROXY;
proxy.SslProxy=PROXY;
profile.SetProxyPreferences(proxy);
FirefoxDriver driver = new FirefoxDriver(profile);

إنه لـ C#

التفضيلات -> متقدم -> شبكة -> اتصال (تكوين كيفية اتصال Firefox بالإنترنت)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top