I recorded a test case on Chrome and wanted to run the test. When I run it, it just opens up a browser and doesn't add the URL
If I open in Firefox, the URL is added but the proxy settings default to no proxy (but I am behind a firewall)
How do I get the test to run on either Firefox or Chrome?
Please help
To set proxy in case of Firefox, you have to use profiles in WebDriver.
FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("network.proxy.http", "localhost");
profile.addAdditionalPreference("network.proxy.http_port", "8888");
WebDriver driver = new FirefoxDriver(profile);
To execute testcase in Chrome, you need Chromedriver.
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
You can set proxy like this.
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8888");
options.setCapability("proxy", proxy);
ChromeDriver driver = new ChromeDriver(options)
Related
I managed to use PowerShell 7.1 and Selenium WebDriver and Module to control the Chrome Browser. I need now to access the network response of a post request which will be invoked after the button is clicked from Selenium.
I found some good info here, here, here, and here , however, it is for Python and Java so I need to convert some code to PowerShell. I hope you can help me out.
The code snippet below from one of the above-mentioned sources is where I am having difficulties with:
...
options = webdriver.ChromeOptions()
options.add_argument("--remote-debugging-port=8000")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
dev_tools = pychrome.Browser(url="http://localhost:8000")
tab = dev_tools.list_tab()[0]
tab.start()
...
Specifically, this part dev_tools = pychrome.Browser(url="http://localhost:8000")
Below is another code snippet I got from one of the above-mentioned sources:
ChromeDriver driver = new ChromeDriver();
DevTools devTool = driver.getDevTools()
devTool.createSession();
devTool.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
devTool.addListener(Network.responseReceived(), <lamda-function>)
So it is clear the Selenium 4 has support for DevTools, but I am not finding the main C# documentation so that I can use it with PowerShell.
Finally, after accessing the response, I need to verify it using PowerShell Pester.
I appreciate your help.
Selenium Webdriver based test using powershell and chrome,
The windows server, is returning an authentication pop up window.
This is my current script:
$CDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$CDriver.Navigate().GoToURL('http://mytestserver/login/')
$CDriver.Navigate().GoToURL('http://admin:adm!n#mytestserver/login/')
I understand, that i will not be able to use elements, as this isn't a message from the website itself.
But i'm trying to understand if i can use the Alert mechanism in Selenium Webdriver,
Instead of passing the username and password, into the actual url?
This what i tried so far, but with no successes:
$alert = $CDriver.SwitchTo().Alert()
$alert.SendKeys("admin");
$alert.SendKeys("adm!n");
$alert.SwitchTo().Alert().Accept();
Also,
Is there is any official documentation for Selenium WebDriver and powershell?
Many websites would rediret to a authentication site while accepting the credentials.
This renders $CDriver.Navigate().GoToURL('http://admin:adm!n#mytestserver/login/') useless.
An option which worked for me was as follows:
[Ofcourse this is in java, but i hope you figure it out]
`//url=orignal url of your application.
driver.get(url);
authURL = driver.getCurrentUrl();
driver.get("http://admin:adm!n#"+authURL.replaceFirst("https://","");`
Hope that works or please let me know in case of any questions.
A new functional in new PhpStorm 11 is debug rest api within build-in rest api tool. I setup debugger and all works from browser - application stops on breakpoints.
But when i run debug from rest api tool, my breakpoints be ignored.
What i missed? On jetbrains blog said:
"To use the debugger, just make sure Xdebug is configured and enabled. Now you can use the new “Submit request in debug mode” button to easily send the request and initiate the debugger."
If you want to trigger and xdebug session from PHPStorm’s REST client
you can set the debug cookie manually. Add the following to a new Request header:
Name: Cookie
Value: XDEBUG_SESSION=PHPSTORM
I had same problem as you.
Try to change Xdebug port. I changed it to 9001 and it works.
php.ini
[xdebug]
xdebug.remote_enable=on
xdebug.default_enable=on
xdebug.remote_autostart=on
xdebug.remote_port=9001
xdebug.remote_host=localhost
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_name=xdebug-profile-cachegrind.out-%H-%R
xdebug.var_display_max_children = 128
xdebug.var_display_max_data = 2048
xdebug.var_display_max_depth = 128
Storm
I have struggling for the past week to try to get this to work. I have downloaded this fantastic tool which is the genymotion emulator for android. But I can't access the internet from my line of code.
using( WebClient wbclient = new WebClient() )
{
try
{
String URI = "http://www.timeapi.org/utc/now"; // test purpose only
Stream s = wbclient.OpenRead( URI );
using( StreamReader r = new StreamReader( s ) )
{
string str = r.ReadToEnd();
}
}catch(Exception ex)
{
// handle...
}
}
This is a simple service that returns the time. If I enter this address in the browser of the guest device genymotion ( android 4.2.2 - API 17 ), the browser works perfectly and the time is returned. But the above code throws an exception "Connection time out". Why within my guest device the above url can be retrieved from the browser and properly display the time and throw an exception when access in code via WebClient object? Thanks
It's not your code: you have discovered that genymotion is not on the internet - this flaw is by official design. this happens because genymotion (a wrapper for VirtualBox) dis-disconnects the correct adapters (that you may or may not have set in VirtualBox) and uses it's own (faulty) "Host Only Adapter" networking setting instead, and then HIDES that it does this.
To fix this highly unfair "bug" (feature?) you have to go into VirtualBox, find the GenyMotion machine by name and then power it off, right click to "Settings" networking and then click under "adapter 2" (tab) and tick "enable network adapter" then click "attached to:>Bridged Adapter" assuming your pc that you are running it all on runs under DHCP it will set up a IP for the Android VM that GenyMotion proclaims as it's own (which it is not)
I am trying to request JSON data from a PHP script in my Android app.
The whole thing works well when I'm directly connecting my mobile phone and directly access the "real" Internet webserver. However, it doesn't work at all using the emulator and localhost (WAMP installation). Running the script directly on the local webserver, again, gives me the expected results- only if I am calling it on the same machine using the emulator, the troubles begin.
Here are the combinations I have tried so far (the scripts are located in the subdirectory "zz" of the root):
private static String url_all_venues = "http://10.0.2.2/zz/pullvenuesjson.php";
or
private static String url_all_venues = "http://10.0.2.2:80/zz/pullvenuesjson.php";
leads to the following exception: E/JSON Parser(657): Error parsing data org.json.JSONException: Value
When I'm trying the following:
private static String url_all_venues = "http://10.0.2.2:8080/zz/pullvenuesjson.php";
the code runs 'forever' and I'm getting a timeout error after about 5 minutes.
Any idea how to fix that so I can also test my app on my local webserver / the emulator? Most probably the problem is in my local Apache configuration, but then, I'm not sure…
EDIT:
Here is some of the code that seems to trigger the error:
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
"url" is the one mentioned above. As mentioned in my comment below, it looks as if the problem comes from the local WAMP webserver not responding appropriately, since the code works fine when I'm directly accessing the "real" server via the Internet (i.o.w, do nothing else than changing the URL to the Internet address of the php script). The odd thing is that the script also works fine when I run it locally, but NOT through the emulator.
I finally figured it out! I logged the transferred data using Log.d(..) and found out that the username/password combination was not valid as I didn't check for the localhost condition... The script and app retrieves the data just fine now on both, localhost and the web. Thanks for your inquiries which helped me to get down to the root of the error!
[Answered myself in order to avoid the Q showing up as unanswered]