Elm Port doesn't run - elm

I'm trying to fetch a json from an url and parse it in elm, following the Reactivity tutorial. But for some reason my code doesn't do anything. I'm using Debug.watch to see if anything happens.
I have the following code:
emailUrl : String
emailUrl = some url
port fetchEmails : Task Http.Error ()
port fetchEmails =
Http.getString (Debug.watch "url" emailUrl) `andThen` parseEmails
parseEmails : String -> Task x ()
parseEmails json =
let result = Json.Decode.decodeString Static.emailDecoder json
in case result of
...
The code compiles, but doesn't seem to do anything. I'm very new to elm, so I'm a bit stuck here. How should this work?
Edit: turns out it was working, but as the answer stated the Debug.watch does not work with ports yet. I was also getting a 'cross-origin request blocked', which explains why it couldn't get the json.
Thanks!

The Elm time traveling debugger does not play well with ports yet.
Please use Debug.log and check you JavaScript Console.

Related

How to make a post request using the gogearbox framework

I am currently stuck because I do not know how to complete my Post request for a project I am doing. I am using a framework called gearbox (I wanted to try something new). The main problem is I don't know how to bind the json to the new variable. So can anyone help me with this issue. For the info I can post the GitHub package. It's "github.com/gogearbox/gearbox" , Please help me.
I did try to look up the documentation,and I did try a few different functions but it didn't work so if anyone can help me please.
You should provide some code even if it doesn't work. It's usually a good starting point. This way we can avoid trying things you already tested out. I've briefly read the doc and didn't test the code below but you may try to look at the ParseBody function:
type Payload struct{
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
}
requestHandler := func(ctx *fasthttp.RequestCtx) {
var payload *Payload
err := ctx.ParseBody(&payload)
if err!= nil {
ctx.Status(gearbox.StatusInternalServerError).SendString("Something went wrong when parsing your payload!")
}
// do something with your payload
}
reference here

How to pass several parameters via pathParam() [REST-ASSURED, API]

How do I pass several parameters via pathParam() in the following rest-assured POST request?
I tried this:
enter code here
createBaseRequest(userRequestSpecification)
.when()
.contentType(ContentType.JSON)
.pathParam("permalink", requestExpertTeam.getPermalink())
.pathParam("id", parseInt(getLoggedUserId(userRequestSpecification)))
.put(ENDPOINT_ADD_USER_TO_EXPERT_TEAM)
.then()
.extract()
.as(UserDTO.class);
But the IntelliJ starts yelling:
java.lang.IllegalArgumentException: Path parameters were not correctly defined. Redundant path parameters are: id=252.
When I change 'pathParam' in [pathParam("id", parseInt(getLoggedUserId(userRequestSpecification)))] to 'queryParam' IntelliJ starts yelling that it expects two params but got only one.
Thank you in advance.
You missed the placeholder in URL for pathParam id. If RA see that mismatch between pathParam and URL, they will fire an error.
.pathParam("permalink", "abc")
.pathParam("id", 1)
http://localhost:8080/{permalink}/{id}

Selenium request returns error 400 - Bad request

I'm trying to get pull data from http://43.248.49.97/indexEn
Normally on the browser there is a first request to the url above returns error 412, the second one is to a JS file and the third one is also to the url above and returns ok (200).
When using selenium the third request returns error 400 - Bad request instead.
I'm using Python. Any ideas on why this is happening?]
Thanks
I had the same problem with you but I found a solution which perfectly solves my problem.
Maybe your program fails because you are detected as a robot using selenium.
So here is the method to solve it or hide your identity(window.navigator.webdriver) by using JavaScript:
With CDP(Chrome Devtools-Protocol), you run the code before the frame is loaded by the JS file(detector). Therefore, use these codes to remove the "webdriver True" property:
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
key codes:
from selenium.webdriver import Chrome
driver = Chrome('D://chromedriver.exe')
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
driver.get('http://pythonlearner.com')
However, if you upgrade your Chrome to 88 right now. The method mentioned above will be useless. Fortunately, we still have a solution (add this code)
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
These codes should help you pass the JS file so that you can obtain the data. At least I successfully run my program.
I am using ChromeDriver 104.0.5112.79.0 and the solution with chrome_options.add_argument("--disable-blink-features=AutomationControlled") works for me!

How to detect browser in Elm

How do I detect the browser from Elm?
Specifically I want to be able to tell if the web app is running on a tablet (Safari on iPad, etc.) or not.
You can use Html.programWithFlags to pass information from Javascript to Elm on initialization.
Assuming you can infer browser from user agent, you could do something like this:
type alias Flags =
{ userAgent : String }
Your init would look like this:
init : Flags -> ( Model, Cmd Msg )
init flags =
...
main =
programWithFlags { init = init, ... }
And from Javascript, you would pass the flags in like this:
var app = Elm.Main.fullscreen({
userAgent: navigator.userAgent
});
Side note: User agent may not be enough to fully detect browser. You can see this StackOverflow answer which provides more reliable detection. Either way, the end result is that you would send some kind of flag along to the Elm app on init.
More info on Flags can be found here.
You can use elm-vendor package.
http://package.elm-lang.org/packages/coreytrampe/elm-vendor/latest

selenium.captureEntirePageScreenshot does not work but selenium.captureScreenshot works

I'm running Selenium with TestNG using Eclipse and Selenium RC. I used the command:
selenium.captureEntirePageScreenshot("\\test.png","");
but got the following error:
com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]
Can someone please suggest why this error is occuring? I have already tried the following:
1)Replaced "" (String kwargs parameter) with "background=#CCFFDD"
2)Running in Firefox in chrome mode
3)Changed the path to the following values and I'm still getting the error:
"\test.jpg",
"c:\test.jpg",
"c:\test.png",
"c:\folder1\test.png", (folder1 exists)
"c:\folder1\test.jpg",
4)Tried with - selenium.captureScreenshot("\test.png"); and it works fine but it does not solve my purpose and I dont want to use awt.
Can someone please suggest what could be wrong?
Thanks,
Mugen
Better yet...
I ran into a similar issue, where I only had access to a relative path instead of an absolute one. Here is the solution I came up with:
public void saveScreenshot(String methodName) {
if (methodName == null) {
methodName = String.valueOf(System.currentTimeMillis());
}
File f = new File("reports" + File.separator + methodName + ".jpg");
selenium.captureEntirePageScreenshot(f.getAbsolutePath(), "");
}
Which will put a screen shot of the entire page into the reports directory that is relative to the project. I am using the method name as the file name, or the current time if null is sent to the method.
Try this:
String path = System.getProperty("user.dir");
selenium.captureEntirePageScreenshot(path + "\\test.png", "");
To whomsoever it may concern,. the problem was solved after I kept fiddling with the code for a while and restarted my system. I came to know that captureEntirePageScreenshot works only on absolute paths so I made sure I kept trying with just that.
I got it working after looking at this page.
http://ashishbhatt.wordpress.com/2010/02/03/using-captureentirepagescreenshot-with-selenium/