Unable to set safari user agent in java for reponsive testing

619 views
Skip to first unread message

piyush...@gmail.com

unread,
May 12, 2014, 1:27:47 AM5/12/14
to webd...@googlegroups.com
Hi,
 
can any one help to me to set safari user agent in java for my responsive web application
 
I had did it for firefox and chorme but not able tot set it for safari
 
Thanks,
Piyush

Shravan Kumar

unread,
May 12, 2014, 6:26:56 AM5/12/14
to webd...@googlegroups.com
Hi Piyush,

Here is a small code that I used to work on safari browser to test application. Webdriver has built-in safari function so no need to set the plugin from third party,

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.safari.SafariDriver;

public class BrowseSafari {

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
WebDriver wd = new SafariDriver();
Thread.sleep(5000);
WebElement searchbox = wd.findElement((By.id("gbqfq")));
searchbox.sendKeys("cleveland");
WebElement button = wd.findElement(By.className("gbqfb"));
button.click();
}

}


If the above one is not your requirement, can you please elaborate your requirement further? Please ignore my response if it is irrelevant,

thank you,

-- 
with regards,
Shravan Kumar.T

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.




piyush...@gmail.com

unread,
May 15, 2014, 1:36:36 AM5/15/14
to webd...@googlegroups.com
Hi Shravan,
 
Thanks for your kind reply, but I want to set user anger switcher to test my application in 320x480 view.
 
I had did to for firefox and chrome as below and its working fine but I am unable to set it for safari browser.
 
Please let me know if you can help to me resolve this issue.

 

 
Fire fox setting
 

FirefoxProfile profile = new FirefoxProfile();

profile.setEnableNativeEvents(true);

profile.addExtension(new File("C:\\Users\\piyush\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\4sm3i8dn.default\\extensions\\{e968fc70-8f95-4ab9-9e79-304de2a71ee1}.xpi"));

profile.setPreference("general.useragent.override", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");

setDriver(new FirefoxDriver(profile));

chrome setting

 

ChromeOptions options = new ChromeOptions();

options.addArguments("--user-agent=-Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5");

System.setProperty("webdriver.chrome.driver", "C:\\Users\\piyush\\Downloads\\chromedriver.exe");

setDriver(new ChromeDriver(options));

 

Many Thanks,

Piyush

Shravan Kumar

unread,
May 15, 2014, 2:31:07 AM5/15/14
to webd...@googlegroups.com
Hi Piyush,

I'm so sorry as I'm not much into the mobile testing application. But as far as to my knowledge, we cannot set the safari user agent syntactically because Safari already has a built in feature to set to whatever version you want either mobile, ipad or anything to test the web application, if you set the user agent using this steps, you may testing your app as if you are testing on mobile versions.

I think you already know this, please pardon my ignorance if I said anything wrong. I have enclosed some couple of screen shots with this mail, please find the attachment.

After setting the user agent, with normal webdriver coding you can open the safari browser, and test your web app and the browser opens as if it opens like in ipad or mobile versions.

Thank you and if you got the solution please let me know and share it here so that it may be useful for all in this group.

thank you once again,

-- 
with regards,
Shravan Kumar.T

safari1.png
safari2.png
safari3.png
Reply all
Reply to author
Forward
0 new messages