How to pass an browser env parameter for nightwatch-api formerly nightwatch-cucumber? - docker-compose

Nightwatch-cucumber is deprecated and we should use Nightwatch-api as per the author.
I have a set up where I use selenium grid with both a Firefox and Chrome nodes running waiting to be activated. I have not set any webdriver settings in my project. I am still able to run tests but it only takes the default test setting.
How would be able to run tests specifying a browser other than the default?

As per the examples from repo, you should be able to pass it through two files (links below) which will enable you to execute them in desired browser (provided, it is configured in nightwatch.conf.js file).
https://github.com/mucsi96/nightwatch-api/blob/master/packages/selenium-hub-example/test/server.js
https://github.com/mucsi96/nightwatch-api/blob/master/packages/selenium-hub-example/test/support/setup.js
Examples from Repo:
Selenium Grid : https://github.com/mucsi96/nightwatch-api/tree/master/packages/selenium-hub-example
Webdriver : https://github.com/mucsi96/nightwatch-api/tree/master/packages/cucumber-example
Selenium standalone : https://github.com/mucsi96/nightwatch-api/tree/master/packages/cucumber-selenium-example
Please accept this as answer if it helps in resolving your issue.

Related

Vs Code Issue: no code output. how do i fix this?

I am very new to coding and am trying to write a practice script for webscraping in VS Code Editor. But every time i run the script i get this issue of there being no real output. Can you please advise on what the issue is? Note: the pink boxes are just covering my nameenter image description here
I tried running the code and expected webscraped data from the link. I have tried many different scripts and the same issue happens. So there must be something wrong with the whole system i think
VSCode is an excellent IDE. When you start a new project (or open a folder in VSCode), it does not come with any build tools or compilers etc. You have to manually configure them. You have to set up the environment using different toolchains. Here are some instructions for Python
This is not a problem with VSCode but I am going to answer your question.
You can't webscrape indeed.com with requests and beatiful soup because it has bot protection using cloudflare. If you take a closer look to the response it returns the 403 Forbidden status code instead of 200 OK. You can scrape using a headless browser using selenium.
Here's an example
First install selenium and webdriver_manager
pip install selenium webdriver_manager
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
# Make sure you are not detected as HeadlessChrome, some sites will refuse access
options = ChromeOptions()
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = Chrome(options=options, service=Service(
ChromeDriverManager().install()))
# Make sure you are not detected as HeadlessChrome, some sites will refuse access
ua = driver.execute_script("return navigator.userAgent").replace(
"HeadlessChrome", "Chrome")
driver.execute_cdp_cmd("Network.setUserAgentOverride", {
"userAgent": ua})
driver.execute_script(
"Object.defineProperty(navigator,'webdriver',{get:()=>undefined});")
driver.get("https://www.indeed.com/companies/best-Agriculture-companies")
main = driver.find_element(By.ID, "main")

Multithread Pytest

I wanted to create a test in PyTest where it will parallelly open two Chrome and Firefox browser and test two test cases one by one with valid and invalid sets of inputs. How should I achieve it?
Thanks for your advanced help.
You can achieve this using following methods
Selenium Grid and docker.
Download docker and pull the image for Selenium Hub and Image for Chrome and Image for Firefox. Start the containers and you are good to go.
You can follow the instruction from this page.
https://github.com/SeleniumHQ/docker-selenium
If you do not want to use docker then, you can download selenium grid jar file for hub and nodes in your local machine and manually trigger them using the command prompt. following link can be useful they have explained it very nicely
https://www.guru99.com/introduction-to-selenium-grid.html
https://www.selenium.dev/documentation/en/grid/grid_4/setting_up_your_own_grid/

Invoke install4j updater with custom proxy settings

I want to do the following with application wrapped by Install4J:
have the Install4J Updater invoked from the code of the wrapped Java app
show the GUI dialogs, configured in the Install4J IDE to a user if there is an update available
pass custom proxy parameters to the Updater, if required
As far as I can understand Install4J I should be able to do it with the following:
List<String> args = new ArrayList<String>();
args.add("-DproxySet=true");
args.add("-DproxyHost="+MY_PROXY_SERVER);
args.add("-DproxyPort="+MY_PROXY_PORT););
args.add("-DproxyAuth=true");
args.add("-DproxyAuthUser="+MY_PROXY_USERNAME);)
args.add("-DproxyAuthPassword="+MY_PROXY_PASSWORD);
ApplicationLauncher.launchApplicationInProcess(
MY_UPDATER_ID.toString(),
args.toArray(new String[args.size()]),
null,
ApplicationLauncher.WindowMode.FRAME,
null);
but I keep getting the popup for entering proxy details.
I have tried changing parameters not to have prefix "-D", tried switching Updater to console mode or unattended mode, not passing the parameters but rather putting them to JVM directly with System.setProperty()... but with no success. I always ended either with proxy-popup or with message that "The update information could not be downloaded from ____ Please check your network settings."
Also: if I repeatedly invoke Updater but with different parameters the popup always shows the once I used for the first invocation.
Any help?
Thanks in advance.
Thanks to the support from EJ-tehnologies (developers of Install4J) we got the proxy thing working. In the moment of asking the question we were using v5.0.11, and they instructed us to use v5.1.2 (latest stable build in that moment). And finally we ended using the beta release v5.1.3 (not publicly available at the moment).
Details on how to have proxy working, without popup and with using dynamic parameters:
to the code above add additional argument that will prevent Install4J to detect system wide proxy settings:
args.add("-Dinstall4j.noProxyAutoDetect=true");
use method ApplicationLauncher.launchApplication() for invoking the Install4J wrapper as it will start it in the new JVM. starting like this is required due to JVM's handling of existing env variables, so if you start Install4J in the same JVM and append arguments in that JVM the Install4J might not pick the latest values (this is if you want to dynamically change proxy params)
wait for v5.1.3 to become stable and download it as it will support "not showing" of proxy popup dialog when proxy parameters are explicitly given to Install4J (this is my guess, I'm not speaking in the name of people from EJ-technologies)

How can I set up Eclipse/Selenium to run scripts on other browsers on a Mac?

Im new to Macs and Im having issues trying to run scripts on any browser, let alone IE or Chrome. Here is what Ive done so far:
Installed the latest versions of Eclipse, Selenium standalone server and Selenium IDE
Installed TestNG framework for Eclipse
Installed Selenium web driver and the JAVA libraries
So far all I can do is just run the test scripts Ive created on FF12.
I have created some test scripts on FF12 using Selenium IDE, then exported them to Eclipse with TestNG and when I try to run them I get this error message "Please add the directory containing ''firefox-bin' or 'firefox'' to your PATH environment"
I have a feeling im missing a lot of steps to properly configure Eclipse & Selenium to run scripts on other browsers (ideally IE9 and the latest version of Chrome). And if thats not bad enough, im using a MacBook Pro (Ive been a PC person all my life). Please be gentle and any advice that I can get would be highly appreciated. Thanks
Short answer
Seems like your firefox executable in not in the system path or in the default location. There are multiple ways to fix this
1.Set the firefox binary path in code
You need to set the webdriver.firefox.bin property. In java you can do this by using the following code:
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("path/to/your/firefox.exe")), profile);
2.Find where your firefox is installed and update that path in your path variable
export PATH=/my/firefox/path/bin:$PATH
3.Specify webdriver.firefox.bin as a system property when you start selenium server.
java -jar seleniumserver.jar -D webdriver.firefox.bin = "/path/to/firefox-bin
Once you do one of the above, your issue should be resolved.
Not so short answer - Why it fails?
Per FirefoxDriver javadoc -
org.openqa.selenium.firefox.FirefoxDriver
An implementation of the {#link WebDriver} interface that drives
Firefox. This works through a firefox extension, which gets installed
automatically if necessary. Important system variables are:
webdriver.firefox.bin - Which firefox binary to use (normally
"firefox" on the PATH).
webdriver.firefox.profile - The name of the
profile to use (normally "WebDriver").
Here, webdriver.firefox.bin determines the path of firefox.exe (in windows) or firefox (in mac).
Usually, when you install firefox in your machine the path to firefox file gets added to the path variable. This will allow the user to call firefox from any place.
Webdriver will look for this firefox executable in the path variable and then in the default location. From selenium code, this default path is defined as given below:
case MAC:
if (!binaryName.endsWith(".app"))
binaryName += ".app";
binaryName += "/Contents/MacOS/firefox-bin";
break;
If your firefox file is not available in /Contents/MacOS/firefox-bin then webdriver will not know where to find it. Hence the failure.

Getting WatiN.Core.Exceptions.TimeoutException while running from CruieControl

I am getting WatiN.Core.Exceptions.TimeoutException:
Timeout while Internet Explorer busy error while executing my tests via CruiseControl.Net.
Any one have idea how to resolve this?
While we are using TeamCity, we had to disable IE protected mode.
Also, check that user, under which watiN tests are being run can interact with desktop.
I know this question is old and answered, but below are some of my observations.
It is possible to run watin tests under a service account
but the following restrictions/prerequisites apply:
service must run in desktop interactive mode. Only available if running as system.
tests must not create a new windows, even alert/confirm dialogs
Ie cannot create a new window, so watin fails when looking for/expecting it to appear.
ie may show its own warnings, e.g. Insecure content in a secure Page, this can cause tests to fail*
if the tests fail/timeout and the ie instance is forcefully closed, the next instance may try to restore the previous state. The tests then appear to fail*
this can be turned off in the advanced settings.
*from what I've experienced, usually because the prompt is halting the document from being reported as loading-finished.
Feel free to add with other restrictions /comments.