How to work with mobile chrome and testing app by Appium - java

I'm automationg mobile application, but in some cases I need to click on link and check that approproate link was opened by browser. For example link Terms of Service on SignUP page of my application.So the question is -HOW to switch between testing app and browser.Here is my code
File apk = new File("src/test/resources/myapp.apk");
DesiredCapabilities AppCapabilities = new DesiredCapabilities();
DesiredCapabilities chromeCapabilities=new DesiredCapabilities();
AppCapabilities.setCapability("app", apk.getAbsolutePath());
AppCapabilities.setCapability("platformName", "Android");
AppCapabilities.setCapability("automationName", "Appium");
AppCapabilities.setCapability("deviceName", "MyDevice");
AppCapabilities.setCapability("platformVersion", "4.3");
//capabilities.setCapability(key, value);
AppCapabilities.setCapability("newCommandTimeout", 400);
androidDriver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), AppCapabilities);
but something like adroidDriver.getCurrentURL() doesn't work.

You are missing a few capabilities.
Please look at the server flag and capabilities for anything related to "Chrome" http://appium.io/slate/en/master/?ruby#server-flags
And then please take a look at the documentation for automation using ChromeDriver with Appium.
http://appium.io/slate/en/master/?ruby#mobile-chrome-on-emulator-or-real-device

Solution found. Just add one more appium node and define additional driver for mobile browser

Related

Unable to run headless selenium on heroku with javascript enabled

I am trying to scrape some twitter data with headless selenium running in a Spring Boot application on Heroku. The following 2 buildpacks are included in my Heroku app:
1) https://github.com/heroku/heroku-buildpack-chromedriver.git
2) https://github.com/heroku/heroku-buildpack-google-chrome.git
These two buildpacks are designed for running headless selenium in a heroku app.
After the selenium script enters my twitter login data and hit the login button, my script keeps crashing. Why? I examined the page source and found the following hint from twitter:
We've detected that JavaScript is disabled in your browser. Would you
like to proceed to legacy Twitter?
So obviously javascript seems to be disabled which is very bad. And i don't want to proceed in legacy mode (without javascript).
When initializing the webdriver, i tried the following two options to make sure javascript is enabled. But it seems to be ignored:
Option 1)
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless", "--enable-javascript");
WebDriver webdriver = ChromeDriver(chromeOptions);
Option 2)
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver webdriver = ChromeDriver(capabilities);
Any ideas?
I had a similar problem. I solved it by removing some options.
This is my driver options (python) currently:
options = Options()
options.binary_location = os.getenv("GOOGLE_CHROME_BIN")
options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument("--window-size=1920x1080")
driver = webdriver.Chrome(options=options, executable_path=os.getenv("CHROMEDRIVER_PATH"))

chrome extension - how to invoke webDriver with chrome extension (not in a new tab)

i am trying to open webDriver with chrome extension (Modify header value) using below code
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
but this code is opening the webDriver instance with the extention in another window can any one know how to invoke it with chrome extension not in a new tab.
You may refer with this thread. Be noted that Selenium supports interaction with web view only. You can check this tutorial on how to test your Chrome Extension with selenium. However, you can also use of sikuli (Automation tool that make use of image recognition), to click the chrome add-on. After that add-on popup will be another browser window, so use switch window to perform actions on add-on popup. Hope this helps!

selenium webdriver take too much time in .get() method and then unconditionally stop my whole java process.(It is only for one specific URL only)

friends i am using selenium webdriver to fetch pagesource in my java desktop application. I am getting problem with only one URL which is "http://www.greenbergdental.com/offices/university" every time I try to get this my current java thread was stuck and whole application was stopped. Please suggest me some solution regarding this I have tried Pagetimeout, Scripttimeout.
Note: I can not enable javascript for some reason. so please dont give me suggestions like turn on javascript that I can't.
websiteURL ="http://www.greenbergdental.com/offices/university";
WebDriver htmlUnitDriver = new HtmlUnitDriver();
htmlUnitDriver.manage().timeouts().pageLoadTimeout(15,TimeUnit.SECONDS);
htmlUnitDriver.manage().timeouts().setScriptTimeout(15,TimeUnit.SECONDS);
htmlUnitDriver.get(websiteURL);
String pagesource = htmlUnitDriver.getPageSource();
Try running for a specific browser (though web apps better be neutral of recent browser is used). If you are using latest firefox browser, try this:
HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45);
For chrome:
HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.CHROME);
Also, you could go for setting driver with capabilities:
HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(capabilities);

Install/Add chrome extension from Chrome Web Store using Selenium

I am developing test automation using Selenium with Java. I would like to install/add extension to chrome instance launched through Selenium. One way to install/add extension is using .crx file as follow.
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(ext_path));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
But I would like to install/add extension from Chrome Web Store. Can anyone please suggest how to achieve this.
Thanks.
You can install extension (packed/unpacked) to chrome with options.addExtensions/addArguments as mentioned here:- https://sites.google.com/a/chromium.org/chromedriver/extensions
alternative: Chromedriver every time opens new chrome instance with temporary profile for the execution. To avoid this you can use existing profile with desired chrome extension installed OR you can send commands to already running instance of chrome which has desir d extension installed.
usually, inline/webstore installation of a Chrome extension can't be tested with ChromeDriver/Selenium alone, because of confirmation dialog.
you can use platform-specific hacks to click on the button (e.g. via AutoIt),

Accepting "Sharing Location" browser popups through Selenium WebDriver

I've Googled, searched SO, and looked at the Selenium Javadocs but haven't found an answer to this question.
Is there any way, using Selenium WebDriver, to accept those "Share Location" popups that get displayed by browsers (Chrome, Firefox, IE) when a website is trying to track your location?
Also, I'm writing up my Selenium code in Java and using the Selenium Client Drivers.
I've tried running the Selenium IDE (the Firefox add-on) and recording me accepting the "Share Location" popup that Firefox popsup but nothing gets recorded in the Selenium IDE.
If the popup is part of the browser then the answer is no. If you want to interact with something displayed in a second window ( not part of the browser) then yes. There should be a .switch_to method.
Although if you can have this page remember your settings you can load a profile when you create a new instance of the browser.
In windows you can create a profile in firefox by going to the start menu and typing "firefox.exe -p" here you can create a new profile where you you would have a "remember me check box" checked.
As far as loading a profile in Java + Selenium I'm not sure how you would do this. I use Ruby + Selenium and this is how I do it.
$driver = Selenium::WebDriver.for :firefox, :profile => "MyProfile"
hope this helps
I have got the solution to this in firefox but still working on chrome. The below code should help and fetch your exact location on maps:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("default");
myprofile.setPreference("geo.prompt.testing", true);
myprofile.setPreference("geo.prompt.testing.allow", true);
myprofile.setPreference("geo.wifi.uri", "https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE,myprofile);
After this just pass the FirefoxProfile instance in the driver method just as below(for the above code):
driver = new FirefoxDriver(myprofile);
That should be fine, write all the other stuff you want and execute!!

Categories